By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

Using a variable from another class.

P: 66
EDIT: my title should have said "Define enum data type in one class and use in another" sorry


i know, create a getter method but what i need to do is like in C, how we use headers to define data types and include that header, i want to define an enum in a java class only once and use it everywhere in my package. here is my example :

Expand|Select|Wrap|Line Numbers
  1. public class WlanLayer {
  2.  
  3.     /** Enum of status flags
  4.      */    
  5.     public enum Status {
  6.         SUCCESS(1), UNSPECIFIED_ERROR(2);
  7.  
  8.         private int value;
  9.         private Status(int value) {
  10.                 this.value = value;
  11.         }
  12.     };  
  13. }
  14.  
  15.  
  16. import WlanLayer.Status;
  17. public class Node {
  18.  
  19.     public Status method()
  20.     {
  21.       // here, i want to set the status flag, to 
  22.       // an enum value, init to success
  23.       Status s = Status.SUCCESS;
  24.  
  25.  
  26.       // oh no, some error just happened after statements
  27.       s = Status.UNSPECIFIED_ERROR;    
  28.     }
  29.  
  30. }
  31.  
  32.  
  33.  
  34.  

in eclipse, it gives me an error even at the import statement (everything's in teh same package) : import WlanLayer cannot be resolved

can someone please help me with the correct syntax ? thanks!
Apr 9 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.