0

在我的 android 应用程序中,我创建了一个菜单,其中包含两个操作保存和刷新,并在另一个活动中调用。

但它给出了这个例外,如何解决这个问题。 在路径上找不到类“android.view.menu”

这是我的代码,

这是我在 main.xml 里面的 main.

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

1 回答 1

0

您是否将 menu.xml 文件放入/res/menu/menu.xml

当 menu.xml 位于/layout/

于 2013-07-23T08:11:47.780 回答