注:前添加我的應用程序是做工不錯,用同樣的方法AdView的崩潰我的應用程序
當我試圖與AdView添加到我的應用程序也讓我的應用程序崩潰的廣告,所以我刪除,但還是給我此 這是logcat的
10-12 21:33:19.765 4993-4993/com.fm360.almorfis E/AndroidRuntime:致命異常:主 工藝:com.fm360.almorfis,PID:4993 java.lang.RuntimeException:無法啓動活動ComponentInfo {com.fm360.almorfis/com.fm360.almorfis.MainActivity}:java.lang.NullPointerException:嘗試在android.app.ActivityThread.handleLaunchActivity(ActivityThread)上的android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) 上的null對象引用 上調用虛擬方法'void android.widget.Spinner.setSelection(int)'。 java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java :102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method)(com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 引起的: NullPointerException:試圖在com.fm360.almorfis.MainActivity.spinnerVal(MainActivity.java:123) com.fm360.almorfis上的空對象引用 上調用虛擬方法'void android.widget.Spinner.setSelection(int)' .MainActivity.onCreate(MainActivity.java:59) at android.app.Activity.performCreate(Activity.java:6664) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread .perfo rmLaunchActivity(ActivityThread.java:2599) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread .java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) ,這是我的方法,它告訴
private void spinnerVal(int spinnerID, int move, int selection){
Spinner sp = (Spinner) findViewById(spinnerID);
ArrayList<Integer> spinnerOption = new ArrayList<>();
for (int i = 0; i < 50; i+=move) {
spinnerOption.add(i);
}
ArrayAdapter<Integer> integerArrayAdapter = new ArrayAdapter<>(this, R.layout.spinner_item, spinnerOption);
integerArrayAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
sp.setAdapter(integerArrayAdapter);
sp.setSelection(selection);
sp.setOnItemSelectedListener(this);
}