Android6.0:新建eclipse工程遇到的几个错误记录

2016年03月31日 Android 暂无评论 阅读5276次

Android6.0:新建eclipse工程遇到了几个错误记录

appcompat_v7工程中的编译出错:No resource found that matches the given name (at 'layout_marginTop' with value '@dimen/abc_action_bar_icon_vertical_padding

No resource found that matches the given name (at 'layout_marginTop' with value '@dimen/abc_action_bar_icon_vertical_padding 

编译错误是abc_action_bar_icon_vertical_padding的定义找不到,在工程中grepabc_action_bar_icon_vertical_padding能找到一个后面带有_material的定义。原因主要是新的Material Design中把原来老的ActionBar替换了,很多尺寸的定义等也被修改了。所以就用刚才我们全局grep的结果替换就好了。

结论:

abc_action_bar_icon_vertical_padding 

替换为

abc_action_bar_icon_vertical_padding_material 

这样,编译问题就全都解决了。下面的都是运行时的异常了。

Exception java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable

Exception java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable 

修改完第一个问题遇到的是这个错误,详细信息如下

D/AndroidRuntime(10534): Shutting down VM
W/dalvikvm(10534): threadid=1: thread exiting with uncaught exception (group=0x4126b2a0)
E/AndroidRuntime(10534): FATAL EXCEPTION: main
E/AndroidRuntime(10534): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
E/AndroidRuntime(10534):    at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:327)
E/AndroidRuntime(10534):    at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
E/AndroidRuntime(10534):    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
E/AndroidRuntime(10534):    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
E/AndroidRuntime(10534):    at com.example.jileniao.MainActivity.onCreate(MainActivity.java:14)
E/AndroidRuntime(10534):    at android.app.Activity.performCreate(Activity.java:5184)
E/AndroidRuntime(10534):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
E/AndroidRuntime(10534):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
E/AndroidRuntime(10534):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
E/AndroidRuntime(10534):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
E/AndroidRuntime(10534):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
E/AndroidRuntime(10534):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(10534):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(10534):    at android.app.ActivityThread.main(ActivityThread.java:4898)
E/AndroidRuntime(10534):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(10534):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(10534):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
E/AndroidRuntime(10534):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
E/AndroidRuntime(10534):    at dalvik.system.NativeStart.main(Native Method) 

网上很多说法。但都没能解决我的问题。经过自己的检查后发现我的appcompat_v7工程中gen里没有生成R文件。所以,把appcompat_v7工程clean,在重新编译,看到gen目录下有生成R.java文件,在重新运行,这个问题就已解决了。

android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar

这是紧接着出现的第三个问题

D/AndroidRuntime(15169): Shutting down VM
W/dalvikvm(15169): threadid=1: thread exiting with uncaught exception (group=0x4126b2a0)
E/AndroidRuntime(15169): FATAL EXCEPTION: main
E/AndroidRuntime(15169): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.zxz/com.example.zxz.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
E/AndroidRuntime(15169):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
E/AndroidRuntime(15169):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
E/AndroidRuntime(15169):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
E/AndroidRuntime(15169):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
E/AndroidRuntime(15169):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(15169):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(15169):    at android.app.ActivityThread.main(ActivityThread.java:4898)
E/AndroidRuntime(15169):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(15169):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(15169):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
E/AndroidRuntime(15169):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
E/AndroidRuntime(15169):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(15169): Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
E/AndroidRuntime(15169):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
E/AndroidRuntime(15169):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
E/AndroidRuntime(15169):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime(15169):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
E/AndroidRuntime(15169):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime(15169):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(15169):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime(15169):    at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:379)
E/AndroidRuntime(15169):    at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
E/AndroidRuntime(15169):    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
E/AndroidRuntime(15169):    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
E/AndroidRuntime(15169):    at com.example.zxz.MainActivity.onCreate(MainActivity.java:14)
E/AndroidRuntime(15169):    at android.app.Activity.performCreate(Activity.java:5184)
E/AndroidRuntime(15169):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
E/AndroidRuntime(15169):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
E/AndroidRuntime(15169):    ... 11 more
E/AndroidRuntime(15169): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime(15169):    at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime(15169):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
E/AndroidRuntime(15169):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
E/AndroidRuntime(15169):    ... 25 more
E/AndroidRuntime(15169): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f02002a
E/AndroidRuntime(15169):    at android.content.res.Resources.loadDrawable(Resources.java:1951)
E/AndroidRuntime(15169):    at android.content.res.Resources.getDrawable(Resources.java:672)
E/AndroidRuntime(15169):    at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
E/AndroidRuntime(15169):    at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
E/AndroidRuntime(15169):    at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
E/AndroidRuntime(15169):    at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
E/AndroidRuntime(15169):    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
E/AndroidRuntime(15169):    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
E/AndroidRuntime(15169):    at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
E/AndroidRuntime(15169):    at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
E/AndroidRuntime(15169):    at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
E/AndroidRuntime(15169):    ... 28 more
E/AndroidRuntime(15169): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
E/AndroidRuntime(15169):    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:877)
E/AndroidRuntime(15169):    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
E/AndroidRuntime(15169):    at android.content.res.Resources.loadDrawable(Resources.java:1948)
E/AndroidRuntime(15169):    ... 38 more
E/android.os.Debug(2274): !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error
I/dumpstate(15195): begin
D/KeyguardViewMediator(2274): setHidden false 

