按照http://developer.android.com中的教程,我正在学习开发安卓应用程序。
现在我在http://developer.android.com/training/custom-views/create-view.html上工作,当我构建应用程序时,我得到了错误:
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'showText' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelHeight' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelWidth' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelY' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelPosition' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'highlightStrength' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'pieRotation' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'labelColor' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'autoCenterPointerInSlice' in package 'com.example.android.customviews.charting'
D:\sviluppo\netbeans\custom-view\res\layout\main.xml:24: error: No resource identifier found for attribute 'pointerRadius' in package 'com.example.android.customviews.charting'我从网站上下载了代码,并按原样安装,没有做任何更改,所以main.xml是
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.example.android.customviews"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.example.android.customviews.charting.PieChart
android:id="@+id/Pie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_weight="100"
custom:showText="true"
custom:labelHeight="20dp"
custom:labelWidth="110dp"
custom:labelY="85dp"
custom:labelPosition="left"
custom:highlightStrength="1.12"
android:background="@android:color/white"
custom:pieRotation="0"
custom:labelColor="@android:color/black"
custom:autoCenterPointerInSlice="true"
custom:pointerRadius="4dp"
/>
<Button
android:id="@+id/Reset"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/reset_button"
/>
</LinearLayout>和名称空间是相同的。
你能帮助我理解为什么我会得到这些错误吗?非常感谢。
发布于 2014-03-20 07:26:09
我也遇到了同样的问题,答案就在这个link中。
简而言之,您需要替换
http://schemas.android.com/apk/res/com.example.android.customviews使用
http://schemas.android.com/apk/lib/com.example.android.customviews即从/res/到/lib/。
发布于 2015-07-16 11:36:31
我从Android.com下载了同样的自定义演示,也遇到了同样的问题。
改变
xmlns:custom="http://schemas.android.com/apk/res/com.example.android.customviews"到任何一个
xmlns:custom="http://schemas.android.com/apk/lib/com.example.android.customviews"或
xmlns:custom="http://schemas.android.com/apk/res-auto"起作用了。它们之间有一些不同,我发现第二个解决方案完美地满足了我的需求。我不知道它为什么有用。
发布于 2013-09-11 16:18:01
我遇到了同样的问题,我认为你的自定义属性不属于正确的namespace.You可以得到customview_panda的演示,看看main.xml中的自定义属性,你就会明白了。https://github.com/pandabo1985/Android_App_Prac
https://stackoverflow.com/questions/18298460
复制相似问题