I am trying to develop a small app BusTracker which will list down a list of buses when you mention the from and to places.
I have a frombutton which when clicked will call another activity(which is a listactivity) that will show a list of places. I choose one and the place gets saved and textfield in the firstActivity gets populated with that. I’m getting stackOverFlowerror in the oncreate method of the second activity. can anyone pls give me a possible reason for this?
Here is my code in the firstActivity onClick method
case R.id.from_button:
Intent i= new Intent(this,PlacesActivity.class);
startActivity(i);
String ss=PlacesActivity.getPlace();
Then in the 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);
}
Error I get:
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)
You shouldn’t call
this.onCreate(onSavedInstanceState);, butsuper.onCreate(onSavedInstanceState);otherwise you are in an endless recursion of calling on create and then you get the STackOverflow.