gpt4 book ai didi

android - 未找到 startActivity 源

转载 作者:行者123 更新时间:2023-11-30 04:09:48 25 4
gpt4 key购买 nike

public void openOptions()
{
Intent intent=new Intent(this,Game.class);
//intent.putExtra("razmer", level);
startActivity(intent);

// Intent intent=new Intent(this,Options.class);
// intent.putExtra("level", level);
// startActivity(intent);
}

输出错误日志:

    06-14 10:27:15.049: W/dalvikvm(539): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
06-14 10:27:15.078: E/AndroidRuntime(539): FATAL EXCEPTION: main
06-14 10:27:15.078: E/AndroidRuntime(539): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{your.KrestikiNolikiActivity.namespace/your.KrestikiNolikiActivity.namespace.Game}:
java.lang.InstantiationException: can't instantiate class your.KrestikiNolikiActivity.namespace.Game; no empty constructor
06-14 10:27:15.078: E/AndroidRuntime(539): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
06-14 10:27:15.078: E/AndroidRuntime(539): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-14 10:27:15.078: E/AndroidRuntime(539): at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-14 10:27:15.078: E/AndroidRuntime(539): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-14 10:27:15.078: E/AndroidRuntime(539): at android.os.Handler.dispatchMessage(Handler.java:99)
06-14 10:27:15.078: E/AndroidRuntime(539): at android.os.Looper.loop(Looper.java:137)
06-14 10:27:15.078: E/AndroidRuntime(539): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-14 10:27:15.078: E/AndroidRuntime(539): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 10:27:15.078: E/AndroidRuntime(539): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 10:27:15.078: E/AndroidRuntime(539): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-14 10:27:15.078: E/AndroidRuntime(539): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-14 10:27:15.078: E/AndroidRuntime(539): at dalvik.system.NativeStart.main(Native Method)
06-14 10:27:15.078: E/AndroidRuntime(539): Caused by: java.lang.InstantiationException: can't instantiate class your.KrestikiNolikiActivity.namespace.Game; no empty constructor
06-14 10:27:15.078: E/AndroidRuntime(539): at java.lang.Class.newInstanceImpl(Native Method)
06-14 10:27:15.078: E/AndroidRuntime(539): at java.lang.Class.newInstance(Class.java:1319)
06-14 10:27:15.078: E/AndroidRuntime(539): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
06-14 10:27:15.078: E/AndroidRuntime(539): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
06-14 10:27:15.078: E/AndroidRuntime(539): ... 11 more

最佳答案

您需要向您的游戏类添加一个空白构造函数。

public class Game extends Activity {

public Game(){

}

}

之所以会发生这种情况,是因为您重写了构造函数

public Game(String something){
this.something = something;
}

您不应该在 Activity 中执行此操作,因为您无法使用构造函数实例化 Activity,因此无论如何它都没有效果

关于android - 未找到 startActivity 源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11031997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com