0

我一遍又一遍地尝试,但我找不到解决方案,错误日志一直告诉我它无法启动意图,我不知道该怎么做。当我单击“动物”按钮和“人类”按钮时会发生错误。另外,“人”按钮是指打嗝,请帮忙。谢谢你。

错误日志

03-27 20:44:57.342: E/AndroidRuntime(5348): [FRANDRO_ERR_HANDLER] com_android_internal_os_RuntimeInit_BlueErrorHandler
03-27 20:44:57.342: E/AndroidRuntime(5348): FATAL EXCEPTION: main
03-27 20:44:57.342: E/AndroidRuntime(5348): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.triplec.letthewindout_fart/com.triplec.letthewindout_fart.Animals}: java.lang.NullPointerException
03-27 20:44:57.342: E/AndroidRuntime(5348):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1662)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1678)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at android.os.Looper.loop(Looper.java:130)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at android.app.ActivityThread.main(ActivityThread.java:3740)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at java.lang.reflect.Method.invokeNative(Native Method)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at java.lang.reflect.Method.invoke(Method.java:507)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at dalvik.system.NativeStart.main(Native Method)
03-27 20:44:57.342: E/AndroidRuntime(5348): Caused by: java.lang.NullPointerException
03-27 20:44:57.342: E/AndroidRuntime(5348):     at com.triplec.letthewindout_fart.Animals.onCreate(Animals.java:28)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-27 20:44:57.342: E/AndroidRuntime(5348):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1626)

这是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
package="com.triplec.letthewindout_fart"
android:versionCode="5"
android:versionName="5" xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/fart_sign"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.triplec.letthewindout_fart.MainActivity"
        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="com.triplec.letthewindout_fart.Menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.triplec.letthewindout_fart.MENU" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.triplec.letthewindout_fart.Animals"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.triplec.letthewindout_fart.ANIMALS" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.triplec.letthewindout_fart.Burp"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.triplec.letthewindout_fart.BURP" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.triplec.letthewindout_fart.Mainu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.triplec.letthewindout_fart.MAI" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

<activity 
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
/>

</application>

我的动物.java

package com.triplec.letthewindout_fart;

import java.io.IOException;

