aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can resolve symbol ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can resolve symbol ???" Watch "can resolve symbol ???" New topic
Author

can resolve symbol ???

Mateen Nasir
Ranch Hand

Joined: Aug 01, 2001
Posts: 33
i have compiled the following code and receive the error given below

class ATest {
static int i = 2 ;
static int [] b = new int[i] ;
i = 2039;
public static void main( String[] args ) {
System.out.println ( " testing" ) ;
// 2
}
}

MESSSAGE FROM COMPILER

ATest.java:4: <identifier> expected
i = 2039;
^
ATest.java:4: cannot resolve symbol
symbol : class i
location: class ATest
i = 2039;
^
2 errors

I FAIL to understand why the compiler cannot resolve the variablr that i have jsut defined above using the variable inside the method i.e. coping thesame statement that gives the error to location 2 inside main does not give any error
I cannot understand why??
can anyone help
Rehan Malik
Ranch Hand

Joined: Jul 09, 2001
Posts: 76
I believe this is because you cannot assign another value to the variable OUTSIDE of a method.
It works within the method but not outside.


Rehan Malik
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Mateen
After a variable is declared the only place you can assign a new value is within a block of code.
Within a static initializer block (for static variables), an instance initializer block (for instance variables) or in a constructor of method.
like this:

hope that helps
Dave
SCJP


Dave
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: can resolve symbol ???