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

  • Home
  • SEARCH
  • 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 6983269
In Process

The Archive Base Latest Questions

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

when testing my application in the emulator(I’m using Eclipse) it shows me The application

  • 0

when testing my application in the emulator(I’m using Eclipse) it shows me “The application Counter(com.ian.counter) has stopped unexpectedly. Please try again.” when running it. I’ve searched and searched for an answer but I’ve found none. Anyone know the problem?

Code:

package com.ian.counter;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
import android.widget.Toast;

public class CounterActivity extends Activity {
    /** Called when the activity is first created. */
    TextView textView1 = (TextView) this.findViewById(R.id.textView1);
    int count = 0;
    @Override  
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void Count(){
        count ++;
        textView1.setText(Integer.toString(count));
    }
}

Logcat:

12-28 16:59:20.615: D/AndroidRuntime(353): Shutting down VM
12-28 16:59:20.686: W/dalvikvm(353): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-28 16:59:20.756: E/AndroidRuntime(353): FATAL EXCEPTION: main
12-28 16:59:20.756: E/AndroidRuntime(353): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ian.counter/com.ian.counter.CounterActivity}: java.lang.NullPointerException
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.os.Looper.loop(Looper.java:123)
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-28 16:59:20.756: E/AndroidRuntime(353):  at java.lang.reflect.Method.invokeNative(Native Method)
12-28 16:59:20.756: E/AndroidRuntime(353):  at java.lang.reflect.Method.invoke(Method.java:507)
12-28 16:59:20.756: E/AndroidRuntime(353):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-28 16:59:20.756: E/AndroidRuntime(353):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-28 16:59:20.756: E/AndroidRuntime(353):  at dalvik.system.NativeStart.main(Native Method)
12-28 16:59:20.756: E/AndroidRuntime(353): Caused by: java.lang.NullPointerException
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.app.Activity.findViewById(Activity.java:1647)
12-28 16:59:20.756: E/AndroidRuntime(353):  at com.ian.counter.CounterActivity.<init>(CounterActivity.java:10)
12-28 16:59:20.756: E/AndroidRuntime(353):  at java.lang.Class.newInstanceImpl(Native Method)
12-28 16:59:20.756: E/AndroidRuntime(353):  at java.lang.Class.newInstance(Class.java:1409)
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-28 16:59:20.756: E/AndroidRuntime(353):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)

Any help is appreciated.

  • 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:23:50+00:00Added an answer on May 27, 2026 at 6:23 pm

    You’re trying to set the textView1 variable before the layout has been set. You need to define it as a variable and then assign it in onCreate() after you’ve called setContentView(). Like this:

    package com.ian.counter;
    
    import android.app.Activity;
    import android.widget.TextView;
    import android.os.Bundle;
    import android.widget.Toast;
    
    public class CounterActivity extends Activity {
        /** Called when the activity is first created. */
        TextView textView1;
        int count = 0;
        @Override  
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            textView1 = (TextView) this.findViewById(R.id.textView1);
        }
    
        public void Count(){
            count ++;
            textView1.setText(Integer.toString(count));
        }
    }
    

    Just copy and paste the above, that’ll work just fine.

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

Sidebar

Related Questions

friends, while testing application on eclipse using emulator google map is being displayed properly.
Currently I'm using TestNG framework for testing application business logic, i added some Servlet
I've been testing an application using my machine as a server, and everything's going
I'm using WatiN for web application testing. There is a field called enter choices
I'm building a hybrid mobile application (PhoneGap+JQM). While testing in the Android emulator, I'm
I'm using the MSTest system for unit testing my compact framework (3.5) application and
I have create testing application that has 3 classes Car Radio SportCar : Car
In my application (https://market.android.com/details?id=com.cabot.beastly&feature=search_result), I am using facebook-android api to login and share to
I am developing an android application(using Eclipse 3.5.2, Android 2.2) where i need to
I am testing my application in Android Emulator and I am only able to

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.