aspose file tools
The moose likes Beginning Java and the fly likes Errors - PLEASE HELP! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Errors - PLEASE HELP!" Watch "Errors - PLEASE HELP!" New topic


Naf Rash
Ranch Hand

Joined: Feb 19, 2004
Posts: 85
I'm having some problems with some code I've written- I keep getting errors.I have had a look at the code myself but think that a new pair of eyes may be needed beacuse I probably have made a stupid mistake somewhere but can't seem to find it. Just to provide you with some information - this class is used by another class and it obtains an array from another class also. The errors I'm receiving are:
- Syntax error on keyword "public"; ";", "," expectedline 10
- all cannot be resolvedline 20
- Syntax error on token "row", "]" expectedline 38
PLEASE HELP. The code is:
class Clusteringclass {
distances dist = new distances();
double theRow = 1;
double theCoulmn =0;
double newRow = 1

public Clusteringclass(){
private void obtainClusters(double distanceMatrix[][]){
for (int i=0;i<distanceMatrix.length; ++i){
for (int all = 1; all<distanceMatrix.length; ++all)
for (double checkDistanceVal = 100; checkDistanceVal > distanceMatrix[i][all] && distanceMatrix[i][all] !=0
checkDistanceVal = distanceMatrix[i][all];/*This will hold the final value ie, the value with the smallest distance.*/
double row = i;
double column = all;/*These assignments ensure that the corresponding row and column numbers are stored for the
shortest value.*/


public double[][] addElement(double[][] distanceMatrix, double row, double column ){

double[][] newArray = new double [distanceMatrix.length - 1][distanceMatrix.length - 1];/*Creates a brand new array of greater
for ( int i = 0; i < distanceMatrix.length; i++){
system.out.println (i+"\n");
if (i != row && i != column){/*As long as the element of distance matrix being covered is not*/
newArray[i - 1] = distanceMatrix[i];/*Assigns elements of the distance matrix to the new Array. use -1 because obviously
the array size will decrease since the rows that are of the shortest distance will be amalgamated into 1. */

for (int i = 0; i < theDistanceMatrix.length; ++i){
newArray[newRow][theColumn] = Math.min(double [row][i], double [column][i]);/*Puts the minimum value into the new array at the
++newRow;/*Only increment the row value because going to input the new values downwards. */

distanceMatrix = newArray;
return distanceMatrix;
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11734

You need a semi-colon on this line...

try that for starters.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
First it would help if you used the code tags to format your code, it makes it more readable. Also, if you're going to post a lot of code and then mention line numbers you should highlight or somehow mark those lines so we can tell what the lines in question are.
Fred is right, you need a semi colon on the line indicated.
Also, it lloks like, in this line:
for (int all = 1; all<distanceMatrix.length; ++all)
you declare a variable 'all'. that variable will be local to the block it is declared in and not visible outside of the block. In this case the for statement has no braces so the statement executed within the for loop would be the very next line. In any code after that line the variable 'all' would not be visible. So, in the line:
checkDistanceVal = distanceMatrix[i][all];/*This will hold the final value ie, the value with the smallest distance.*/
It can't see the variable. IF it needs to then declare all before the for statement so it local to the method instead of the for statement.
Hope that helps

Andrew Hocker

Joined: Feb 05, 2004
Posts: 13
I'm just a java newb, but shouldn't it be "all++" instead of "++all"?

I don't really know anything, google does though.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Andrew Hocker:
I'm just a java newb, but shouldn't it be "all++" instead of "++all"?

Either will work in this context. The difference is when these operators are used within another expression: all++ evaluates to the value of all BEFORE incrementing but ++all evaluates to the value of all AFTER incrementing. To see this in action, try the following example:

Java API Documentation
The Java Tutorial
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
It looks like you double-posted. Here's what I added in the other post:
There are seveal syntax errors, and fixing one leads to the creation of others. I'll list some of the errors that need to be fixed.
1. double theCoulmn =0; // Should be double theColumn =0;

2. system.out.println(...); // Should be System.out.println(...);

3. newArray[newRow][theColumn] = Math.min(double [row][i], double [column][i]);
"double" is not the name of an array. I think you want Math.min(distanceMatrix[row][i], distanceMatrix[column][i]);

4. for (int i = 0; i < theDistanceMatrix.length; ++i){
There is no "theDistanceMatrix" ... should be "i < distanceMatrix.length".

5. Since you are using "theRow", "theColumn" and "newRow" as array indexes, they should be declared as "int", not "double".

6. Based on how you're using it, the line "for (all = 1; all<distanceMatrix.length; ++all)"
should probably be "for (all = 1; all<distanceMatrix[i].length; ++all) (do you really want to start with "all=1", or "all=0"?)

7. For some reason it doesn't like the line " double row =(double)i;" right after the "for" loop. Even if you are only doing one thing inside of a control statement (if, for, while), it's not a bad idea to enclose it in curly braces. Just uncomment out the line right before it, which is probably what you want to happen inside of the loop.

These are just syntax errors. Once you get it clean-compiled you can worry about the logic errors.
I agree. Here's the link:
subject: Errors - PLEASE HELP!