当前位置: 首页 > 知识库问答 >
问题:

AndroidRuntime致命异常:Main

彭浩穰
2023-03-14
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/scr_levelboard"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Survival" >

<ImageButton
    android:id="@+id/btn_porch"
    android:layout_width="100dip"
    android:layout_height="40dip"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="36dp"
    android:layout_marginTop="93dp"
    android:background="@null"
    android:scaleType="fitXY"
    android:src="@drawable/btn_porch" 
    android:onClick="LvlSelect"/>

<ImageButton
    android:id="@+id/btn_livingroom"
    android:layout_width="100dip"
    android:layout_height="40dip"
    android:layout_alignLeft="@+id/btn_porch"
    android:layout_below="@+id/btn_porch"
    android:background="@null"
    android:scaleType="fitXY"
    android:src="@drawable/btn_livingroom" 
    android:onClick="LvlSelect"/>

<ImageButton
    android:id="@+id/btnkitchen"
    android:layout_width="100dip"
    android:layout_height="40dip"
    android:layout_alignLeft="@+id/btnbedroom"
    android:layout_below="@+id/btnbedroom"
    android:layout_marginTop="14dp"
    android:background="@null"
    android:scaleType="fitXY"
    android:src="@drawable/btn_kitchen" 
    android:onClick="LvlSelect"/>

<ImageButton
    android:id="@+id/btnbedroom"
    android:layout_width="100dip"
    android:layout_height="40dip"
    android:layout_alignLeft="@+id/btn_livingroom"
    android:layout_below="@+id/btn_livingroom"
    android:background="@null"
    android:scaleType="fitXY"
    android:src="@drawable/btn_bedroom" 
    android:onClick="LvlSelect"/>

<ImageButton
    android:id="@+id/btnwashroom"
    android:layout_width="100dip"
    android:layout_height="40dip"
    android:layout_alignLeft="@+id/btnkitchen"
    android:layout_below="@+id/btnkitchen"
    android:layout_marginTop="18dp"
    android:background="@null"
    android:scaleType="fitXY"
    android:src="@drawable/btn_washroom" 
    android:onClick="LvlSelect"/>

<ImageButton
    android:id="@+id/btnbasement"
    android:layout_width="100dip"
    android:layout_height="40dip"
    android:layout_alignLeft="@+id/btnwashroom"
    android:layout_below="@+id/btnwashroom"
    android:background="@null"
    android:scaleType="fitXY"
    android:src="@drawable/btn_basement" 
    android:onClick="LvlSelect"/>

</RelativeLayout>
package com.example.thesis;

import android.os.Bundle;

import android.view.View;
import android.view.Window;
import android.app.Activity;

import android.content.Intent;


public class Survival extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_survival);

}
    public void LvlSelect (View view){
        if(view.getId()==R.id.btn_porch){
        Intent d=new Intent(this, PorchStartactivity.class);
        startActivity(d);}

        else if(view.getId()==R.id.btn_livingroom){
            Intent b=new Intent(this, LvroomStartactivity.class);
            startActivity(b);
            }
            else if(view.getId()==R.id.btn_bdroom){
            Intent c=new Intent(this, BdroomStartactivity.class);
            startActivity(c);

        }
    }
}
package com.example.thesis;



import android.os.Bundle;
import android.view.Window;
import android.app.Activity;
import android.media.MediaPlayer;


public class PorchStartactivity extends Activity {

    MediaPlayer bgmusic;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(new PorchGameView(this));

        bgmusic = MediaPlayer.create(PorchStartactivity.this, R.raw.bgm_housefly);
        bgmusic.setLooping(true);
        bgmusic.start();
    }
    @Override
    protected void onPause(){
        super.onPause();
        bgmusic.release();
        finish();
    }
}
01-15 22:24:11.428: E/AndroidRuntime(4170): FATAL EXCEPTION: main
01-15 22:24:11.428: E/AndroidRuntime(4170): java.lang.IllegalStateException: Could not execute method of the activity
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.view.View$1.onClick(View.java:3599)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.view.View.performClick(View.java:4204)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.view.View$PerformClick.run(View.java:17355)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.os.Handler.handleCallback(Handler.java:725)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.os.Looper.loop(Looper.java:137)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.app.ActivityThread.main(ActivityThread.java:5041)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at java.lang.reflect.Method.invokeNative(Native Method)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at java.lang.reflect.Method.invoke(Method.java:511)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at dalvik.system.NativeStart.main(Native Method)
01-15 22:24:11.428: E/AndroidRuntime(4170): Caused by: java.lang.reflect.InvocationTargetException
01-15 22:24:11.428: E/AndroidRuntime(4170):     at java.lang.reflect.Method.invokeNative(Native Method)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at java.lang.reflect.Method.invoke(Method.java:511)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.view.View$1.onClick(View.java:3594)
01-15 22:24:11.428: E/AndroidRuntime(4170):     ... 11 more
01-15 22:24:11.428: E/AndroidRuntime(4170): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.thesis/com.example.thesis.PorchStartactivity}; have you declared this activity in your AndroidManifest.xml?
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.app.Activity.startActivityForResult(Activity.java:3370)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.app.Activity.startActivityForResult(Activity.java:3331)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.app.Activity.startActivity(Activity.java:3566)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at android.app.Activity.startActivity(Activity.java:3534)
01-15 22:24:11.428: E/AndroidRuntime(4170):     at com.example.thesis.Survival.LvlSelect(Survival.java:24)
01-15 22:24:11.428: E/AndroidRuntime(4170):     ... 14 more
01-15 22:24:15.369: E/Trace(5617): error opening trace file: No such file or directory (2)

共有1个答案

鲁鹤轩
2023-03-14

您的意图找不到“PorchStartActivity”类。

在androidmanifest中声明“porchstartactivity”活动

此外,其他活动(在您的情况下是级别)需要在应用程序清单文件中声明为活动。要了解更多为什么这很重要的信息,请阅读以下内容。

 类似资料: