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 8179009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:54:25+00:00 2026-06-06T23:54:25+00:00

I get the following error message when running my basic application. The application consists

  • 0

I get the following error message when running my basic application.
The application consists of a button called button1 and a textView called topLeft.

07-01 15:33:02.754: D/AndroidRuntime(2334): Shutting down VM 07-01 15:33:02.754: W/dalvikvm(2334): threadid=1: thread exiting with
uncaught exception (group=0x40a13300) 07-01 15:33:02.984:
E/AndroidRuntime(2334): FATAL EXCEPTION: main 07-01 15:33:02.984:
E/AndroidRuntime(2334): java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}:
java.lang.NullPointerException 07-01 15:33:02.984:
E/AndroidRuntime(2334): at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
07-01 15:33:02.984: E/AndroidRuntime(2334): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-01 15:33:02.984: E/AndroidRuntime(2334): at android.app.ActivityThread.access$600(ActivityThread.java:130) 07-01
15:33:02.984: E/AndroidRuntime(2334): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-01 15:33:02.984: E/AndroidRuntime(2334): at android.os.Handler.dispatchMessage(Handler.java:99) 07-01
15:33:02.984: E/AndroidRuntime(2334): at android.os.Looper.loop(Looper.java:137) 07-01 15:33:02.984:
E/AndroidRuntime(2334): at android.app.ActivityThread.main(ActivityThread.java:4745) 07-01
15:33:02.984: E/AndroidRuntime(2334): at java.lang.reflect.Method.invokeNative(Native Method) 07-01
15:33:02.984: E/AndroidRuntime(2334): at java.lang.reflect.Method.invoke(Method.java:511) 07-01 15:33:02.984:
E/AndroidRuntime(2334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-01 15:33:02.984: E/AndroidRuntime(2334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 07-01
15:33:02.984: E/AndroidRuntime(2334): at dalvik.system.NativeStart.main(Native Method) 07-01 15:33:02.984:
E/AndroidRuntime(2334): Caused by: java.lang.NullPointerException
07-01 15:33:02.984: E/AndroidRuntime(2334): at android.app.Activity.findViewById(Activity.java:1825) 07-01
15:33:02.984: E/AndroidRuntime(2334): at com.example.myfirstapp.MainActivity.<init>(MainActivity.java:28) 07-01
15:33:02.984: E/AndroidRuntime(2334): at java.lang.Class.newInstanceImpl(Native Method) 07-01 15:33:02.984:
E/AndroidRuntime(2334): at java.lang.Class.newInstance(Class.java:1319) 07-01 15:33:02.984:
E/AndroidRuntime(2334): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
07-01 15:33:02.984: E/AndroidRuntime(2334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
07-01 15:33:02.984: E/AndroidRuntime(2334):     ... 11 more

When attempting to use the findViewById, this error comes up referring to line 28.

The program looks like the following:

package com.example.myfirstapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener{

    int a = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
    }


    Button button1 = (Button) findViewById(R.id.button1);
    TextView topLeft = (TextView) findViewById(R.id.textView2);
//  button1.setOnClickListener( this );

    public void onClick(View v) {
        // TODO Auto-generated method stub

    }    

}

What does this mean? Why is my code having trouble doing something along the lines of referring to the R.java file?

R.java does have
    public static final class id {
        public static final int button1=0x7f080001;
        public static final int menu_settings=0x7f080003;
        public static final int textView1=0x7f080000;
        public static final int textView2=0x7f080002;

Thanks in advance.

  • 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-06-06T23:54:27+00:00Added an answer on June 6, 2026 at 11:54 pm

    You’re calling findViewById as part of your field definition, at which point the layout isn’t inflated (that happens when you call setContentView). findViewById isn’t finding the view, so the reference is being set to null.

    Moving your findViewById calls inside of onCreate, after calling setContentView should fix it.

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

Sidebar

Related Questions

We get the following error when running at test: ContextSwitchDeadlock was detected Message: The
I am using GWT2.0.1,when I am running web application then I get following error
while running my application I get the following error: javax.el.ELException: /view/doi/common/navigation.xhtml: Can't find bundle
I am running a Python code and I get the following error message: Exception
When running some commands in the terminal, I get the following error message dyld:
I get the following error message when trying to connect a web app running
I get following error message, when I try to run git rebase -i for
I get the following error message when I try the following: Dim XL As
when I start GDB, I get the following error message in debugger: input:--- token
Upon launching a sinatra app, I get the following error message: /home/matt/.rvm/gems/ruby-1.9.3-p125/gems/backports-2.5.1/lib/backports/tools.rb:310:in `require': cannot

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.