1
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
4

2 回答 2

1

您需要在 Game 类中添加一个空白构造函数。

IE

public class Game extends Activity {

    public Game(){

    }

}

所以发生这种情况是因为您已经覆盖了构造函数

IE

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

您不应该在活动中执行此操作,因为您无法使用构造函数实例化活动,因此无论如何它都不会产生影响

于 2012-06-14T11:22:28.000 回答
0

将此添加到您的清单文件中。每个类都应该有一个清单中提到的活动。

<activity  android:name=".Game"  
           android:label="@string/app_name">  
</activity>
于 2014-10-06T02:58:57.313 回答