I have done this many times in different apps but this is my first time on a honeycomb app and for some reason it is not working...
I call
Intent myIntent = new Intent(getApplicationContext(), PvP.class);
startActivity(myIntent);
When a button is pushed. Here is my manifest:
<?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>
Also, if needed here is the other class (Just the 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) {
开发者_如何学Python super.onCreate(savedInstanceState);
setContentView(R.layout.game);
turn = false;
}
}
EDIT: FORGOT LOGCAT! Sorry! Here:
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
Any ideas? maybe its something stupid, I don't know. Cant seem to figure it out.
TextView p1 = (TextView) findViewById(R.id.p1);
TextView p2 = (TextView) findViewById(R.id.p2);
Those must be called in onCreate(), after the layout has been set.
精彩评论