crash on my app
i have a crash: ERROR/AndroidRuntime(27007): FATAL EXCEPTION: main 03-15 18:29:04.967: ERROR/AndroidRuntime(27007): java.lang.RuntimeException: Unable to destroy activity {com.TravelTop/com.TravelTop.Ego}: java.lang.NullPointerException
That is the onCreate of First activity, when you press on the button (fromButton) that will call the other activity and expect to get back the name of the country
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
// final int recquestCode = 0;
final Button btnCountryfrom = (Button) findViewById(R.id.fromButton);
btnCountryfrom.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent pingIntent = new Intent(getApplicationContext(),CountryView.class);
pingIntent.putExtra("btnText", " ");
pingIntent.setClass(TravelPharmacy.this, CountryView.class);
s开发者_开发技巧tartActivityForResult(pingIntent, RECEIVE_MESSAGE);
Log.i("tag for easy filter in logcat 6","I am Working!!!");
ButtonFromPressed=true;
}
});
}
when getting back the name of the country that be choose in the other activity Override onActivityResult and set the name of country in the button
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Button btnCountryfrom = (Button) findViewById(R.id.fromButton);
CharSequence seq = data.getCharSequenceExtra("response");
btnCountryfrom.setText(seq);
ButtonFromPressed=false;
}
}
the onCreate of my second Activity
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.country);
mListUsers = getCountry();
lvUsers = (ListView) findViewById(R.id.countrylistView);
lvUsers.setAdapter(new ListAdapter(this, R.id.countrylistView, mListUsers));
lvUsers.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
Intent pongIntent = new Intent();
Log.i("tag for easy filter in logcat 1", "information you provide");
Log.i("tag for easy filter in logcat 2",mListUsers.get(position).pays);
pongIntent.putExtra("response",mListUsers.get(position).pays);
setResult(Activity.RESULT_OK,pongIntent);
finish();
Log.i("tag for easy filter in logcat 3",mListUsers.get(position).pays);
}
});
}
i will appreciate help!!!
thanks!
Looks like Null pointer dereference (from java API docs)
"Thrown when an application attempts to use null in a case where an object is required. ..."
It's hard to say more without seeing the code.
精彩评论