English 中文(简体)
Anders SDK 努埃尔人例外
原标题:Android SDK Nullpointer exception

我想建立一个健全的板,这样,当你点击 but子时,它就能够发挥声。

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.akali);

    Button b = (Button) findViewById(R.id.akaliJokeButton);
    b.setOnClickListener(new OnClickListener() {


        public void onClick(View v) {
            MediaPlayer mp = MediaPlayer.create(Akali.this, R.raw.akalijoke);
            mp.start();
        }
    });

}

That is my code that I have so far. But I get a no pointer exception error

07-25 14:36:47.919: DEBUG/AndroidRuntime(1079): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
07-25 14:36:47.919: DEBUG/AndroidRuntime(1079): CheckJNI is ON
07-25 14:36:48.529: DEBUG/AndroidRuntime(1079): Calling main entry com.android.commands.pm.Pm
07-25 14:36:48.560: DEBUG/AndroidRuntime(1079): Shutting down VM
07-25 14:36:48.569: DEBUG/dalvikvm(1079): GC_CONCURRENT freed 101K, 71% free 297K/1024K, external 0K/0K, paused 1ms+1ms
07-25 14:36:48.579: DEBUG/dalvikvm(1079): Debugger has detached; object registry had 1 entries
07-25 14:36:48.599: INFO/dalvikvm(1079): JNI: AttachCurrentThread (from ???.???)
07-25 14:36:48.599: INFO/AndroidRuntime(1079): NOTE: attach of thread  Binder Thread #3  failed
07-25 14:36:48.989: DEBUG/AndroidRuntime(1089): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
07-25 14:36:48.989: DEBUG/AndroidRuntime(1089): CheckJNI is ON
07-25 14:36:49.579: DEBUG/AndroidRuntime(1089): Calling main entry com.android.commands.am.Am
07-25 14:36:49.609: INFO/ActivityManager(61): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.reg.lolsoundboard/.Main } from pid 1089
07-25 14:36:49.829: DEBUG/AndroidRuntime(1089): Shutting down VM
07-25 14:36:49.849: DEBUG/dalvikvm(1089): GC_CONCURRENT freed 102K, 69% free 320K/1024K, external 0K/0K, paused 1ms+1ms
07-25 14:36:49.849: DEBUG/jdwp(1089): Got wake-up signal, bailing out of select
07-25 14:36:49.849: DEBUG/dalvikvm(1089): Debugger has detached; object registry had 1 entries
07-25 14:36:49.879: INFO/ActivityManager(61): Start proc com.reg.lolsoundboard for activity com.reg.lolsoundboard/.Main: pid=1099 uid=10036 gids={}
07-25 14:36:49.931: INFO/AndroidRuntime(1089): NOTE: attach of thread  Binder Thread #3  failed
07-25 14:36:50.839: DEBUG/dalvikvm(1099): GC_EXTERNAL_ALLOC freed 49K, 53% free 2557K/5379K, external 2002K/2137K, paused 54ms
07-25 14:36:51.250: INFO/ActivityManager(61): Displayed com.reg.lolsoundboard/.Main: +1s426ms (total +8m29s588ms)
07-25 14:36:52.179: INFO/ActivityManager(61): Starting: Intent { cmp=com.reg.lolsoundboard/.Akali } from pid 1099
07-25 14:36:52.299: DEBUG/AndroidRuntime(1099): Shutting down VM
07-25 14:36:52.299: WARN/dalvikvm(1099): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): FATAL EXCEPTION: main
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.reg.lolsoundboard/com.reg.lolsoundboard.Akali}: java.lang.NullPointerException
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at android.os.Looper.loop(Looper.java:123)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at android.app.ActivityThread.main(ActivityThread.java:3683)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at java.lang.reflect.Method.invokeNative(Native Method)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at java.lang.reflect.Method.invoke(Method.java:507)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at dalvik.system.NativeStart.main(Native Method)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): Caused by: java.lang.NullPointerException
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at com.reg.lolsoundboard.Akali.onCreate(Akali.java:19)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099):     ... 11 more
07-25 14:36:52.319: WARN/ActivityManager(61):   Force finishing activity com.reg.lolsoundboard/.Akali
07-25 14:36:52.329: WARN/ActivityManager(61):   Force finishing activity com.reg.lolsoundboard/.Main
07-25 14:36:52.839: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{406fa098 com.reg.lolsoundboard/.Akali}
07-25 14:36:54.199: INFO/Process(1099): Sending signal. PID: 1099 SIG: 9
07-25 14:36:54.209: INFO/ActivityManager(61): Process com.reg.lolsoundboard (pid 1099) has died.
07-25 14:36:54.209: INFO/WindowManager(61): WIN DEATH: Window{40761880 com.reg.lolsoundboard/com.reg.lolsoundboard.Main paused=true}
07-25 14:36:54.299: WARN/InputManagerService(61): Got RemoteException sending setActive(false) notification to pid 1099 uid 10036

XML 文件

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/akalibg" android:weightSum="1">
        <RelativeLayout android:layout_width="match_parent" android:id="@+id/relativeLayout1" android:layout_height="wrap_content" android:layout_weight="0.33">

            <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:id="@+id/akaliLaugh1" android:text="Laugh 1"></Button>
            <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:text="Laugh 2" android:id="@+id/akaliLaugh2"></Button>
            <Button android:text="Laugh 3" android:id="@+id/akaliLaugh3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignTop="@+id/akaliLaugh4" android:layout_alignLeft="@+id/akaliJokeButton"></Button>
            <Button android:id="@+id/akaliLaugh4" android:layout_height="wrap_content" android:keepScreenOn="false" android:layout_width="wrap_content" android:layout_centerVertical="true" android:layout_alignLeft="@+id/akaliLaugh1" android:text="Laugh 4"></Button>
            <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignBottom="@+id/akaliLaugh4" android:layout_alignParentRight="true" android:id="@+id/akaliTaunt" android:layout_alignLeft="@+id/akaliLaugh2" android:text="Taunt 1"></Button>
            <Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignRight="@+id/akaliLaugh3" android:text="Joke 1"></Button>

            </RelativeLayout>
        <RelativeLayout android:layout_width="match_parent" android:id="@+id/relativeLayout2" android:layout_height="wrap_content">
        </RelativeLayout>


    </LinearLayout>

B. 进入实际音板的首选家庭屏幕

package com.reg.lolsoundboard;

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 Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


       ImageButton b = (ImageButton) findViewById(R.id.akaliButton);
       b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            startActivity(new Intent(Main.this, Akali.class));

        }
    });
    }
}
最佳回答

你们似乎没有“kaliJokeButton”的 but子。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签