开发者

Android.view.InflateException

开发者 https://www.devze.com 2023-03-12 14:57 出处:网络
I am new in Android Programming. I am trying to simulate a program for temperature metric conversion. While executing the program i am getting runtime exception

I am new in Android Programming. I am trying to simulate a program for temperature metric conversion. While executing the program i am getting runtime exception

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):

Can you advise me here

The complete thread dump is

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


I followed the same tutorial (vogella) http://www.vogella.de/articles/Android/article.html and made the same mistake. In the file strings.xml, you define the color as text, instead of as color. should be:

<color name="myColor">#3399CC</color>


If you have custom controls in your application then it should be specified using the full package in your layout XML, if only "yourcustomcontrol" is used it will throw this error. For example:

<yourcustomcontrol android:id="@+id/yourCustomControl1" /> will throw error.
<packageName.yourcustomcontrol android:id="@+id/yourCustomControl1" /> will work.

More about custom controls can be found at the android developers' homepage here.


This error may occur because sometime u will mention your package name wrongly. So do check the particular error line that whether your mentioned package name is correct or not. Check and let me know whether this works.Cause in my case i wrongly mentioned my package name and once i rectified that error resolved.

0

精彩评论

暂无评论...
验证码 换一张
取 消