行,所以我有5個陣列都在他們5種元素在我的strings.xml文件,像這樣:NullPointerException異常越來越字符串數組爲String []
<string-array name="monday">
<item>monday</item>
<item>tuesday</item>
<item>wednesday</item>
<item>thursday</item>
<item>friday</item>
</string-array>
現在我已經在我的代碼switch語句是deppending上他們點擊的按鈕會將這5個數組中的一個設置爲我的主數組。但是我已經嘗試了許多歧方法,但我仍然得到空指針異常在這條線:
Days.masterarray = getResources().getStringArray(R.array.monday);
也修整這一點,但得到了同樣的結果:
Days.setMasterarray(getResources().getStringArray(R.array.monday));
主數組:
public static String[] masterarray = new String[] { "monday", "tuesday",
"wednesday", "thursday", "friday" };
我已經給它默認值開始。現在,當我運行switch語句中我得到這個:
03-19 13:43:23.555: WARN/System.err(1379): java.lang.NullPointerException
03-19 13:43:23.586: WARN/System.err(1379): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
03-19 13:43:23.586: WARN/System.err(1379): at schoolBook.Icestone.Days.setArray(Days.java:77)
03-19 13:43:23.595: WARN/System.err(1379): at schoolBook.Icestone.SampleActivity.onCreate(SampleActivity.java:27)
03-19 13:43:23.605: WARN/System.err(1379): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
03-19 13:43:23.626: WARN/System.err(1379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
03-19 13:43:23.626: WARN/System.err(1379): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1577)
03-19 13:43:23.635: WARN/System.err(1379): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:130)
03-19 13:43:23.644: WARN/System.err(1379): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:342)
03-19 13:43:23.655: WARN/System.err(1379): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:680)
03-19 13:43:23.676: WARN/System.err(1379): at android.widget.TabHost.setCurrentTab(TabHost.java:349)
03-19 13:43:23.676: WARN/System.err(1379): at android.widget.TabHost.addTab(TabHost.java:239)
03-19 13:43:23.695: WARN/System.err(1379): at schoolBook.Icestone.Days.onCreate(Days.java:32)
03-19 13:43:23.695: WARN/System.err(1379): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
03-19 13:43:23.695: WARN/System.err(1379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
03-19 13:43:23.716: WARN/System.err(1379): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
03-19 13:43:23.716: WARN/System.err(1379): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
03-19 13:43:23.716: WARN/System.err(1379): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
03-19 13:43:23.735: WARN/System.err(1379): at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 13:43:23.735: WARN/System.err(1379): at android.os.Looper.loop(Looper.java:126)
03-19 13:43:23.744: WARN/System.err(1379): at android.app.ActivityThread.main(ActivityThread.java:3997)
03-19 13:43:23.754: WARN/System.err(1379): at java.lang.reflect.Method.invokeNative(Native Method)
03-19 13:43:23.754: WARN/System.err(1379): at java.lang.reflect.Method.invoke(Method.java:491)
03-19 13:43:23.754: WARN/System.err(1379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
03-19 13:43:23.775: WARN/System.err(1379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
03-19 13:43:23.775: WARN/System.err(1379): at dalvik.system.NativeStart.main(Native Method)
就如何解決這一問題的任何燈光,將不勝感激
我會嘗試做一個項目乾淨和重建。有時R類不會更新 - 至少在最後一個SDK中。 – bigstones 2011-03-19 15:32:18