为什么在布局XML中定义<shape>时会出现ClassNotFoundException?</shape>

时间:2012-05-12 21:49:52

标签: android android-layout

我试图通过将其包含在/layout/myactivity.xml

中来绘制矩形
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <corners
      android:radius="2dp"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp"
      android:bottomLeftRadius="0dp" />
  <stroke
      android:width="1dp"
      android:color="@android:color/white" />
</shape>

当我尝试运行项目时,我得到:

05-12 23:37:14.090: E/AndroidRuntime(541): Caused by: java.lang.ClassNotFoundException: android.view.shape
05-12 23:37:14.090: E/AndroidRuntime(541):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-12 23:37:14.090: E/AndroidRuntime(541):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-12 23:37:14.090: E/AndroidRuntime(541):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-12 23:37:14.090: E/AndroidRuntime(541):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
05-12 23:37:14.090: E/AndroidRuntime(541):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:636)
05-12 23:37:14.090: E/AndroidRuntime(541):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
05-12 23:37:14.090: E/AndroidRuntime(541):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
05-12 23:37:14.090: E/AndroidRuntime(541):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
05-12 23:37:14.090: E/AndroidRuntime(541):  ... 22 more

我错过了什么吗?

1 个答案:

答案 0 :(得分:10)

您的XML代码很好,位置就是问题所在。您需要将此文件保存在res/layoutres/drawable等特定的可绘制文件夹中,而不是将此文件保存在res/drawable-xhdpi文件夹中。