0

Everytime I try to run my application on an emulator, after the splash screen (splash.xml), which leads to my second screen (advert.xml), I get a fatal exception in the LogCat. The app running on the emulator also crashes (unexpectedly). I thought the fatal exception would be the second screen, but instead it says it's my third screen. Here's the log:

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

Main, the fatal exception, is my third screen. I had been messing around with it, but there weren't any problems earlier. Here's the xml main:

<?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"
    />  

I was actually testing out a button I had just created. The button is on the second screen, is supposed to take the user to the third screen when clicked. Here's the java code for the second screen, which includes the button:

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"));

        }
    });

}

}

If someone could help me fix this, I would be eternally grateful.

EDIT: Here's the code for 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>
4
  • 1
    I cannot find any button with id "bSKIP" in that XML. Are you showing us the correct code? Commented Jan 8, 2012 at 23:48
  • Had same thoughts. Make sure R.layout.advert contains requested Button with given id. Commented Jan 8, 2012 at 23:51
  • and thats why there is an NPE, wrong id is being tried to be found Commented Jan 8, 2012 at 23:54
  • Sorry, the xml I had posted was for my third screen (main.xml) since that's where the fatal exception occured. I have edited my question with the xml file for my second screen (advert.xml), please have a look. Commented Jan 9, 2012 at 9:16

1 Answer 1

2

You should replace . with : in your xml here:

android.id="@+id/bSKIP"

and here:

android.id="@+id/bAPPLY"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.