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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:21:01+00:00 2026-05-28T08:21:01+00:00

I am trying to call a static method from another activity to find a

  • 0

I am trying to call a static method from another activity to find a integer for a score:

public class HighscoreActivity extends Activity {

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

        TextView txtGuess = (TextView) findViewById(R.id.txtScore);
        int temp = MastermindGameActivity.getScore();
        String score = Integer.toString(temp);
        txtGuess.setText(score);

    }
}

by calling this method:

public static int getScore()
{
    return score;
}

Why will this not work? I keep getting

01-14 21:28:54.347: ERROR/AndroidRuntime(1485): FATAL EXCEPTION: main
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): java.lang.RuntimeException: Unable to start activity ComponentInfo{sam.android.mastermind/sam.android.mastermind.HighscoreActivity}: java.lang.NullPointerException
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at android.os.Looper.loop(Looper.java:123)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at java.lang.reflect.Method.invoke(Method.java:507)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at dalvik.system.NativeStart.main(Native Method)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): Caused by: java.lang.NullPointerException
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at sam.android.mastermind.HighscoreActivity.blah(HighscoreActivity.java:27)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at sam.android.mastermind.HighscoreActivity.onCreate(HighscoreActivity.java:13)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-14 21:28:54.347: ERROR/AndroidRuntime(1485):
… 11 more

The activity is defined in manifest.

  • 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-28T08:21:01+00:00Added an answer on May 28, 2026 at 8:21 am

    Try this..

    MastermindGameActivity masterActivity = new MastermindGameActivity();
    
    masterActivity.getScore();
    

    Also you can try passing it as a intent as i would recommend.

     Intent intent=new Intent(this,Activity2.class);
     intent.putIntExtra("Score" score);
    

    And pull it out in the receiving activity

     Intent sender=getIntent();
         int score = sender.getExtras().getInt("Score");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to call on a method from another class my method as a
I am trying to call the following function from a static method. File directory
I am currently trying to call a method from a utility class that will
I'm trying to use a method from within another method in a class. I
I am trying to call a static function from a class but the intellisense
I am trying to use a method inside class, from another class. namespace Crystal.Utilities
I trying to call some ejb bean method from tread. and getting error :
I'm new for Jquery. I'm trying to call server method from my user control
I'm trying to get a simple Java method call from C++ while Java calls
I'm trying to call a web service from Excel 2003 module. The way 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.