android自定义View在xml中的使用出错?到底该怎么用?求高手指教
java.lang.RuntimeException:UnabletostartactivityComponentInfo{cm.test/cm.test.TestsAc...
java.lang.RuntimeException: Unable to start activity ComponentInfo{cm.test/cm.test.TestsActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class cm.test.testview
(434): at dalvik.system.NativeStart.main(Native Method)
07-16 08:49:03.574: E/AndroidRuntime(434): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class cm.test.testview
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-16 08:49:03.574: E/AndroidRuntime(434): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.app.Activity.setContentView(Activity.java:1657)
07-16 08:49:03.574: E/AndroidRuntime(434): at cm.test.TestsActivity.onCreate(TestsActivity.java:12)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-16 08:49:03.574: E/AndroidRuntime(434): ... 11 more
07-16 08:49:03.574: E/AndroidRuntime(434): Caused by: java.lang.ClassNotFoundException: cm.test.testview in loader dalvik.system.PathClassLoader[/data/app/cm.test-1.apk] 展开
(434): at dalvik.system.NativeStart.main(Native Method)
07-16 08:49:03.574: E/AndroidRuntime(434): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class cm.test.testview
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-16 08:49:03.574: E/AndroidRuntime(434): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.app.Activity.setContentView(Activity.java:1657)
07-16 08:49:03.574: E/AndroidRuntime(434): at cm.test.TestsActivity.onCreate(TestsActivity.java:12)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 08:49:03.574: E/AndroidRuntime(434): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-16 08:49:03.574: E/AndroidRuntime(434): ... 11 more
07-16 08:49:03.574: E/AndroidRuntime(434): Caused by: java.lang.ClassNotFoundException: cm.test.testview in loader dalvik.system.PathClassLoader[/data/app/cm.test-1.apk] 展开
4个回答
展开全部
android.view.InflateException: Binary XML file line #8: Error inflating class cm.test.testview
1. 确认准确包名 “cm.test.testview” -->
2. 确认 inflate 使用
[code] 三种方式可以生成LayoutInflater:
LayoutInflaterinflater=LayoutInflater.from(this);
LayoutInflaterinflater=getLayoutInflater();
LayoutInflaterinflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
publicViewinflate(intresource,ViewGrouproot,booleanattachToRoot)
在View类中,也有inflate方法
publicstaticViewinflate(Contextcontext,intresource,ViewGrouproot)
[/code]
1. 确认准确包名 “cm.test.testview” -->
2. 确认 inflate 使用
[code] 三种方式可以生成LayoutInflater:
LayoutInflaterinflater=LayoutInflater.from(this);
LayoutInflaterinflater=getLayoutInflater();
LayoutInflaterinflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
publicViewinflate(intresource,ViewGrouproot,booleanattachToRoot)
在View类中,也有inflate方法
publicstaticViewinflate(Contextcontext,intresource,ViewGrouproot)
[/code]
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
目测是你的自定义testview在inflate的时候出错了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
07-16 08:49:03.574: E/AndroidRuntime(434): at cm.test.TestsActivity.onCreate(TestsActivity.java:12)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看看是不是定义的textview有错误
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询