The Artima Developer Community
Sponsored Link

Java Answers Forum
cannot resolve symbol: variable

5 replies on 1 page. Most recent reply: Dec 2, 2002 12:46 AM by Singh M.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
rachael

Posts: 3
Nickname: rachy
Registered: Nov, 2002

cannot resolve symbol: variable Posted: Nov 27, 2002 11:58 AM
Reply to this message Reply
Advertisement
hi i think the answer to this will probably be quite simple as im new to java and have probably missed something quite basic.
i want to write a program that takes data from a txt file and calculates the mean and sd. the txt file has two columns of data, one column is vibration and one is viscosity. i keep getting the error message cannot resolve symbol for variable k. i thought i had said what k is.
any help would be greatly appreciated.
rachael

import java.io.*;
import java.util.*;

public class coursework{

static final int x = 150;

public static void main ( String args [] ) {

BufferedReader din;
FileReader fin;

File f = new File ("normal.txt");
String[] records = new String[x];

try {
fin = new FileReader (f);
din = new BufferedReader (fin);
for (int k=0; k<x; k++){
records[k] = din.readLine();
}
}
catch (Exception e){
System.exit(0);
}
double[] vibration = new double[x];
double[] viscosity = new double[x];

for (int k=0; k<x; k++){
StringTokenizer st = new StringTokenizer(records[k], " ");

String s1 = st.nextToken() ;
String s2 = st.nextToken() ;

double d1 = Double.parseDouble (s1);
double d2 = Double.parseDouble (s2);
System.out.println("\t" +d1 +" " + d2);
vibration [k] = d1;
viscosity [k] = d2;

}


System.out.println ("\n\t Number of arguments: " + vibration.length ); // has no errors up to here!



float sumVibration =0.0f;
float sumViscosity =0.0f;
double mean1 = 0.0, mean2 = 0.0;

for ( k=0; k<x; k++){
sumVibration += Double.parseFloat ( args [k] ) ;
}
sumVibration / (int) x = mean1;
System.out.println ("\n\t The mean of the vibration values is: "+ mean1 );

for ( k=0; k<x; k++){
sumViscosity += Float.parseFloat ( args [k] );
}
sumViscosity /x = mean2;
System.out.println ("\n\t The mean of the viscosity values is: "+ mean2 );
}
}


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: cannot resolve symbol: variable Posted: Nov 27, 2002 8:19 PM
Reply to this message Reply
for ( k=0; k<x; k++){
sumVibration += Double.parseFloat ( args [k] ) ;
}
sumVibration / (int) x = mean1;
System.out.println ("\n\t The mean of the vibration values is: "+ mean1 );

for ( k=0; k<x; k++){
sumViscosity += Float.parseFloat ( args [k] );
}


in the above for loops, k is not defined.

just start with int k = 0; k<x...

rachael

Posts: 3
Nickname: rachy
Registered: Nov, 2002

Re: cannot resolve symbol: variable Posted: Nov 30, 2002 7:46 AM
Reply to this message Reply
thanks alot singh. I now have no errors when i complile and can get the program to list the numbers from the text file yet the program then crashes and i get the error message Exception in Thread "main" java.lang.ArrayIndexOutOfBoundsException at coursework.main(coursework.java:52)

from searching the net it looks to me that there was a problem with my program as it was trying to find an extra number in the array, due to the loop starting at k=0, therefore i changed line 51
51> for ( k=0; k<x; k++){
52> sumVibration += Double.parseFloat ( args [k] ) ; to
51> for ( k=0; k<(x-1); k++){
52> sumVibration += Double.parseFloat ( args [k] ) ;

yet this has not solved the problem
id be very greatfull if you could enlighten me as to where i am stuck, i did not realise java could be this frustrating!!
thanks rachael

Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: cannot resolve symbol: variable Posted: Dec 1, 2002 4:14 AM
Reply to this message Reply
Seems that in your line 51 and 52, you need to make use of records instead of args.

rachael

Posts: 3
Nickname: rachy
Registered: Nov, 2002

Re: cannot resolve symbol: variable Posted: Dec 1, 2002 7:51 AM
Reply to this message Reply
thanks for your reply singh,
however i have tried replacing args with records and instead of the ArrayIndexOutOfBoundsException i now get the error message :

Exception in thread "main" java.lang.NumberFormatException:
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal).java:1176)
at java.lang.Float.parseFloat(Float.java:183)
at problem.main(problem.java:54)

think i might have just made the problem a whole lot more complicated. realise i am completely out of my depth and think i might have to purchase java for dummies tomorrow as the net isnt helping me that much!
dont worry if you cant help me, thank you your time.

Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: cannot resolve symbol: variable Posted: Dec 2, 2002 12:46 AM
Reply to this message Reply
Buy the book. It is a good idea.

In your program, do the following...

1. Change : sumVibration += Double.parseFloat ( records[k] ) ;
to sumVibration += Double.parseDouble ( records [k] ) ;

2. Change : sumVibration / (int) x = mean1;
to : mean1 = sumVibration / x;

3. Do the same for mean2.

Good luck.

Flat View: This topic has 5 replies on 1 page
Topic: Code for One JButton Previous Topic   Next Topic Topic: Chat Application

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use