-1
在我的android應用程序中,我創建了一個菜單,其中包含兩個操作save和refresh,並在另一個activity中調用。路徑上找不到類「android.view.menu」
但它給出了這個例外,如何解決這個問題。 沒有找到路徑
這裏是我的代碼類「android.view.menu」,
這是我的主要內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)
添加日誌或異常 –
'但它給這個exception' - >異常在哪裏?發佈。 –
據我記得,方法是'onOptionsItemSelected()'。不'onMenuItemSelected()' – Shaiful