• Post Reply Bookmark Topic Watch Topic
  • New Topic

need help with "=" error  RSS feed

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the error "Syntax error on token "=", "Identifier" expected", on this code:
LimitedTextContainer GrpAcctNumber;
GrpAcctNumber = new LimitedTextContainer ("1234567890");
What could be causing this error? I have checked everything that I can think of that would cause it.
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such class in the java API doc, so I am guessing it is a user-defined class. I suggest you post a little more code, in order for us to help, because the code seems a little bit ambiguous.
 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
try this

if you define the reference inside a method, then you need to assign a value to the reference GrpAcctNumber even if its null.
cheers
k
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you define the reference inside a method, then you need to assign a value to the reference GrpAcctNumber even if its null.
Thats true. But I dont think in this case it will matter just yet as the object is being initialized before its being accessed (atleast from this snippet of code thats how it seems.) IMHO, locally declared references will give an error if they are accessed to check for null, equality, etc before they are initialized or an object is assigned to them. Unless I am missing something here.
 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried setting GrpAcctNumber = null first but that didn't change the error at all. There is a whole lot of code so I don't exactly know how much you need to see so here is some more of it:
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Candy,
Do you still get same compiler error if you shorten the code to one line?
LimitedTextContainer GrpAcctNumber = new LimitedTextContainer("1234567890");

Does the compiler error disappear when you comment out the second line (this will probably result in a NullPointerException during run-time, but the point is to get past the compiler error first)?
LimitedTextContainer GrpAcctNumber = null;
//GrpAcctNumber = new LimitedTextContainer ("1234567890");
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not allowed to do any Java logic outside of a method except in certain, constrained situations. The error message you are getting happens because you are trying to define and then initialize an instance variable in two separate steps.

Unfortunately you are trying to do number 3. To fix your problem you can do:
LimitedTextContainer GrpAcctNumber = new LimitedTextContainer("1234567890");
which is what David suggested. Or you could move the line "GrpAcctNumber = new LimitedTextContainer("1234567890");" inside of the constructor and that would work. However since you can't call any methods on a "null" variable, you'd also have to move the line "GrpAcctNumber.addLimtedTextListener(this);" inside of the constructor. You may have to do that anyway (since you can't do that outside of a method unless you put it inside of an instance initializer).
Also, I think you want "addLimitedTextListener(...)" (you're missing an "i").
[ March 09, 2004: Message edited by: Wayne L Johnson ]
 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much. I moved
GrpAcctNumber = new LimitedTextContainer ("1234567890");
GrpAcctNumber.addLimitedTextListener(this);
inside the constructor and now it works good.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!