我是Android编程的新手。我正在尝试模拟温度度量转换的程序。执行程序时,我得到运行时异常
java.lang.RuntimeException: Unable to start activity
ComponentInfo{btn.pkg/btn.pkg.contemp}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
06-14 17:46:26.132: ERROR/AndroidRuntime(360):
你能在这里告诉我
完整的线程转储是
06-14 17:46:26.132: ERROR/AndroidRuntime(360): FATAL EXCEPTION: main
06-14 17:46:26.132: ERROR/AndroidRuntime(360): java.lang.RuntimeException: Unable to start activity ComponentInfo{btn.pkg/btn.pkg.contemp}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.os.Handler.dispatchMessage(Handler.java:99)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.os.Looper.loop(Looper.java:123)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.app.ActivityThread.main(ActivityThread.java:3647)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at java.lang.reflect.Method.invoke(Method.java:507)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at dalvik.system.NativeStart.main(Native Method)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.app.Activity.setContentView(Activity.java:1657)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at btn.pkg.contemp.onCreate(contemp.java:21)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): ... 11 more
06-14 17:46:26.132: ERROR/AndroidRuntime(360): Caused by: java.lang.reflect.InvocationTargetException
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at java.lang.reflect.Constructor.constructNative(Native Method)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): ... 21 more
06-14 17:46:26.132: ERROR/AndroidRuntime(360): Caused by: android.content.res.Resources$NotFoundException: File #3399CC from drawable resource ID #0x7f040005
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.content.res.Resources.loadDrawable(Resources.java:1714)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.view.View.<init>(View.java:1951)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.view.View.<init>(View.java:1899)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.view.ViewGroup.<init>(ViewGroup.java:286)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.widget.LinearLayout.<init>(LinearLayout.java:120)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): ... 24 more
06-14 17:46:26.132: ERROR/AndroidRuntime(360): Caused by: java.io.FileNotFoundException: #3399CC
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.content.res.AssetManager.openNonAssetNative(Native Method)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.content.res.AssetManager.openNonAsset(AssetManager.java:406)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): at android.content.res.Resources.loadDrawable(Resources.java:1706)
06-14 17:46:26.132: ERROR/AndroidRuntime(360): ... 29 more
答案 0 :(得分:1)
我遵循了相同的教程(vogella) http://www.vogella.de/articles/Android/article.html 并犯了同样的错误。 在文件strings.xml中,您将颜色定义为文本,而不是颜色。应该是:
<color name="myColor">#3399CC</color>
答案 1 :(得分:0)
如果您的应用程序中有自定义控件,则应使用布局XML中的完整包指定它,如果仅使用“yourcustomcontrol”,则会抛出此错误。 例如:
<yourcustomcontrol android:id="@+id/yourCustomControl1" /> will throw error.
<packageName.yourcustomcontrol android:id="@+id/yourCustomControl1" /> will work.
有关自定义控件的更多信息,请访问Android开发人员主页here。
答案 2 :(得分:0)
可能会发生此错误,因为有时您会错误地提及您的包名称。因此,请检查特定的错误行,确认您提到的包名是否正确。检查并告诉我这是否有效。因为在我的情况下我错误地提到了我的包名,一旦我纠正了错误已解决。