2011-03-06 97 views
0

我已经在不同的应用程序做了很多次,但是这是我第一次在蜂窝应用程序,由于某种原因,它是不工作...强制关闭活动开关?

我打电话

Intent myIntent = new Intent(getApplicationContext(), PvP.class); 

    startActivity(myIntent); 

当按下一个按钮。这里是我的清单:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.aaron.decker.make15" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="11" /> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".MainMenu" 
        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="PvP" android:label="PvP" android:theme="@android:style/Theme.NoTitleBar"> </activity> 

    </application> 
</manifest> 

另外,如果在这里需要的是其他类(就在的onCreate):

package com.aaron.decker.make15; 

    import android.app.Activity; 
    import android.os.Bundle; 
    import android.view.View; 
    import android.widget.TextView; 

    public class PvP extends Activity{ 
     private int PLAYER_ONE_SCORE; 
     private int PLATER_TWO_SCORE; 
     private boolean turn; 
     //Button button = (Button) findViewById(R.id.button_id); 
     TextView p1 = (TextView) findViewById(R.id.p1); 
     TextView p2 = (TextView) findViewById(R.id.p2); 

    //If turn is false then it is player one's turn, else if it is true it is player two's turn. FALSE = P1 TRUE = P2 

      public void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       setContentView(R.layout.game); 
       turn = false; 


      } 
} 

编辑:忘了logcat的!抱歉!这里:

03-06 16:08:13.382: ERROR/AndroidRuntime(652): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.aaron.decker.make15/com.aaron.decker.make15.PvP}: java.lang.NullPointerException 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.app.ActivityThread.access$1500(ActivityThread.java:123) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.os.Handler.dispatchMessage(Handler.java:99) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.os.Looper.loop(Looper.java:126) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.app.ActivityThread.main(ActivityThread.java:3997) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at java.lang.reflect.Method.invokeNative(Native Method) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at java.lang.reflect.Method.invoke(Method.java:491) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at dalvik.system.NativeStart.main(Native Method) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652): Caused by: java.lang.NullPointerException 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.app.Activity.findViewById(Activity.java:1741) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at com.aaron.decker.make15.PvP.<init>(PvP.java:13) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at java.lang.Class.newInstanceImpl(Native Method) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at java.lang.Class.newInstance(Class.java:1424) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.app.Instrumentation.newActivity(Instrumentation.java:1022) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 
03-06 16:08:13.382: ERROR/AndroidRuntime(652):  ... 11 more 

任何想法?也许它很愚蠢,我不知道。不能似乎弄清楚。

+0

也许类名前清单中的缺失点? ' bigstones 2011-03-06 22:17:28

+0

不...无法工作 – 2011-03-06 22:21:04

回答

3
TextView p1 = (TextView) findViewById(R.id.p1); 
TextView p2 = (TextView) findViewById(R.id.p2); 

这些必须在布局设置后在onCreate()中调用。

+0

谢谢!它的工作:) – 2011-03-06 22:27:03

+0

你打败了我。 :-) – Squonk 2011-03-06 22:28:24