Android - 更改活动

时间:2010-12-29 22:45:32

标签: android

我有改变活动的问题。我将该行添加到AndroidManifest并且它不起作用。这意味着点击“NowaGra”ImageButton后出现错误。 (错误 - “抱歉!,应用程序Gra_Milionerzy(进程gra_Milionerzy.Gra)已经意外停止了。请再试一次)

这是主要活动(Gra - 英文游戏)

    package gra_Milionerzy.Gra;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class Gra extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        /*   Menu Gry */  

          ImageButton Nowa_Gra = (ImageButton)this.findViewById(R.id.nowa_gra);
          Nowa_Gra.setOnClickListener(new OnClickListener()
            {
      public void onClick(View v)
       {
       Intent intent = new Intent(Gra.this, NowaGra.class);
        startActivity(intent);   
          }      

            });


          ImageButton Profile = (ImageButton)this.findViewById(R.id.profile);
          Profile.setOnClickListener(new OnClickListener()
            {
      public void onClick(View arg0)
       {
        finish();
       }
            });

          ImageButton OAutorze = (ImageButton)this.findViewById(R.id.o_autorze);
          OAutorze.setOnClickListener(new OnClickListener()
            {
      public void onClick(View arg0)
       {
        finish();
       }
            });

          ImageButton Ustawienia = (ImageButton)this.findViewById(R.id.ustawienia);
          Ustawienia.setOnClickListener(new OnClickListener()
            {
      public void onClick(View arg0)
       {
        finish();
       }
            });

          /*  Koniec Menu Gry  */


          /*  Kola Ratunkowe  */




    }
}

这里是NowaGra(NewGame; P)

package gra_Milionerzy.Gra;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class NowaGra extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       finish();

        /*   Kola Ratunkowe */  





    }
}

和AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="gra_Milionerzy.Gra"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Glowna"
                  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=".NowaGra"></activity>
    </application>


<uses-sdk android:minSdkVersion="1"></uses-sdk>
</manifest> 

加上LogCat

12-30 12:43:06.738: ERROR/AndroidRuntime(1379): FATAL EXCEPTION: main
12-30 12:43:06.738: ERROR/AndroidRuntime(1379): android.content.ActivityNotFoundException: Unable to find explicit activity class {gra_Milionerzy.Gra/gra_Milionerzy.Gra.NowaGra}; have you declared this activity in your AndroidManifest.xml?
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.app.Activity.startActivityForResult(Activity.java:2817)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.app.Activity.startActivity(Activity.java:2923)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at gra_Milionerzy.Gra.Gra$1.onClick(Gra.java:25)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.view.View.performClick(View.java:2408)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.view.View$PerformClick.run(View.java:8816)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.os.Handler.handleCallback(Handler.java:587)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.os.Looper.loop(Looper.java:123)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at java.lang.reflect.Method.invokeNative(Native Method)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at java.lang.reflect.Method.invoke(Method.java:521)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-30 12:43:06.738: ERROR/AndroidRuntime(1379):     at dalvik.system.NativeStart.main(Native Method)

我做错了什么?有什么想法吗?

__ _ __ _ __ _ __ _ __ _ __ _ ____ - ANWSER - 恶意在AndroidManifest中写道

1 个答案:

答案 0 :(得分:1)

如果使用eclipse,则在调试中运行它,它将倾向于停止异常。您可以检查详细消息的异常。或者,检查logcat,如果尚未显示堆栈跟踪,则可以将其作为eclipse中的视图添加到您的透视图中。