我從另一個活動加載sharedPreference,並把一些數據從 sharedPreferenece成一個ListView使用arrayAdpter當我編譯我的應用程序的強制關閉 這個活動是我的代碼:arrayAdapter造成應用程序強行關閉
public class DawaaActivity extends Activity implements View.OnClickListener {
/** Called when the activity is first created. */
Button add;
ListView dataList;
private SharedPreferences emportPref;
String[] dawaaList;
String theName;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initialaiz();
emportPref = getSharedPreferences("dawaaData", MODE_PRIVATE);
theName = emportPref.getString("subject", "no data found");
Toast.makeText(this, theName, Toast.LENGTH_LONG).show();
dawaaList[0] = theName;
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,dawaaList);
dataList.setAdapter(adapter);
}
private void initialaiz() {
// TODO Auto-generated method stub
add = (Button) findViewById(R.id.button3);
dataList = (ListView) findViewById(R.id.myListView);
add.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
Intent data = new Intent(DawaaActivity.this,SettingActivity.class);
startActivity(data);
}
當我提出這個兩行,如果代碼暗示:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,dawaaList);
dataList.setAdapter(adapter)
應用程序是工作就好
但不填充的ListView當然幫我請
您的logcat錯誤報告在哪裏? –
dawaaList [0] = theName;//錯誤我認爲 – Carnal