尝试从另一个活动调用活动时获取StackOverflowError

时间:2012-03-11 02:22:53

标签: java android

我正在尝试开发一个小应用程序BusTracker,当你提到来自和去的地方时,它会列出一个公共汽车列表。 我有一个按钮,当点击它将调用另一个活动(这是一个列表活动),将显示一个地方列表。我选择一个并保存地点,并在firstActivity中填充文本字段。我在第二个活动的oncreate方法中得到stackOverFlowerror。任何人都可以给我一个可能的理由吗?

这是我在firstActivity onClick方法中的代码

case R.id.from_button:
Intent i= new Intent(this,PlacesActivity.class);
startActivity(i);
String ss=PlacesActivity.getPlace();

然后在secondActivity

this.onCreate(onSavedInstanceState);
    setContentView(R.layout.places);
     ListView placesList=(ListView)this.findViewById(R.layout.places);

     placesList.setVisibility(View.VISIBLE);
     placesList.setAdapter(new ArrayAdapter(this,R.array.fromArray));
     placesList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
     //placesList.setOnItemClickListener(this);

}

public void onListItemClick(ListView l, View v, int position, long id)
{
    Object o=this.getListAdapter().getItem(position);
    String s=o.toString();
    place=s;
    System.out.println("sssssssssssss"+s);
}

我得到错误:

03-10 18:02:46.352: E/AndroidRuntime(542): FATAL EXCEPTION: main
03-10 18:02:46.352: E/AndroidRuntime(542): java.lang.StackOverflowError
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)
03-10 18:02:46.352: E/AndroidRuntime(542):  at com.example.BusTracker.PlacesActivity.onCreate(PlacesActivity.java:17)

1 个答案:

答案 0 :(得分:3)

你不应该调用this.onCreate(onSavedInstanceState);,而是调用super.onCreate(onSavedInstanceState);,否则你会在无限的递归中调用create,然后你会得到STackOverflow。