Android应用程序崩溃

Android应用程序崩溃,android,Android,我正在尝试制作一个android应用程序。当我加载它时,它会显示首页。当我点击按钮时,它意外地停止了。以下是logcat报告 05-09 23:47:51.570: E/AndroidRuntime(881): FATAL EXCEPTION: main 05-09 23:47:51.570: E/AndroidRuntime(881): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.

我正在尝试制作一个android应用程序。当我加载它时,它会显示首页。当我点击按钮时,它意外地停止了。以下是logcat报告

05-09 23:47:51.570: E/AndroidRuntime(881): FATAL EXCEPTION: main
05-09 23:47:51.570: E/AndroidRuntime(881): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.besafe/com.example.besafe.Tips}: java.lang.NullPointerException
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.os.Looper.loop(Looper.java:137)
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.app.ActivityThread.main(ActivityThread.java:5103)
05-09 23:47:51.570: E/AndroidRuntime(881):  at java.lang.reflect.Method.invokeNative(Native Method)
05-09 23:47:51.570: E/AndroidRuntime(881):  at java.lang.reflect.Method.invoke(Method.java:525)
05-09 23:47:51.570: E/AndroidRuntime(881):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
05-09 23:47:51.570: E/AndroidRuntime(881):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-09 23:47:51.570: E/AndroidRuntime(881):  at dalvik.system.NativeStart.main(Native Method)
05-09 23:47:51.570: E/AndroidRuntime(881): Caused by: java.lang.NullPointerException
05-09 23:47:51.570: E/AndroidRuntime(881):  at com.example.besafe.Tips.onCreate(Tips.java:31)
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.app.Activity.performCreate(Activity.java:5133)
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-09 23:47:51.570: E/AndroidRuntime(881):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
05-09 23:47:51.570: E/AndroidRuntime(881):  ... 11 more
谁能帮帮我吗。提前谢谢

提示的OnCreate()方法如下所示

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        t1=(TextView)findViewById(R.id.t1);
        t2=(TextView)findViewById(R.id.t2);
        t3=(TextView)findViewById(R.id.t3);
        t4=(TextView)findViewById(R.id.t4);
        t5=(TextView)findViewById(R.id.t5);
        t6=(TextView)findViewById(R.id.t6);
        t7=(TextView)findViewById(R.id.t7);
        t9=(TextView)findViewById(R.id.t9);
        t10=(TextView)findViewById(R.id.t10);
        t11=(TextView)findViewById(R.id.t11);
        t12=(TextView)findViewById(R.id.t12);
        t13=(TextView)findViewById(R.id.t13);
        t14=(TextView)findViewById(R.id.t14);
        t15=(TextView)findViewById(R.id.t15);
        t8=(TextView)findViewById(R.id.t8);

        aware="Your first line of defence. Most people think of kicks to the groin and blocking punches when they hear the term “self-defence.” However, true self-defence begins long before any actual physical contact. The first, and probably most important, component in self-defence is awareness: awareness of yourself, your surroundings, and your potential attacker’s likely strategies.  ";
        t3.setText(aware);

        sense="“Sixth sense.” “Gut instinct.” Whatever you call it, your intuition is a powerful subconscious insight into situations and people. All of us, especially women, have this gift, but very few of us pay attention to it. Learn to trust this power and use it to your full advantage. Avoid a person or a situation which does not “feel” safe–you’re probably right.  ";
        t5.setText(sense);

        escape="Always your best option. What if the unthinkable happens? You are suddenly confronted by a predator who demands that you go with him–be it in a car, or into an alley, or a building. It would seem prudent to obey, but you must never leave the primary crime scene. You are far more likely to be killed or seriously injured if you go with the predator than if you run away (even if he promises not to hurt you). Run away, yell for help, throw a rock through a store or car window–do whatever you can to attract attention. And if the criminal is after your purse or other material items, throw them one way while you run the other.  ";
        t7.setText(escape);

        fight="Unfortunately, no matter how diligently we practice awareness and avoidance techniques, we may find ourselves in a physical confrontation. Whether or not you have self-defence training, and no matter what your age or physical condition, it is important to understand that you CAN and SHOULD defend yourself physically. You have both the moral and legal right to do so, even if the attacker is only threatening you and hasn’t struck first. Many women worry that they will anger the attacker and get hurt worse if they defend themselves, but statistics clearly show that your odds of survival are far greater if you do fight back. Aim for the eyes first and the groin second. Remember, though, to use the element of surprise to your advantage–strike quickly, and mean business. You may only get one chance.  ";
        t9.setText(fight);

        pepper="Pepper spray, like other self-defence aids, can be a useful tool. However, it is important to understand that there can be significant drawbacks to its use. For example, did you know that it doesn’t work on everyone? Surprisingly, 15-20% of people will not be incapacitated even by a full-face spray. Also, if you’re carrying it in your purse, you will only waste time and alert the attacker to your intentions while you fumble for it. Never depend on any self-defence tool or weapon to stop an attacker. Trust your body and your wits, which you can always depend on in the event of an attack.  ";
        t11.setText(pepper);

        homei="A crime on the rise. The primary way to prevent a home invasion is simply to never, ever open your door unless you either are certain you know who’s on the other side or can verify that they have a legitimate reason for being there (dressing up as a repair person or even police officer is one trick criminals use). In the event that an intruder breaks in while you’re home, you should have a safe room in your house to which you can retreat. Such a room should be equipped with a strong door, deadbolt lock, phone (preferably cell phone), and a can of pepper spray or fire extinguisher.  ";
        t13.setText(homei);

        cyber="Although the Internet is educational and entertaining, it can also be full of danger if one isn’t careful. When communicating on-line, use a nickname and always keep personal information such as home address and phone number confidential. Instruct family members to do the same.  ";
        t15.setText(cyber);