import com.google.ads.AdRequest;
import com.google.ads.AdView;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Animals extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.animals);

    AdView ad = (AdView)findViewById(R.id.adView);
    ad.loadAd(new AdRequest());


    final MediaPlayer sound01 = MediaPlayer.create(this, R.raw.alpaca_mating_call);
    final MediaPlayer sound02 = MediaPlayer.create(this, R.raw.angry_cat);
    final MediaPlayer sound03 = MediaPlayer.create(this, R.raw.bluejay_call);
    final MediaPlayer sound04 = MediaPlayer.create(this, R.raw.cat_meow);
    final MediaPlayer sound05 = MediaPlayer.create(this, R.raw.cow);
    final MediaPlayer sound06 = MediaPlayer.create(this, R.raw.dog_kennel);
    final MediaPlayer sound07 = MediaPlayer.create(this, R.raw.frogs);
    final MediaPlayer sound08 = MediaPlayer.create(this, R.raw.growling_snarling_dogs);
    final MediaPlayer sound09 = MediaPlayer.create(this, R.raw.horse_blow);
    final MediaPlayer sound10 = MediaPlayer.create(this, R.raw.horse_neigh);
    final MediaPlayer sound11 = MediaPlayer.create(this, R.raw.kitten_meow);
    final MediaPlayer sound12 = MediaPlayer.create(this, R.raw.laughing_kookaburra_birds);
    final MediaPlayer sound13 = MediaPlayer.create(this, R.raw.lion_roar);
    final MediaPlayer sound14 = MediaPlayer.create(this, R.raw.quack);
    final MediaPlayer sound15 = MediaPlayer.create(this, R.raw.raccoon);
    final MediaPlayer sound16 = MediaPlayer.create(this, R.raw.rooster);
    final MediaPlayer sound17 = MediaPlayer.create(this, R.raw.trex);
    final MediaPlayer sound18 = MediaPlayer.create(this, R.raw.warbling_vireo);
    final MediaPlayer sound19 = MediaPlayer.create(this, R.raw.zebra_call);


    // play sound files on clicks
    Button s01 = (Button) findViewById(R.id.btalpaca); 
    s01.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound01.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound01.start();                
            }

    });
    Button s02 = (Button) findViewById(R.id.btangry); 
    s02.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound02.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound02.start();
        }
    });

    Button s03 = (Button) findViewById(R.id.btblue); 
    s03.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound03.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound03.start();
        }
    });


    Button s04 = (Button) findViewById(R.id.btcat); 
    s04.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound04.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound04.start();
        }
    });


    Button s05 = (Button) findViewById(R.id.btcow); 
    s05.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound05.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound05.start();
        }
    });

    Button s06 = (Button) findViewById(R.id.btdog); 
    s06.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound06.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound06.start();
        }
    });

    Button s07 = (Button) findViewById(R.id.btfrog); 
    s07.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound07.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound07.start();
        }
    });

    Button s08 = (Button) findViewById(R.id.btgrowl); 
    s08.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound08.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound08.start();
        }
    });

    Button s09 = (Button) findViewById(R.id.bthorse); 
    s09.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound09.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound09.start();
        }
    });

    Button s10 = (Button) findViewById(R.id.bthorse2); 
    s10.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound10.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound10.start();
        }
    });

    Button s11 = (Button) findViewById(R.id.btkitten); 
    s11.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound11.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound11.start();
        }
    });

    Button s12 = (Button) findViewById(R.id.btlaugh); 
    s12.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound12.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound12.start();
        }
    });

    Button s13 = (Button) findViewById(R.id.btlion); 
    s13.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound13.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound13.start();
        }
    });

    Button s14 = (Button) findViewById(R.id.btquack); 
    s14.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound14.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound14.start();
        }
    });

    Button s15 = (Button) findViewById(R.id.btracoon); 
    s15.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound15.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound15.start();
        }
    });

    Button s16 = (Button) findViewById(R.id.btrooster); 
    s16.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound16.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound16.start();
        }
    });

    Button s17 = (Button) findViewById(R.id.btt); 
    s17.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound17.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound17.start();
        }
    });

    Button s18 = (Button) findViewById(R.id.btwarb); 
    s18.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound18.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound18.start();
        }
    });

    Button s19 = (Button) findViewById(R.id.btzebra); 
    s19.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                sound19.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sound19.start();
        }
    });

}
}

最后,这是我的“主要”,错误日志在我的项目中说了一些关于致命的(唯一称为“主要”的东西)是一个 XML,所以我不知道它为什么这样做。

我的“主要”

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/warning"
android:orientation="vertical"
>



<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

 <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ads:adSize="BANNER"
        ads:adUnitId="a1513e8c7087157"
        ads:loadAdOnCreate="true" >
</com.google.ads.AdView>

        <Button
            android:id="@+id/bKing"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="King Farthur"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bLawn"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Lawn Mower"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bString"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="String Cheese"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bShort"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Short Ripper"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bSharp"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Sharp Fart"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bMotor"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Motor Bike"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bTrial"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Fart Trail"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bRigid"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Rigid Fart"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bGirl"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Girl Fart"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bLong"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Long Fart"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bQuick"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Quick Fart"
            android:textSize="20sp" />

        <Button
            android:id="@+id/bWindy"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:text="Windy Fart"
            android:textSize="20sp" />



    </LinearLayout>
</ScrollView>

</LinearLayout>
4

1 回答 1

1
setContentView(R.layout.animals);
                        ^^^^^^^ --> This is wrong. It should be main here.

上述说法是错误的。它应该是

setContentView(R.layout.main);

因为您在问题中提到的adView包含main.xml 的布局因为,您将布局设置为,animals而不是main您的(AdView)findViewById(R.id.adView);return null,因为布局adView中不存在animals

于 2013-03-28T03:58:22.287 回答