
package com.my.androID.library.layout;public class CustomVIEw extends VIEw {... 我还为我的CustomVIEw定义了styleable:
<?xml version="1.0" enCoding="utf-8"?><resources> <declare-styleable name="CustomVIEw"> <attr name="Title_text" format="string" /> </declare-styleable></resources>
由于我不想将我的源代码分享给正在使用我的库项目的其他人,所以我创建了一个分布式库项目,在其中我将上面的主库项目的jar添加到分布式库项目的libs /文件夹中并复制了所有从主库项目到分布式库项目的资源.
NEXT,我制作了一个使用分布式库项目的androID app项目.在app项目的主要布局文件中,我定义了以下内容:
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:tools="http://schemas.androID.com/tools" xmlns:custom="http://schemas.androID.com/apk/res-auto" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <com.my.androID.library.layout.CustomVIEw custom:Title_text = "THIS IS Title" /><relativeLayout>
当我运行我的应用程序时,我得到以下异常:
E/AndroIDRuntime(30993): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.androID.app/com.my.androID.app.MainActivity}: androID.vIEw.InflateException: Binary XML file line #7: Error inflating class com.my.androID.library.layout.CustomVIEwE/AndroIDRuntime(30993): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2071)E/AndroIDRuntime(30993): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096) ... Caused by: java.lang.classNotFoundException: com.my.androID.library.layout.CustomVIEwE/AndroIDRuntime( 2947): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)E/AndroIDRuntime( 2947): at java.lang.classLoader.loadClass(ClassLoader.java:501)E/AndroIDRuntime( 2947): at java.lang.classLoader.loadClass(ClassLoader.java:461)E/AndroIDRuntime( 2947): at androID.vIEw.LayoutInflater.createVIEw(LayoutInflater.java:552)E/AndroIDRuntime( 2947): at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:687) 它似乎无法在布局xml中膨胀我的CustomVIEw.为什么?如何摆脱它?
(我检查了主库jar文件,有CustomVIEw类.请不要只是给我链接AndroID网站而不解释.)
解决方法 由于您要从jar添加VIEw,因此您应该能够将命名空间指定为:xmlns:custom="http://schemas.androID.com/apk/lib/root_package_name
“root_package_name”可以是“com.my.androID.library.layout”或“com.my.androID.library”或类似的东西.
如果这不起作用,那么可能是“订单和导出”问题或者您添加库的方式.确保正确包含库:
Android Activity ClassNotFoundException – tried everything
最后,如果这也失败了,那么您可能需要更新AndroID SDK:
ClassNotFoundException: Didn’t find class “com.google.android.gms.ads.AdView”
总结以上是内存溢出为你收集整理的android – 在我的案例中使用库项目的自定义视图全部内容,希望文章能够帮你解决android – 在我的案例中使用库项目的自定义视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)