开发者

Android Runtime Exception when starting an intent

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.startActivit开发者_运维技巧yForResult(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??


Do you have defined the Activity "SignupActivity" into your AndroidManifest.xml??? =D use the LogCat to get the Exception.


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.


There is a difference. You have int SignupActivityId = 0;


Have you tried startActivity(intent); ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