Android - ResourceNotFoundException和NumberFormatException

时间:2017-09-08 12:07:55

标签: android numberformatexception

我创建了一个应用,其中android.support.v4.widget.DrawerLayoutandroid.support.v7.widget.Toolbar一起使用。

当我在Samsung Tablet Neo(Android版本4.2.2)上运行此应用程序时,该应用程序运行正常。

但是当我在Google Nexus 5(Android版本6.0.1)上运行相同的应用时,我得到ResourceNotFoundException并且应用只是在我的Java中的以下代码的起始行上崩溃了(活动)文件。

应用程序在此行崩溃:setSupportActionBar(topToolBar);

FATAL EXCEPTION: main
rocess: com.myapp, PID: 11761
va.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.MainActivityWithNavigationViewExpandableList}: android.content.res.Resources$NotFoundException: File res/color/abc_hint_foreground_material_dark.xml from color state list resource ID #0x7f0c00ab
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
  at android.app.ActivityThread.-wrap11(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
aused by: android.content.res.Resources$NotFoundException: File res/color/abc_hint_foreground_material_dark.xml from color state list resource ID #0x7f0c00ab
  at android.content.res.Resources.loadColorStateListForCookie(Resources.java:2750)
  at android.content.res.Resources.loadColorStateList(Resources.java:2699)
  at android.content.res.TypedArray.getColorStateList(TypedArray.java:485)
  at android.widget.TextView.<init>(TextView.java:746)
  at android.widget.TextView.<init>(TextView.java:671)
  at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:62)
  at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:58)
  at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:54)
  at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:756)
  at android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261)
  at android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243)
  at android.support.v7.app.ToolbarActionBar.<init>(ToolbarActionBar.java:78)
  at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:223)
  at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)
  at com.myapp.MainActivityWithNavigationViewExpandableList.onCreate(MainActivityWithNavigationViewExpandableList.java:64)
  at android.app.Activity.performCreate(Activity.java:6251)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:148) 
  at android.app.ActivityThread.main(ActivityThread.java:5417) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
aused by: java.lang.NumberFormatException: Invalid float: "0.70000005dip"
  at java.lang.StringToReal.invalidReal(StringToReal.java:63)
  at java.lang.StringToReal.initialParse(StringToReal.java:164)
  at java.lang.StringToReal.parseFloat(StringToReal.java:323)
  at java.lang.Float.parseFloat(Float.java:306)
  at android.content.res.TypedArray.getFloat(TypedArray.java:396)
  at android.content.res.ColorStateList.inflate(ColorStateList.java:275)
  at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:222)
  at android.content.res.ColorStateList.createFromXml(ColorStateList.java:201)
  at android.content.res.Resources.loadColorStateListForCookie(Resources.java:2746)
  at android.content.res.Resources.loadColorStateList(Resources.java:2699) 
  at android.content.res.TypedArray.getColorStateList(TypedArray.java:485) 
  at android.widget.TextView.<init>(TextView.java:746) 
  at android.widget.TextView.<init>(TextView.java:671) 
  at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:62) 
  at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:58) 
  at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:54) 
  at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:756) 
  at android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261) 
  at android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243) 
  at android.support.v7.app.ToolbarActionBar.<init>(ToolbarActionBar.java:78) 
  at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:223) 
  at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130) 
  at com.myapp.MainActivityWithNavigationViewExpandableList.onCreate(MainActivityWithNavigationViewExpandableList.java:64) 
  at android.app.Activity.performCreate(Activity.java:6251) 
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:148) 
  at android.app.ActivityThread.main(ActivityThread.java:5417) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

我也搜索了其他SO答案。

资源&#39; abc_hint_foreground_material_dark &#39;不是我的颜色&#39;。此资源应来自Android的支持库,我在Android Studio中使用。

2 个答案:

答案 0 :(得分:0)

abc_hint_foreground_material_dark是指向主题foreground_material_dark的链接,请参阅here

NumberFormatException表示此颜色值无效('无效浮点数:“0.70000005dip”')。此值不是来自支持库,因此必须由资源设置(请检查colors.xml和values.xml)。颜色值应为十六进制整数,不在dp或任何其他单位。有关详细信息,请参阅here

答案 1 :(得分:0)

所以最后我在这个问题上挖了更多,我的嫌疑人是NumberFormatException。我在dimens.xml文件中搜索了十进制值并对其进行了评论。它现在运作良好。基本上,Android无法解析放置在dimens.xml文件中的小数值。