Quote:
Originally Posted by newbie123
Hi. I am having problem running earthquake example in Chapter 6 on the emulator. I got a blank screen with the title of the activity. Any suggestions?
|
I experienced the same.
Check in logcat if you got this exception :
"android.view.ViewRoot$CalledFromWrongThreadExcept ion: Only the original thread that created a view hierarchy can touch its views"
If so, then it is likely due to calling aa.notifyDataSetChanged() in earthquakeListfragment.java from the thread that started refreshEarthquakes().
So also the code in the book with the thread does not work!!
I tried to call aa.notifyDataSetChanged() in the main thread, and delete aa.notifyDataSetChanged() from earthquakeListfragment.java, and invoked it with a button for instance.
Pressing the button (but first wait some seconds cause the procedure refresh_Earthquake is time consuming!) it filled the list with the earthquake entries.
For instance in earthquake.java's onCreate handler, (and also an extra button ListButton in main.xml) :
Code:
button = (Button)findViewById(R.id.ListButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
EarthquakeListFragment earthquakeList =
(EarthquakeListFragment)fm.findFragmentById(R.id.EarthquakeListFragment);
earthquakeList.aa.notifyDataSetChanged();
}
});
Good luck.