我的Android应用程序在模拟器上正常运行但在Motorola droid 2.2上崩溃了

时间:2011-10-21 20:28:12

标签: android

我在logcat中遇到错误。

> E/AndroidRuntime( 3197): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 3197): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.net.mapapplication/com.net.mapapplication.MainPage}:       android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
E/AndroidRuntime( 3197): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2454)
E/AndroidRuntime( 3197): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
E/AndroidRuntime( 3197): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 3197): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
E/AndroidRuntime( 3197): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3197): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 3197): at android.app.ActivityThread.main(ActivityThread.java:4310)
E/AndroidRuntime( 3197): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3197): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 3197): at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 3197): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 3197): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3197): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
E/AndroidRuntime( 3197): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
E/AndroidRuntime( 3197): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)   
E/AndroidRuntime( 3197): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
E/AndroidRuntime( 3197): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
E/AndroidRuntime( 3197): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime( 3197): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime( 3197): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
E/AndroidRuntime( 3197): at android.app.Activity.setContentView(Activity.java:1622)
E/AndroidRuntime( 3197): at com.net.mapapplication.MainPage.onCreate(MainPage.java:23)
E/AndroidRuntime( 3197): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 3197): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 3197): ... 11 more
E/AndroidRuntime( 3197): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 3197): at android.widget.LinearLayout.<init>(LinearLayout.java:92)
E/AndroidRuntime( 3197): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 3197): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
E/AndroidRuntime( 3197): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
E/AndroidRuntime( 3197): ... 21 more
E/AndroidRuntime( 3197): Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/title_bar_shadow.9.png from drawable resource ID #0x7f02000f
E/AndroidRuntime( 3197): at android.content.res.Resources.loadDrawable(Resources.java:1710)
E/AndroidRuntime( 3197): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
E/AndroidRuntime( 3197): at android.view.View.<init>(View.java:1850)
E/AndroidRuntime( 3197): at android.view.View.<init>(View.java:1799)
E/AndroidRuntime( 3197): at android.view.ViewGroup.<init>(ViewGroup.java:282)
E/AndroidRuntime( 3197): ... 25 more
E/AndroidRuntime( 3197): Caused by: java.io.FileNotFoundException: res/drawable-hdpi/title_bar_shadow.9.png
E/AndroidRuntime( 3197): at android.content.res.AssetManager.openNonAssetNative(Native Method)
E/AndroidRuntime( 3197): at android.content.res.AssetManager.openNonAsset(AssetManager.java:391)
E/AndroidRuntime( 3197): at android.content.res.Resources.loadDrawable(Resources.java:1702)
E/AndroidRuntime( 3197): ... 29 more

我的主要XML文件如下:

?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/icon"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:layout_width="35dp"
android:layout_marginTop="4px"
android:layout_marginRight="4px"
android:layout_marginLeft="4px">
</ImageView>
<TextView android:text="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/label"
android:textSize="20sp"
android:padding="10dp"
android:textStyle="bold"
android:textColor="#999900"></TextView>
/>
</LinearLayout>

MainPage.java.23上的代码是:

setContentView(R.layout.splashscreen);

对于xml文件的上线布局,splashscreen如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:background="@drawable/paceuniversity">
</LinearLayout>

2 个答案:

答案 0 :(得分:3)

请注意您的错误日志:

引起:java.io.FileNotFoundException:res / drawable-hdpi / title_bar_shadow.9.png E / AndroidRuntime(3197)

如果你有一个drawable-hdpi文件,你必须至少有一个drawable(默认)和drawable-mdpi(如果你想让它在非高密度屏幕的设备上工作)

可能发生的情况是你的模拟器或手机的密度不同,所以人们在drawable-hdpi目录中找到png,但另一个在drawable-mdpi和drawable目录中查找,文件不在那里?

答案 1 :(得分:1)

看看这个:Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/title_bar_shadow.9.png from drawable resource ID #0x7f02000。有一些资源错误。检查此图像是否存在并且是否正确调用。您可能还想检查所有XML文件和资源。