打开活动崩溃应用程序

时间:2015-08-08 17:52:19

标签: class android-activity onclicklistener

嘿,伙计我是编码新手,而且最近我一直在开发应用程序。我已经将OnClickListener设置为我的按钮,每个按钮都会导致我相信我在Manifest中说过的另一个类。当我启动我的应用程序时,其中一个按钮可以工作,但另一个按下应用程序并告诉我找不到该课程,请帮忙。这是一些代码:

    public class CharPage extends ActionBarActivity {
private static Button button_next;
private static Button button_kk;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_char_page);
    OnClickButtonListener();
}
public void OnClickButtonListener() {
{
    button_kk= (Button) findViewById(R.id.buttonkk);
    button_kk.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                     Intent intent = new        Intent("com.example.jmac.mortalkombat.Kotal_Khan");
                    startActivity(intent);
                }
            }
    );
}
button_next = (Button) findViewById(R.id.button);

button_next.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent("com.example.jmac.mortalkombat.CharPage2");
                startActivity(intent);

            }
        }
);

}

然后有我的清单:

     <activity
        android:name=".CharPage"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".CharPage2"
        android:label="@string/title_activity_char_page2" >
        <intent-filter>
            <action android:name="com.example.jmac.mortalkombat.CharPage2" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".CharPage3"
        android:label="@string/title_activity_char_page3" >
        <intent-filter>
            <action android:name="com.example.jmac.mortalkombat.CharPage3" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Kotal_Khan"
        android:label="@string/title_activity_kotal__khan" >
        <intent-filter>
            <action android:name="com.example.jmac.mortalkombat.Kotal_Khan" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

StackTrace:  26010-26010 / com.example.jmac.mortalkombat E / AndroidRuntime:FATAL EXCEPTION:main     处理:com.example.jmac.mortalkombat,PID:26010     android.content.ActivityNotFoundException:找不到处理Intent的Activity {act = com.example.jmac.mortalkombat.Kotal_Khan}             在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1801)             在android.app.Instrumentation.execStartActivity(Instrumentation.java:1499)             在android.app.Activity.startActivityForResult(Activity.java:3942)             在android.app.Activity.startActivityForResult(Activity.java:3889)             在android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)             在android.app.Activity.startActivity(Activity.java:4213)             在android.app.Activity.startActivity(Activity.java:4181)             在com.example.jmac.mortalkombat.CharPage $ 1.onClick(CharPage.java:37)             在android.view.View.performClick(View.java:5197)             在android.view.View $ PerformClick.run(View.java:20926)             在android.os.Handler.handleCallback(Handler.java:739)             在android.os.Handler.dispatchMessage(Handler.java:95)             在android.os.Looper.loop(Looper.java:145)             在android.app.ActivityThread.main(ActivityThread.java:5942)             at java.lang.reflect.Method.invoke(Native Method)             在java.lang.reflect.Method.invoke(Method.java:372)             在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1399)             在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

2 个答案:

答案 0 :(得分:0)

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_char_page);
    button_kk= (Button) findViewById(R.id.buttonkk);
    button_next = (Button) findViewById(R.id.button);
    OnClickButtonListener();
}
public void OnClickButtonListener() {
{

    button_kk.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                     Intent intent = new        Intent("com.example.jmac.mortalkombat.Kotal_Khan");
                    startActivity(intent);
                }
            }
    );


button_next.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent("com.example.jmac.mortalkombat.CharPage2");
                startActivity(intent);

            }
        }
);
}

答案 1 :(得分:0)

首先确保您的项目中有一个具有此名称的活动&#34; Kotal_Khan&#34;并且包含在&#34; com.example.jmac.mortalkombat&#34;因为这是你在清单中声明的​​内容。

第二次替换。

Intent intent = new Intent("com.example.jmac.mortalkombat.Kotal_Khan");

代表

Intent intent = new Intent(getApplicationContext(), YOURCLASSNAME.class);

我假设将是Kotal_Khan.class。

祝你好运。