0

I have an activity that load sharedPreference from another activity and put some data from the sharedPreferenece into a listView using the arrayAdpter when I compile my app its forced close this is me code:

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);
}

when I make this two line if code hinted :

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,dawaaList);
    dataList.setAdapter(adapter)

the app is work just fine

but not filling the listView Of course

お願い助けて

4

1 に答える 1

3

String[]適切なサイズで初期化するのを忘れたと思いますが、

それ以外の

String[] dawaaList;

試す

String[] dawaaList = new String[1];

例外をスローする行は、

dawaaList[0] = theName;
于 2012-09-04T11:33:57.853 に答える