这次的异常中日志信息量比较大,不要着急慢慢看,不要错过重要的信息。我们抓取到这样一条关键错误。

E/AndroidRuntime(15169): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f02002a 

难道真的是这个文件出问题了?其实非也。解释这个问题需要从Android新版本的MeteralDesign中允许的自定义矢量图说起。关于新版本中矢量图的相关信息大家可以到Android官网查阅。接着说,因为猜测是新版本的Theme引起的,那么到AndroidManifest.xml中看了下给application设置的theme,为AppTheme,使用鼠标一步一步地往上层点,就发现Base.V21.Theme.AppCompat.Light这个theme了,这里面自定义了很多项目。为了解决整个问题,我们把AndroidManifest.xml中theme属性改为老版本常用的android:Theme.Holo.NoActionBar.Fullscreen。结果还是不行。产生了下面一个错误。

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

D/AndroidRuntime(1183): Shutting down VM
W/dalvikvm(1183): threadid=1: thread exiting with uncaught exception (group=0xb1a48b90)
E/AndroidRuntime(1183): FATAL EXCEPTION: main
E/AndroidRuntime(1183): Process: com.example.zxz, PID: 1183
E/AndroidRuntime(1183): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jileniao/com.example.jileniao.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
E/AndroidRuntime(1183):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
E/AndroidRuntime(1183):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
E/AndroidRuntime(1183):     at android.app.ActivityThread.access$700(ActivityThread.java:135)
E/AndroidRuntime(1183):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
E/AndroidRuntime(1183):     at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(1183):     at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(1183):     at android.app.ActivityThread.main(ActivityThread.java:4998)
E/AndroidRuntime(1183):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(1183):     at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(1183):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
E/AndroidRuntime(1183):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
E/AndroidRuntime(1183):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(1183): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
E/AndroidRuntime(1183):     at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:331)
E/AndroidRuntime(1183):     at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
E/AndroidRuntime(1183):     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
E/AndroidRuntime(1183):     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
E/AndroidRuntime(1183):     at com.example.zxz.MainActivity.onCreate(MainActivity.java:14)
E/AndroidRuntime(1183):     at android.app.Activity.performCreate(Activity.java:5243)
E/AndroidRuntime(1183):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime(1183):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
E/AndroidRuntime(1183):     ... 11 more 

针对此问题:看了日至后,找了下MainActivity这个类,原来MainActivity是继承的主Activity的android.support.v7.app.ActionBarActivity 。想到把ActionBarActivity改成Activity试试。真的解决了问题。

分享本文至:

WRITTEN BY

avatar
本文标签:android6.0eclipse
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

欢迎留言




用户登录

sitemap