ANDROID:致命异常:XML文件

时间:2012-01-08 23:37:58

标签: android fatal-error

每当我尝试在模拟器上运行我的应用程序时,在启动我的第二个屏幕(ads.xml)的启动画面(splash.xml)之后,我在LogCat中遇到致命异常。在模拟器上运行的应用程序也会崩溃(意外)。我认为致命的例外是第二个屏幕,但它说它是我的第三个屏幕。这是日志:

01-08 23:03:35.093: D/AndroidRuntime(287): Shutting down VM
01-08 23:03:35.093: W/dalvikvm(287): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-08 23:03:35.163: E/AndroidRuntime(287): FATAL EXCEPTION: main
01-08 23:03:35.163: E/AndroidRuntime(287): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.revagar.android.niles/com.revagar.android.niles.Advert}: java.lang.NullPointerException
01-08 23:03:35.163: E/AndroidRuntime(287):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-08 23:03:35.163: E/AndroidRuntime(287):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-08 23:03:35.163: E/AndroidRuntime(287):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-08 23:03:35.163: E/AndroidRuntime(287):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-08 23:03:35.163: E/AndroidRuntime(287):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 23:03:35.163: E/AndroidRuntime(287):  at android.os.Looper.loop(Looper.java:123)
01-08 23:03:35.163: E/AndroidRuntime(287):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-08 23:03:35.163: E/AndroidRuntime(287):  at java.lang.reflect.Method.invokeNative(Native Method)
01-08 23:03:35.163: E/AndroidRuntime(287):  at java.lang.reflect.Method.invoke(Method.java:521)
01-08 23:03:35.163: E/AndroidRuntime(287):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-08 23:03:35.163: E/AndroidRuntime(287):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-08 23:03:35.163: E/AndroidRuntime(287):  at dalvik.system.NativeStart.main(Native Method)
01-08 23:03:35.163: E/AndroidRuntime(287): Caused by: java.lang.NullPointerException
01-08 23:03:35.163: E/AndroidRuntime(287):  at com.revagar.android.niles.Advert.onCreate(Advert.java:18)
01-08 23:03:35.163: E/AndroidRuntime(287):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-08 23:03:35.163: E/AndroidRuntime(287):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-08 23:03:35.163: E/AndroidRuntime(287):  ... 11 more
01-08 23:03:38.663: I/Process(287): Sending signal. PID: 287 SIG: 9

主要的,致命的例外,是我的第三个屏幕。我一直在搞乱它,但之前没有任何问题。这是xml主要的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/appbg">


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Welcome to the Club Finder"
    android:textSize="28dp" 
    android:layout_gravity="center"
    android:textColor="#bc0d0d"
    android.id="@+id/tvDisplay"
    android:textStyle="bold"
    android:layout_marginTop="20dp"
    android:gravity="center"
    />

<Button 
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Search by Club Name"
    android:textSize="18dp" 
    android.id="@+id/bSbN"
    android:background="@drawable/button1"
    android:textColor="#bc0d0d" 
    android:layout_marginTop="70dp"
    />  

<Button 
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Search by Location"
    android:textSize="18dp" 
    android.id="@+id/bSbL"
    android:background="@drawable/button1"
    android:textColor="#bc0d0d"
    android:layout_marginTop="60dp"
    />  

我实际上正在测试我刚创建的按钮。按钮位于第二个屏幕上,单击时应该将用户带到第三个屏幕。这是第二个屏幕的java代码,其中包括按钮:

package com.lol.android.cop;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Advert extends Activity{

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

    Button bSkipty = (Button) findViewById(R.id.bSKIP);
    bSkipty.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent ("com.lol.android.cop.MAINACTIVITY"));

        }
    });

}

}

如果有人能帮助我解决这个问题,我将永远感激不尽。

编辑:这是advert.xml的代码:

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


<Button
    android:layout_width="68dp"
    android:layout_height="38dp"
    android:layout_gravity="right"
    android:text="Skip"
    android.id="@+id/bSKIP"
    android:background="@drawable/button1"
    android:textColor="#FFFFFF"
    android:layout_marginTop="2dp"
   />


<Button
    android:layout_width="68dp"
    android:layout_height="38dp"
    android:layout_gravity="right"
    android:text="Apply"
    android.id="@+id/bAPPLY"
    android:background="@drawable/button1"
    android:textColor="#FFFFFF"
    android:layout_marginTop="4dp"
    />

</LinearLayout>

1 个答案:

答案 0 :(得分:2)

您应该在xml中将.替换为:

android.id="@+id/bSKIP"

在这里:

android.id="@+id/bAPPLY"