Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6984323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:32:05+00:00 2026-05-27T18:32:05+00:00

I am having a similar problem as the person here: Android activity error I’ve

  • 0

I am having a similar problem as the person here: Android activity error I’ve read through the post. I also read through other posts. But I can’t seem to get my Android application running.

Description: I have one button. I want this button to work. I keep getting an NPE because of an OnClickListener. This is virtually an identical problem as the above post, but mine is behaving a little differently. Please help me. Thank you very much.

Main.java

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


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

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

            public void onClick(View v) {
            startActivity(new Intent(Main.this, Second.class));
            }
        });
    }
}

Second.java

import android.app.Activity;
import android.os.Bundle;

public class Second extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    }
}    

Error Message

12-27 09:19:10.729: W/dalvikvm(923): threadid=1: thread exiting with uncaught exception (group=0x409951f8)
12-27 09:19:10.749: E/AndroidRuntime(923): FATAL EXCEPTION: main
12-27 09:19:10.749: E/AndroidRuntime(923): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.harryoh.firstapp/com.harryoh.firstapp.Main}: java.lang.NullPointerException
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.os.Looper.loop(Looper.java:137)
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.app.ActivityThread.main(ActivityThread.java:4340)
12-27 09:19:10.749: E/AndroidRuntime(923):  at java.lang.reflect.Method.invokeNative(Native Method)
12-27 09:19:10.749: E/AndroidRuntime(923):  at java.lang.reflect.Method.invoke(Method.java:511)
12-27 09:19:10.749: E/AndroidRuntime(923):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-27 09:19:10.749: E/AndroidRuntime(923):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-27 09:19:10.749: E/AndroidRuntime(923):  at dalvik.system.NativeStart.main(Native Method)
12-27 09:19:10.749: E/AndroidRuntime(923): Caused by: java.lang.NullPointerException
12-27 09:19:10.749: E/AndroidRuntime(923):  at com.harryoh.firstapp.Main.onCreate(Main.java:19)
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.app.Activity.performCreate(Activity.java:4465)
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-27 09:19:10.749: E/AndroidRuntime(923):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-27 09:19:10.749: E/AndroidRuntime(923):  ... 11 more

I really appreciate your help. I really want to learn Android, and these trouble shooting problems have always caused a lot of pain.

EDIT: Thanks for your help. I will return the favor to this community once I am able… I haven’t gone through your inputs yet, since I wanted to provide this as requested. I will work on it now. I hope it works.

main.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" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:32:06+00:00Added an answer on May 27, 2026 at 6:32 pm

    This has happened to me numerous times while messing with layouts. If you just recently added the button try refreshing the project and clean rebuilding and then see if it picks up the button. For some reason if you add widgets and try to test them immediately after it doesn’t actually update.

    EDIT: After seeing your main.xml it looks like you dont even have a button set up. This would cause the null pointer exception because its looking for something that doesn’t exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem similar to this person's: connect ECONNREFUSED - node js ,
I have seen this post here (http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state). I am having a similar problem I
I think I might be having a stack overflow problem or something similar in
I am having a similar issue to this person . The primary difference being
I am having a similar problem as Ant produces jsfl with backslashes instead of
I seem to have exactly the same problem as this person: http://forums.adobe.com/thread/618752 He also
It works like this, so if someone having a similar problem, you can just
I'm having a problem similar to [this question][1] https://stackoverflow.com/questions/1449072/debugging-problem-in-x-code-iphone-development I have created an application,
I'm having a problem similar to jQuery $.ajax Not Working in IE8 but it
I'm having a problem similar to but not quite the same as one I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.