File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what might be the error

 
thirumala raju
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi folks,

package pack1;

class clas2{
String s1;
String s2;
void met(String d1, String d2)
{
System.out.println("ADASD");

}
}
public class rajaone
{
public static void main(String[] args)
{
//String s1,s2;
clas2 ref1 = new clas2();
ref1.s2; //error showing here
}
}


i am getting this error for the above code the error is :
---
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "AssignmentOperator ArrayInitializer" to complete Expression

at pack1.rajaone.main(rajaone.java:18)
thanks
raja
 
Nicolas Stern
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

the line

references the member variable s2 of your instance ref1. Expected is a valid expression or a statement (e.g. an assignment, a method invokation)

examples:


hth - cheers
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thirumala Raju,

please try to make use of CodeTags so that the java code will look nicely.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by thirumala raju:
...hi folks,





What are you trying to achieve in the line in bold? You just used a variable using its reference. But it should be involved in an operation which may be of an assignment, arithmetic etc., The example shown by Nicolas is one kind.

You can call a method like this and leave its return type unassigned to any variable. But it is NOT the case with variables.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic