我在Android中工作。我想設計一個歌曲類別的微調。Android中的微調中的空指針異常
這是我的代碼:
public Spinner spinner_category_forSong;
String[] arr_Category={"Select","sad","dj","rock"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this,android.R.layout.simple_spinner_item,arr_Category);
spinner_category_forSong = (Spinner)findViewById(R.id.Spinner_category_forUpload);
spinner_category_forSong.setPrompt("Music Category :");
spinner_category_forSong.setAdapter(adapter);
但每當我跑我的項目,一個空指針異常在spinner_category_forSong.setPrompt("Music Category :");
和spinner_category_forSong.setAdapter(adapter);
創建。
請告訴我我在這段代碼中犯了什麼錯誤。前spinner_category_forSong.setPrompt("Music Category :");
請出示logcat的輸出... –
無法啓動活動ComponentInfo {com.pericent/com.pericent.FileUploadWithChooser}:顯示java.lang.NullPointerException 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) at android.app.ActivityThread.access $ 2300(ActivityThread.java:125) at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033 ) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) –
引起:java.lang.NullPointerException at com.pericent.FileUploadW ithChooser.initSpinner_category(FileUploadWithChooser.java:157) 在com.pericent.FileUploadWithChooser.onCreate(FileUploadWithChooser.java:40) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 在android.app.ActivityThread。 performLaunchActivity(ActivityThread.java:2627) –