在我的Android应用程序中,我创建了一个菜单,其中包含两个保存和刷新操作,并在另一个活动中调用。
但它给出了这个例外,如何解决这个问题。 未在路径上找到“android.view.menu”类
这是我的代码,
这是main中的main.xml,
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_refresh"
android:orderInCategory="100"
android:showAsAction="always|withText"
android:title="@string/menu_refresh"/>
<item
android:id="@+id/menu_save"
android:icon="@android:drawable/ic_menu_save"
android:orderInCategory="10"
android:showAsAction="always"
android:title="@string/menu_save"/>
</menu>
这就是我在活动中的调用方式,
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_refresh:
return true;
case R.id.menu_save:
return true;
}
return false;
}
这是我的日志
android.view.InflateException: Binary XML file line #1: Error inflating class menu
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.os.Handler.dispatchMessage(Handler.java:99)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.os.Looper.loop(Looper.java:137)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-23 07:48:05.277: E/AndroidRuntime(1097): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 07:48:05.277: E/AndroidRuntime(1097): at java.lang.reflect.Method.invoke(Method.java:511)
07-23 07:48:05.277: E/AndroidRuntime(1097): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-23 07:48:05.277: E/AndroidRuntime(1097): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-23 07:48:05.277: E/AndroidRuntime(1097): at dalvik.system.NativeStart.main(Native Method)
07-23 07:48:05.277: E/AndroidRuntime(1097): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class menu
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:807)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-23 07:48:05.277: E/AndroidRuntime(1097): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.app.Activity.setContentView(Activity.java:1881)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.SampleApp.AndroidDashboardDesignActivity.onCreate(AndroidDashboardDesignActivity.java:28)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.app.Activity.performCreate(Activity.java:5104)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-23 07:48:05.277: E/AndroidRuntime(1097): ... 11 more
07-23 07:48:05.277: E/AndroidRuntime(1097): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.menu" on path: /data/app/android.SampleApp-1.apk
07-23 07:48:05.277: E/AndroidRuntime(1097): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-23 07:48:05.277: E/AndroidRuntime(1097): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-23 07:48:05.277: E/AndroidRuntime(1097): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
07-23 07:48:05.277: E/AndroidRuntime(1097): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
07-23 07:48:05.277: E/AndroidRuntime(1097): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
答案 0 :(得分:0)
您是否将menu.xml文件放在/res/menu/menu.xml
当menu.xml在/layout/