在我的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)
你把menu.xml文件放在/res/menu/menu.xml
中了吗
当menu.xml位于/layout/
内时,您可能会收到此错误