我試圖讓一個世界的創造者在列表視圖中保存世界的名字。但是,在活動打開之前,shaed首選項會導致程序崩潰。這是爲什麼發生?沒有共享偏好,這是完全沒問題的。有任何想法嗎? (上列表視圖中點擊是未完成的,不用擔心。)這是最顯着的錯誤是在陣列適配器空pointerexception,存儲== NULL,並跳過的幀共享首選項崩潰程序
package xxx.xxx.xxx;
import android.app.ListActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
public class WorldMenu extends ListActivity{
SharedPreferences prefs;
String splitter;
String[] worldList;
PopupWindow worldNamer;
Drawable background;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(WorldMenu.this,
android.R.layout.simple_list_item_1, worldList));
prefs = getSharedPreferences("worldString", 0);
splitter = "Create World\\\\\\\\\\\\\\\\\\\\\\\\\\" +
prefs.getString("worldString", "No worlds found.");
worldList = splitter.split("\\\\\\\\\\\\\\\\\\\\\\\\\\");
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
if(position == 0){
worldNamer = new PopupWindow(this);
worldNamer.setBackgroundDrawable(null);
}
}
}
那麼堆棧跟蹤說什麼,*完全*?您的「最值得注意的錯誤」句子特別不明確...... –
請在將來使用空格而不是製表符來格式化您的代碼,順便說一句。 –
好的我下次還會這樣做 – user2649191