2014-02-15 51 views
0

我想學習如何在android中使用菜單我剛剛在menu.xml文件中添加了幾個子項,並運行它。在控制檯中的一切似乎正常,但當我檢查logcat的許多錯誤顯示up.I不知道什麼是錯的我無法弄清楚我5天機器人編程expresience.Can請您help.Thank是提前困惑我怎樣才能讓mymenu運行

02-15 05:13:04.420: E/logwrapper(912): executing /system/bin/e2fsck failed: No such file or directory 
02-15 05:13:04.440: E/logwrapper(915): executing /system/bin/e2fsck failed: No such file or directory 
02-15 05:13:05.010: E/SurfaceFlinger(923): hwcomposer module not found 
02-15 05:13:05.820: E/SurfaceFlinger(923): ro.sf.lcd_density must be defined as a build property 
02-15 05:13:08.240: E/logwrapper(1175): executing /system/bin/ip failed: No such file or directory 
02-15 05:13:08.240: E/logwrapper(1176): executing /system/bin/ip failed: No such file or directory 
02-15 05:13:19.410: E/FlpHardwareProvider(1251): Error hw_get_module 'flp': -2 
02-15 05:13:19.410: E/FlpHardwareProvider(1251): Error hw_get_module 'flp': -2 
02-15 05:13:19.410: E/LocationManagerService(1251): no geocoder provider found 
02-15 05:13:19.410: E/LocationManagerService(1251): No FusedProvider found. 
02-15 05:13:19.410: E/LocationManagerService(1251): no geofence provider found 
02-15 05:13:25.100: E/Netd(920): exec() res=0, status=256 for /system/bin/iptables -t mangle -A st_mangle_EXEMPT -d 10.0.2.4/32 -j MARK --set-mark 1 
02-15 05:13:25.100: E/logwrapper(1561): executing /system/bin/ip failed: No such file or directory 
02-15 05:13:25.100: E/logwrapper(1562): executing /system/bin/ip failed: No such file or directory 
02-15 05:13:25.100: E/SecondaryTablController(920): ip route add failed: /system/bin/ip route add 10.0.2.2/32 via 0.0.0.0 dev eth0 table 60 
02-15 05:13:25.100: E/ConnectivityService(1251): Exception trying to add a route: java.lang.IllegalStateException: command '16 interface fwmark exempt add 10.0.2.2/32' failed with '400 16 Failed to add exemption rule (File exists)' 
02-15 05:13:37.460: E/StrictMode(1693):  at com.android.mms.transaction.TransactionService.onNewIntent(TransactionService.java:224) 
02-15 05:13:37.460: E/StrictMode(1693):  at com.android.mms.transaction.TransactionService$ServiceHandler.handleMessage(TransactionService.java:621) 
02-15 05:13:37.460: E/StrictMode(1693):  at android.os.Looper.loop(Looper.java:137) 
02-15 05:13:37.460: E/StrictMode(1693):  at android.os.HandlerThread.run(HandlerThread.java:61) 
: E/(): Device disconnected 


<menu xmlns:android="http://schemas.android.com/apk/res/android" > 

這個我的代碼 休息

</menu> 

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <string name="app_name">mymenu</string> 
    <string name="action_settings">Settings</string> 
     <string name="MenuItem">Open</string> 
    <string /> 

</resources> 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

} 
+0

它運行正常嗎? –

+0

我這麼認爲。因爲在控制檯屏幕和模擬器正常啓動時,一切都看起來很正常,我也能夠看到Helloworld Textview但是沒有任何地方的菜單。我不知道哪一行很重要,需要過濾。因此,一小部分錯誤 – user2751773

+0

您是否按菜單按鈕? –

回答

1
  1. 確保菜單項在xml菜單文件中正確聲明。
  2. 確保您已包含onCreateOptionsMenu(Menu menu)。並在那裏誇大了適當的菜單。
  3. 確保您已包含onOptionsItemSelected(MenuItem item)並檢查相應的MenuItem ID。
+0

我已經添加了所有的代碼。這裏有什麼不對嗎 – user2751773

+0

在你的菜單文件夾中,你需要有一個菜單佈局,其中有這樣的: 在裏面。有很多步驟,我很難解釋這裏的所有內容,我認爲使用操作欄查看一些教程可能是一個好主意,YouTube上有一些相當不錯的教程,或者您可以只需查看文檔。順便說一句,如果它能幫助你,那麼接受一個答案是一種慣例。 – timeshift117