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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:11:24+00:00 2026-05-27T03:11:24+00:00

Im trying to create a simple high/low app but the application crashes when I

  • 0

Im trying to create a simple high/low app but the application crashes when I try to get a random number.
Here is some code:

final TextView counter = (TextView) findViewById(R.id.tcounter);
Button high = (Button) findViewById(R.id.bhigh);
Button low = (Button) findViewById(R.id.blow);
Button start = (Button) findViewById(R.id.bplay);
final Random rstart = new Random();
final int counternr = rstart.nextInt(5) + 1;

start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            counter.setText(counternr);

That is supposed to set the TextView “counter” to a random number from 1-6, but gives me a crash.

Thanks in advance!

EDIT: Here is the error text:

11-23 20:17:40.509: ERROR/AndroidRuntime(765): FATAL EXCEPTION: main
11-23 20:17:40.509: ERROR/AndroidRuntime(765): java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx.xxx.xxx/xxx.xxx.xxx.play}: java.lang.NullPointerException
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at android.os.Looper.loop(Looper.java:123)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at android.app.ActivityThread.main(ActivityThread.java:3683)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at java.lang.reflect.Method.invokeNative(Native Method)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at java.lang.reflect.Method.invoke(Method.java:507)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at dalvik.system.NativeStart.main(Native Method)
11-23 20:17:40.509: ERROR/AndroidRuntime(765): Caused by: java.lang.NullPointerException
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at xxx.xxx.xxx.play.onCreate(play.java:26)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-23 20:17:40.509: ERROR/AndroidRuntime(765):     ... 11 more

Very messy, but I hope it is OK.

  • 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-27T03:11:25+00:00Added an answer on May 27, 2026 at 3:11 am

    Change this

    counter.setText(counternr);
    

    with this

    counter.setText(Integer.toString(counternr));
    

    The method setText accepts only a CharSequence object as argument (in this case, a String), or an int if it represents a resource ID

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

Sidebar

Related Questions

Im trying to create a simple pan and zoom app using silverlight 4, but
I'm trying to create a simple loop that adds a random number of stars,
I'm trying to create simple Ajax call, but after clicking the link I get
I'm trying to create a simple BaSH-like grammar on ANTLRv3 but haven't been able
I`m trying to create simple QML application. I have QtSDK installed with latest QtCreator.
Iam trying to create simple menu according to the book CCMenuItem . here is
I was trying to create simple program that would perform some trivial operation with
I'm trying to create simple application with Xuggler, which has to encode sequence of
I'm trying create a simple audio stream server like a concept proof, but I'm
Hi I am trying to create a simple column chart with high charts. The

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.