提示的XMl文件如下所示

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#F5D9FF"
    android:layout_height="match_parent"
    android:orientation="vertical" >


<ScrollView 
     android:layout_width="fill_parent"
        android:layout_height="fill_parent"
android:layout_weight="25"
        android:background="#fff"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="486dp"
            android:background="#F5D9FF"
            android:orientation="vertical" >
             <TextView
        android:id="@+id/t1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:textColor="#F70B07"
        android:padding="10dp"
        android:text="Safety Tips"
        android:layout_gravity="center"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:textStyle="bold"
        android:textSize="24dp"
         />
             <TextView
        android:id="@+id/t2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="45dp"
        android:padding="10dp"
        android:textColor="#9D13F7"
        android:text="1. Awareness:"
        android:textSize="20dp"
        />
             <TextView
        android:id="@+id/t3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="70dp"
        android:padding="10dp"
        android:textSize="16dp"
        />
             <TextView
        android:id="@+id/t4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:padding="10dp"
        android:textColor="#9D13F7"
        android:text="2. Use your sixth sense:"
        android:textSize="20dp"
        />
             <TextView
        android:id="@+id/t5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="95dp"
        android:padding="10dp"
        android:textSize="16dp"
        />
             <TextView
        android:id="@+id/t6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="115dp"
        android:padding="10dp"
        android:textColor="#9D13F7"
        android:text="3. Escape:"
        android:textSize="20dp"
        />
             <TextView
        android:id="@+id/t7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="120dp"
        android:padding="10dp"
        android:textSize="16dp"
        />
             <TextView
        android:id="@+id/t8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="150dp"
        android:padding="10dp"
        android:textColor="#9D13F7"
        android:text="4. Your right to fight:"
        android:textSize="20dp"
        />
             <TextView
        android:id="@+id/t9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="145dp"
        android:padding="10dp"
        android:textSize="16dp"
        />
             <TextView
        android:id="@+id/t10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="185dp"
        android:padding="10dp"
        android:textColor="#9D13F7"
        android:text="5. Pepper spray:"
        android:textSize="20dp"
        />
             <TextView
        android:id="@+id/t11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="170dp"
        android:padding="10dp"
        android:textSize="16dp"
        />
             <TextView
        android:id="@+id/t12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="220dp"
        android:padding="10dp"
        android:textColor="#9D13F7"
        android:text="6. Home invasions:"
        android:textSize="20dp"
        />
             <TextView
        android:id="@+id/t13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="195dp"
        android:padding="10dp"
        android:textSize="16dp"
        />
             <TextView
        android:id="@+id/t14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="255dp"
        android:padding="10dp"
        android:textColor="#9D13F7"
        android:text="7. Safety in cyberspace:"
        android:textSize="20dp"
        />
             <TextView
        android:id="@+id/t15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="220dp"
        android:padding="10dp"
        android:textSize="16dp"
        />
             </RelativeLayout>
        </ScrollView>
</RelativeLayout>


您也可以在onCreate()方法中发布代码吗?再看看那条线#31@fmpsagaraonCreate()中的代码如下所示:受保护的void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);cream=(按钮)findViewById(R.id.loud);//final MediaPlayer mp=MediaPlayer.create(this,R.raw.cream);cream.setOnClickListener(this);tips=(Button)findviewbyd(R.id.tips);tips.setOnClickListener(this);emgcy=(Button)findviewbyd(R.id.emgcy);emgcy.setOnClickListener(this);发布“tips”活动的“onCreate()”方法和xml布局(将代码添加到您的问题中,而不是添加到评论部分)@JobishGeorgeat com.example.besafe.Tips.onCreate(Tips.java:31)这一行在Tips.java中有一个NullPointerException您错过了这一行,setContentView(R.layout.activity_Tips);@JobishGeorge