I’m trying to launch an activity when my application starts, but it immediately crashes with a runtime exception. Strangely, an identical activity will work just fine, with the only difference being the name of the activity.
Here is what I’m calling:
int SignupActivityId = 0;
Intent intent = new Intent(this, SignupActivity.class); // Crashes
//Intent intent = new Intent(this, NewGameActivity.class); // Doesn't not crash
this.startActivityForResult(intent, SignupActivityId);
Here is the definition for each activity, notice they are practically identical, even to loading the same resource xml:
SignupActivity – Crashes
package com.example.games.MyGame;
import android.app.Activity;
import android.os.Bundle;
public class SignupActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.new_game);
}
}
NewGameActivity – does not crash
package com.example.games.MyGame;
import android.app.Activity;
import android.os.Bundle;
public class NewGameActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.new_game);
}
}
How can SignupActivity crash, but NewGameActivity doesn’t??
It turns out, after checking LogCat, the layout xml was missing an android:layout_width from one of the views. It turns out that’s required.