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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:08:21+00:00 2026-06-06T11:08:21+00:00

So I have a main class and another class that has a variable I

  • 0

So I have a main class and another class that has a variable I need to pull out into the main class. I have tried some of the ways posted on the answered questions like this, but I’m still failing to get it right.

public class Example extends MapActivity
{
    public void OnCreate(Bundle savedInstanceState){
        final Button bttn = (Button)findViewById(R.id.button1);
        bttn.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Toast tulos = Toast.makeText(getBaseContext(),
                                               "Area is: "
                                                +MyItemizedOverlay.alue +"" 
                     /*I get the non static variable error here
                       which I get as it is not yet defined, it will be after the user 
                       inputs values into the program*/
                                               ,Toast.LENGTH_LONG);
                tulos.show();
            }
     });

public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
    int alue;
        //irreleveant stuff (I assume)
    public void Calc(Geopoint gp, Mapview map){
        //there's some stuff before the variable I want to get like other variables
        //not relevant for my problem I hope

        alue = (int)Math.round(*formula: derived from user input data*)
    }
}

So how can I get a value out of my other class, as it doesn’t seem to be able to get it now? Or is this maybe an indication of a bigger problem?

  • 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-06T11:08:24+00:00Added an answer on June 6, 2026 at 11:08 am

    There are two way

    1 – make alue static but that will show the error that satic variable can't be accesses in non static function Calc so either make function Calcalso static as well or go to point 2

    2-try this new MyItemizedOverlay().alue with making alue public as below

      public class Example extends MapActivity
        {
        public void OnCreate(Bundle savedInstanceState){
            final Button bttn = (Button)findViewById(R.id.button1);
        bttn.setOnClickListener(new View.OnClickListener() {
               public void onClick(View v) {
              Toast tulos = Toast.makeText(getBaseContext(),
                      "Area is: "
                      +new MyItemizedOverlay().alue +"" /<--------------------
        /*I get the non static variable error here
         which I get as it is not yet defined, it will be after the user has input 
        values into the program*/
                      ,Toast.LENGTH_LONG);
               tulos.show();
                 }
             });
    
        public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
        public int alue; /<--------------------
            //irreleveant stuff (I assume)
        public void Calc(Geopoint gp, Mapview map){
            //there's some stuff before the variable I want to get like other variables
            //not relevant for my problem I hope
        alue = (int)Math.round(*formula: derived from user input data*)
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main class in a program that launches another class that handles
I have the next scenario: I define an int[][] variable in my main class.
I have a custom UIImageView class that creates thumbnails (UIImageView) and each thumbnail has
In my iPhone app I have a UIViewController that has a UITableView and another
I have 2 class files. One has the get/set statements and I need to
I have another PHP question for you. I have a class that is supposed
I have a class that has no default constructor or assignment operator so it
I have some code in a reusable class that modifies some types. Here's a
I have a main class(which is basically a netbeans form;drag and drop) from where
I have a Main class and a HelloWorld class. I have created a button

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.