Solved

Error message (cannot resolve symbol)

Posted on 2001-08-04
5
177 Views
Last Modified: 2010-03-31
Hi Folks, I'm having trouble getting my head around the error that I'm experiencing.
I know its only simple but until I can nail it it keeps nagging me.
Some code:-

//Numbers    


public class Numbers
{
     public static void main(String[] args)
     {
          int when, now;     //declare variables
          when=45;
          now=15;
         
          sum=calcSum(when, now);
          diff=calcDiff(when, now);
          prod=clacProd(when, now);
          System.out.println("Total is: " + sum);
          System.out.println("Difference is: " + diff);
          System.out.println("Product is: " + prod);
     }
     public static int calcSum(int w, int n)
     {
          int totSum;     //add the variables
          totSum=(w + n);
          return totSum;
     }
     public static int calcDiff(int w, int n)
     {
          int totDiff;     //get the difference
          totDiff=(w % n);
          return totDiff;
     }
     public static int calcProd(int w, int n)
     {
          int totProd;     //multiply the variables
          totProd=(w * n);
          return totProd;
     }
         
}    

This is some of the errors,

                ^
Numbers.java:14: cannot resolve symbol
symbol  : method clacProd  (int,int)
location: class Numbers
                prod=clacProd(when, now);
                     ^
Numbers.java:15: cannot resolve symbol
symbol  : variable sum
location: class Numbers
                System.out.println("Total is: " + sum);
                                                  ^
As you can see they are similar errrors, so I only need to get this and I'll be able to nail another concept(hopefully).
Regards Ned
0
Comment
Question by:Ned_Kelly
  • 2
  • 2
5 Comments
 

Author Comment

by:Ned_Kelly
ID: 6352732
This piece of code is very similar and it works, the maths might not be perfect but the app works.

//Picture

public class Picture
{
     public static void main(String[] args)
     {
          float height, width;     //declare types
          float cost, glass, met, squ;    
         
          squ=0.56f;     //Square is $56 divided by 1000 number of square cm
          met=28.50f;     //meter is $28.50 per lineal meter
          height=17.9f;
          width=24.6f;
          cost=calcCost(height, width);
          glass=calcGlass(height, width);
          System.out.println("Frame cost is: " + cost);
          System.out.println("Glass cost is: " + glass);
          System.out.println("Total cost for the picture is: " + (cost + glass) / 100 * 10);
     }
     public static float calcCost(float h, float w)
     {
          float totCost;
          totCost=(h * 2 + w * 2) * 28.50f;
          return totCost;
     }
     public static float calcGlass(float h, float w)
     {
          float totGlass;
          totGlass=(h * w) * 0.56f;
          return totGlass;
     }
}

Regards Ned
0
 
LVL 9

Expert Comment

by:yongsing
ID: 6352741
Here are your problems:

>> Numbers.java:14: cannot resolve symbol
>> symbol  : method clacProd  (int,int)
>> location: class Numbers
>>                prod=clacProd(when, now);
                    ^
The function name is "calcProd", not "clacProd"!

>> Numbers.java:15: cannot resolve symbol
>> symbol  : variable sum
>> location: class Numbers
>>                System.out.println("Total is: " + sum);
                                                 ^
The variables sum, diff, and prod are not defined. You should rewrite the statements as:

int sum=calcSum(when, now);
int diff=calcDiff(when, now);
int prod=clacProd(when, now);
0
 
LVL 9

Accepted Solution

by:
yongsing earned 50 total points
ID: 6352745
The last statement should be:

int prod = calcProd(when, now);

Also, you have a mistake in your calcDiff() method:

totDiff=(w % n);

You should change the % to a - sign.
0
 

Author Comment

by:Ned_Kelly
ID: 6353108
Thats great, thankyou yongsing, you were right in both instances.  The % sign was put there thinking that it was the difference that I wanted, not to worry.
I'm still not sure why the other app works though, is it because of the f behind the numbers in the code below.

  squ=0.56f;    
                                                             met=28.50f;    
                                                             height=17.9f;
                                                             width=24.6f;
                                                             cost=calcCost(height, width);
                                                             glass=calcGlass(height, width);

Or is it because its a different type.
Thanks again for a great answer.
Regards Ned
0
 
LVL 2

Expert Comment

by:vasan_sr
ID: 6353906
Hello sir,
   U have to declare the variable, and then use the variable.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now