2014-02-07 157 views
0

我試圖做出選項菜單,但在switch語句中出現錯誤(所有Case語句中的錯誤無法解決,如R.id.regid)。Android選項菜單

@Override 
    public boolean onOptionsItemSelected(MenuItem item) 
    { 
     switch(item.getItemId()){ 
     case R.id.regid:Toast.makeText(this,"You pressed the registration  menu",Toast.LENGTH_LONG).show(); 
         return true; 

     case R.id.enqid:Toast.makeText(this,"You pressed the Add Enquiry Menu",Toast.LENGTH_LONG).show(); 
         return true; 

     case R.id.searchid:Toast.makeText(this,"You pressed the Search Students Menu",Toast.LENGTH_LONG).show(); 
         return true; 

     case R.id.calid:Toast.makeText(this,"You pressed the calendar Menu for Upcoming batches",Toast.LENGTH_LONG).show(); 
         return true; 

     case R.id.timingsid:Toast.makeText(this,"You pressed the Batch Timings Menu for Current Batches",Toast.LENGTH_LONG).show(); 
         return true; 

     case R.id.courseid:Toast.makeText(this,"You pressed jlc Syllabus",Toast.LENGTH_LONG).show(); 
          return true; 

     case R.id.facultiesid:Toast.makeText(this,"You pressed the faculties details",Toast.LENGTH_LONG).show(); 
         return true; 

     default:return super.onOptionsItemSelected(item); 
     } 
    } 

     } 

Optionmenuitem.xml

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



<item 
    android:id="@+id/regid" 
    android:icon="@drawable/ic_menu_reg" 
    android:title="@string/reg" 
    android:alphabeticShortcut="R" 
    /> 

<item 
    android:id="@+id/enqid" 
    android:icon="@drawable/ic_enquiry" 
    android:title="@string/enquiry" 
    android:alphabeticShortcut="E" 
    /> 

<item 
    android:id="@+id/searchid" 
    android:icon="@drawable/searchid" 
    android:title="@string/search" 
    android:alphabeticShortcut="S" 

    /> 

<item 
    android:id="@+id/calid" 
    android:icon="@drawable/ic_calendar" 
    android:title="@string/upcomingbatches" 
    android:alphabeticShortcut="U" 
    /> 
<item 
    android:alphabeticShortcut="T" 
    android:id="@+id/timingsid" 
    android:icon="@drawable/ic_clock" 
    android:title="timings" 
    /> 
<item 
    android:id="@+id/courseid" 
    android:alphabeticShortcut="C" 

    android:title="JLC Syllabus" 
    /> 
<item 
    android:id="@+id/facultiesid" 
    android:title="faculties" 
    android:icon="@drawable/ic_faculties" 
    android:alphabeticShortcut="F" 
    /> 

</menu> 

下面是在控制檯顯示錯誤消息。

Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_menu_reg'). 
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_enquiry'). 
Error: No resource found that matches the given name (at 'icon' with value '@drawable/searchid'). 
Error: No resource found that matches the given name (at 'title' with value '@string/search'). 
Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_calendar'). 
Error: No resource found that matches the given name (at Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_faculties'). 

    Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_menu_reg'). 
    Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_enquiry'). 
    Error: No resource found that matches the given name (at 'icon' with value '@drawable/searchid'). 
    Error: No resource found that matches the given name (at 'title' with value '@string/search'). 
    Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_calendar'). 
    Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_clock'). 
    Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_faculties'). 
+0

該錯誤與您發佈的代碼無關。 – doorstuck

回答

1

如果導入它,請從導入中刪除android.R。如果仍不起作用,請嘗試清理該項目(項目 - >清潔...)

+0

也應該刪除任何其他進口的R。 – PearsonArtPhoto

+0

我刪除了import.R。現在得到一個錯誤R無法解決。 – user3077236

0

好吧!我覺得控制檯中的錯誤與你的代碼無關。
所以你可以嘗試以下步驟:

  • 按Ctrl + Shift + Ø整理進口。
  • 清理您的項目(項目 - >清潔在菜單中)。
  • 現在運行您的應用程序。它應該工作。

讓我知道它是否適合你。

+0

Thanx的答覆。沒有它仍然是同樣的問題。 – user3077236

+0

然後確保你擁有'drawable'文件夾中的所有資源。 – SMR

+0

thrz a ic_launcher.png所有繪圖文件。我們是否需要可繪製文件夾中的任何其他文件? – user3077236