我是 Android 开发的新手,如果重复,我很抱歉,但我尝试查看其他解决方案,但它们没有帮助。所以这是我的问题:
我尝试创建一个不做任何事情的简单菜单。它应该在按下菜单按钮时弹出。它在一个模拟器(目标 Android 3.0(API 级别 11))上工作,但在我尝试过的其他模拟器(Android 1.5 和 4.0)中打开 logcat 并给出消息:“应用程序菜单(进程 menu.intro)已意外停止。 请再试一次”。
我的 MainActivity.java 文件:
package menu.intro;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.mainmenu,menu);
return true;
}
}
我在 /res/menu 文件夹中的 mainmenu.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/buttonone"
android:icon="@drawable/icon1"
android:title="@string/showimage1"/>
<item android:id="@+id/buttontwo"
android:icon="@drawable/icon2"
android:title="@string/showimage2" />
<item android:id="@+id/buttonthree"
android:icon="@drawable/icon3"
android:title="@string/showimage3" />
</menu>
我的 activity_main.xml 文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#000000"
android:src="@drawable/image" />
</RelativeLayout>
logcat 是这样的,对我来说都是希腊语:
02-16 17:46:19.171: I/jdwp(747): received file descriptor 10 from ADB
02-16 17:46:19.211: W/System.err(747): Can't dispatch DDM chunk 46454154: no handler defined
02-16 17:46:19.211: W/System.err(747): Can't dispatch DDM chunk 4d505251: no handler defined
02-16 17:46:19.591: W/ResourceType(747): Failure getting entry for 0x7f020004 (t=1 e=4) in package 0: 0xffffffb5
02-16 17:46:19.601: D/AndroidRuntime(747): Shutting down VM
02-16 17:46:19.601: W/dalvikvm(747): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
02-16 17:46:19.601: E/AndroidRuntime(747): Uncaught handler: thread main exiting due to uncaught exception
02-16 17:46:19.631: E/AndroidRuntime(747): java.lang.RuntimeException: Unable to start activity ComponentInfo{menu.intro/menu.intro.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class java.lang.reflect.Constructor
02-16 17:46:19.631: E/AndroidRuntime(747): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.os.Handler.dispatchMessage(Handler.java:99)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.os.Looper.loop(Looper.java:123)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.app.ActivityThread.main(ActivityThread.java:3948)
02-16 17:46:19.631: E/AndroidRuntime(747): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 17:46:19.631: E/AndroidRuntime(747): at java.lang.reflect.Method.invoke(Method.java:521)
02-16 17:46:19.631: E/AndroidRuntime(747): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
02-16 17:46:19.631: E/AndroidRuntime(747): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
02-16 17:46:19.631: E/AndroidRuntime(747): at dalvik.system.NativeStart.main(Native Method)
02-16 17:46:19.631: E/AndroidRuntime(747): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class java.lang.reflect.Constructor
02-16 17:46:19.631: E/AndroidRuntime(747): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
02-16 17:46:19.631: E/AndroidRuntime(747): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-16 17:46:19.631: E/AndroidRuntime(747): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.app.Activity.setContentView(Activity.java:1626)
02-16 17:46:19.631: E/AndroidRuntime(747): at menu.intro.MainActivity.onCreate(MainActivity.java:17)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
02-16 17:46:19.631: E/AndroidRuntime(747): ... 11 more
02-16 17:46:19.631: E/AndroidRuntime(747): Caused by: java.lang.reflect.InvocationTargetException
02-16 17:46:19.631: E/AndroidRuntime(747): at android.widget.ImageView.<init>(ImageView.java:103)
02-16 17:46:19.631: E/AndroidRuntime(747): at java.lang.reflect.Constructor.constructNative(Native Method)
02-16 17:46:19.631: E/AndroidRuntime(747): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
02-16 17:46:19.631: E/AndroidRuntime(747): ... 22 more
02-16 17:46:19.631: E/AndroidRuntime(747): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/title_bar_shadow.9.png from drawable resource ID #0x7f020004
02-16 17:46:19.631: E/AndroidRuntime(747): at android.content.res.Resources.loadDrawable(Resources.java:1641)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.widget.ImageView.<init>(ImageView.java:113)
02-16 17:46:19.631: E/AndroidRuntime(747): ... 26 more
02-16 17:46:19.631: E/AndroidRuntime(747): Caused by: java.io.FileNotFoundException: res/drawable/title_bar_shadow.9.png
02-16 17:46:19.631: E/AndroidRuntime(747): at android.content.res.AssetManager.openNonAssetNative(Native Method)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.content.res.AssetManager.openNonAsset(AssetManager.java:392)
02-16 17:46:19.631: E/AndroidRuntime(747): at android.content.res.Resources.loadDrawable(Resources.java:1634)
02-16 17:46:19.631: E/AndroidRuntime(747): ... 28 more
02-16 17:46:19.671: I/dalvikvm(747): threadid=7: reacting to signal 3
02-16 17:46:19.681: I/dalvikvm(747): Wrote stack trace to '/data/anr/traces.txt'
02-16 17:46:26.052: I/Process(747): Sending signal. PID: 747 SIG: 9
非常感谢您耐心阅读我的问题!任何帮助都深表感谢。