Я пытаюсь заставить кнопку начать другой класс. Я получаю исключение нулевого указателя, которое я нашел с помощью logcat, и я не знаю почему.
package com.Juggle2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
public class Juggle2 extends Activity {
public static final String LOG_TAG = "Juggle2";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Button StartGameButton = (Button) findViewById(R.id.StartGame);
StartGameButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Juggle2.this, StartGame.class);
startActivity(i);
}
});
И мой XML-манифест:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Juggle2"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Juggle2"
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=".Panel"></activity>
</application>
</manifest>
Вот лог
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): FATAL EXCEPTION: main
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Juggle2/com.Juggle2.Juggle2}: java.lang.NullPointerException
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at android.os.Looper.loop(Looper.java:126)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at android.app.ActivityThread.main(ActivityThread.java:3997)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at java.lang.reflect.Method.invoke(Method.java:491)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at dalvik.system.NativeStart.main(Native Method)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): Caused by: java.lang.NullPointerException
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at com.Juggle2.Juggle2.onCreate(Juggle2.java:24)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
05-27 21:12:07.749: ERROR/AndroidRuntime(6705): ... 11 more
А внутри main.xml:
есть эта кнопка
<Button
android:id="@+id/StartGame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/startgame_button"
>