在我的应用程序崩溃

时间:2011-03-16 09:28:06

标签: android

我发生了崩溃:     错误/ AndroidRuntime(27007):致命异常:主03-15 18:29:04.967:错误/ AndroidRuntime(27007):java.lang.RuntimeException:无法销毁活动{com.TravelTop / com.TravelTop.Ego}:java .lang.NullPointerException

这是onCreate of First活动,当你按下按钮(fromButton)时,它将调用另一个活动并期望返回该国家的名称

@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);
            startActivityForResult(pingIntent, RECEIVE_MESSAGE);
            Log.i("tag for easy filter in logcat 6","I am Working!!!");
            ButtonFromPressed=true;

         }



    }); 

}

获取在其他活动中选择的国家/地区的名称时覆盖 onActivityResult并在按钮

中设置国家/地区的名称
     @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;



    }

}

我的第二个活动的onCreate

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



        }
     });

}

我将非常感谢帮助!!!

谢谢!

1 个答案:

答案 0 :(得分:0)

看起来像Null指针取消引用(来自java API docs)

  

“在需要对象的情况下,当应用程序尝试使用null时抛出。”

如果没有看到代码,很难说更多。