I've spent the last few hours figuring out why my application is crashing without an error message on load.
Basically, when I run it either by USB or by emulator, the screen refreshes every half a second or so. Looking at the log, it seems to be running onCreate in a loop. I can't figure out why! Eventually, there are a bunch of 'Channel is unrecoverably broken and will be disposed' messages. This message also turns up a lot:
07-15 13:59:22.334: ERROR/AbstractCompatWrapper(381): Invalid input to AbstructCompatWrapper 07-15 13:59:22.334: ERROR/CompatUtils(381): Exception in invoke: NullPointerException
I can post a complete log if you like, but I couldn't find anything useful there.
Finally, I discovered that removing the call to 'fillActionBar', a method that instantiates the action bar, 'fixes' the problem. However, I would like to be able to use the action bar! What have I done wrong?
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
resultBox = (TextView) findViewById(R.id.readout_values);
// commenting out the following line fixes the problem,
// but removes the action bar.
this.actionBar = fillActionBar();
try {
specialHttpClient = new SpecialHttpClient(
"username", "password");
} catch (Exception e) {
Dbg.loge(this.getClass().getName(), "Could not instantiate client", e);
}
}
private ActionBar fillActionBar() {
ActionBar bar = getActionBar();// getSupportActionBar();
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_spinner_dropdown_item,
//R.layout.sherlock_spinner_item,
pages
);
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ActionBar.OnNavigationListener navListener = new ActionBar.OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
Intent i = null;
switch(itemPosition) {
case 0:
i = new Intent(context, RecorderActivity.class);
break;
case 1:
i = new Intent(context, TrackerActivity.class);
break;
}
startActivity(i);
return true;
}
};
bar.setListNavigationCallbacks(spinnerAdapter, navListener);
return bar;
}
** EDIT **
The problem seems to be that startActivity(i) is being called even when no button is pressed. Moving that call to the second menu item only seems to fix the problem - but why is this happening?