• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to access non-static variables across classes

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a midlet class (called ClassesTestMIDlet) and two other classes (Calcs and MoreCalcs).

I would like to know if it possible for the methods in Calcs and MoreCalcs to access variables from the ClassesTestMIDlet class without having to declare the ClassesTestMIDlet variables static, and without having to pass the current instance of ClassesTestMIDlet when constructing the other classes.

Here is the code....



.... which gives the following compile error:
ClassesTest/MoreCalcs.java [14:26] non-static variable testInt cannot be referenced from a static context
ClassesTestMIDlet.testInt = p;
1 error
Errors compiling MoreCalcs.



So was just wondering if anyone knows whether it's possible?


Thanks,
James
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic