0

I am trying to access some of the onCreate class variables from another class that is under activity class, for example

..Acivity class(..)
        Class onCreate(..){
              Final int intItemNo = 0;

        } 

        Class testing(){
             //some commands here, will need access to the intItemNo above.
        } 
 };
3
  • Final int intItemNo = 0; this is local variable in `onCreate() method, not class variable. Commented Oct 11, 2011 at 0:37
  • So how can I declear it in a way that it can be accessed in the other class class testing() Commented Oct 11, 2011 at 0:42
  • your stuffs above just don't make any sense to me, are you trying to say onCreate() and testing() are classes? Commented Oct 11, 2011 at 0:49

1 Answer 1

1

Place the variable definition outside of the onCreate Class. I am assuming this code is from an activity class so onCreate is really a method not a class. It does not change the answer though. If it is not, onCreate is not a good name for class as it conflicts with an android method.

public class1 extends Activity {

    Final int intItemNo;

    public void  onCreate(..){
         intItemNo = 0;
    } 

    Class testing(){
         intItemNo = 1;
    } 
}
Sign up to request clarification or add additional context in comments.

1 Comment

I am not confused between classes and methods. I know the difference. the issue I have is I was trying to get some vars that are located inside onCreate to be used on testing class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.