ユーザが電話の戻るボタンを押したときに特定の設定を正常にリロードすることができました。これが起こると、私はその場所と最初の要素をリストに保存します。今度は、画像ボタンを押してリストを生成します。リストが生成されると、任意の要素を押すことができ、新しいクラスがロードされます。リストアイテムが起動していません。共有設定で再読み込みしたときのアクティビティ
しかし、リストから情報を呼び出すと、アプリがクラッシュし、 ヌルポインタ例外が発生します。私はこれが何であるか分かっていますが、理由を理解できません。ここに私のコードです:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.new_sightings);
// Initialize location
user_lat_Value = (TextView)findViewById(R.id.lat_Value);
user_long_Value = (TextView)findViewById(R.id.long_Value);
// Have not received coordinates yet
gotCoord = false;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
setListAdapter(adapter);
SharedPreferences settings = getSharedPreferences(PREFS_NAME,0);
if(settings.contains("ARRAY_LIST_VALUE_0") || settings.contains("LAT"))
{
user_lat_Value.setText(settings.getString("LAT", myNewLat));
user_long_Value.setText(settings.getString("LONG", myNewLon));
listItems.add(settings.getString("ARRAY_LIST_VALUE_0",tempStore));
adapter.notifyDataSetChanged();
}
reload = (Button)findViewById(R.id.reloadTen);
reload.setOnClickListener(this);
list = getListView();
list.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
// Start an activity based on what list view item is pressed
Intent intent = new Intent(newSightings.this, newCompass.class);
// Pass the data we retrieved to the next activity
intent.putExtra("info",data[position] );
startActivity(intent);
}
});
list.setTextFilterEnabled(true);
}
@Override
protected void onStop()
{
super.onStop();
gotCoord = false;
SharedPreferences settings = getSharedPreferences(PREFS_NAME,0);
SharedPreferences.Editor editor = settings.edit();
// Store the latitude and longitude values and then reload them if known
editor.putString("LAT",myNewLat);
editor.putString("LONG",myNewLon);
// Place first element of array list in storage
if(adapter.getCount() > 0)
{
Toast.makeText(getApplicationContext(), "Leaving Activity, Adapter Size: "+ adapter.getCount()+"\nStoring: "+listItems.get(0).toString(), Toast.LENGTH_SHORT).show();
tempStore = listItems.get(0).toString();
editor.putString("ARRAY_LIST_VALUE_0",tempStore);
/**
for(int i = 0; i < storeList.length; i++)
{
storeList[i] = listItems.get(i).toString();
editor.putString("ARRAY_LIST_VALUE_"+i, listItems.get(i).toString());
}
*/
}
editor.commit();
}
私は間違っているが、私はリストアダプタにデータをリロードして押すので、それだけでロードされていたならば、それはそれは、リスト内のアイテムの動作を模倣べきではないなら、私を修正?
私は混乱しています。あなたのコメントに基づいて
乾杯
NullPointerExceptionの行は何ですか? – Samuel
行114 - intent.putExtra()行 – Katana24