Newb--Q: How to get VARIABLE from ACTIVITY

Put your problem here if it does not fit any of the other categories.

Newb--Q: How to get VARIABLE from ACTIVITY

Postby doubleslash » Sun Mar 01, 2009 7:05 am

Hi,
Can you tell me how to access a private variable (count in the following example) defined in Activity?
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Myapp extends Activity{
  2.  
  3. private int count;
  4.  
  5. public int get(){
  6.  
  7. return count;
  8.  
  9. }
  10.  
  11. }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
In another file, I tried to access count as follows, but it failed.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyView extends View{
  2.  
  3. //inside some method like onDraw
  4.  
  5. int num = new Myapp().get();
  6.  
  7. }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Any suggestions?
doubleslash
Developer
Developer
 
Posts: 30
Joined: Fri Feb 13, 2009 6:05 am

Top

Postby doubleslash » Sun Mar 01, 2009 6:28 pm

I found that making the variable static solved the problem.
doubleslash
Developer
Developer
 
Posts: 30
Joined: Fri Feb 13, 2009 6:05 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 20 guests