• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiler Error Question

 
Frances Hollis
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a compiler error, can anyone suggest why? Here is the portion of the code involved.

//populateNames
public static void populateNames(String[]theNames)

for (i=0;i<test.length;i++)
{
system.out.println("Please enter the student's name.");
theName[i]= keyboard.next;
system.out.println(theName[i]);

}


Here is the error.


C:\Documents and Settings\Ann\Desktop\StuTestAnn.java:47: ';' expected
^
1 error

Tool completed with exit code 1

Thanks, Frances
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We'd need to see more to track this down. There's only one definite error here (lowercase "system" should be "System", uppercase) but potentially more, depending on where and how various variables are declared. Furthermore, errors like "expected ;", "}" or "{" often really mean an error in some earlier part of the code; the line pointed to is where the compiler just gave up trying to figure things out, but the problem happened elsewhere. So lets see the whole file up to and including this passage.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, maybe it was just an error copying it ot the post, but did you forget a pair of braces?
 
Frances Hollis
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, here is all the code.

import static java.lang.System.out;
import java.util.Scanner;

public class StuTestAnn
{
private static Scanner keyboard = new Scanner(System.in);

public static void main(String[] args)

{
int students;
int tests;
int[][] testScores; // [students][tests]
String[] stuNames;

testScores = createArray();
if(testScores != null)
{
stuNames = new String[testScores.length];
populateNames(stuNames);
populateTestScores(stuNames,testScores);
// printStudentReport(stuNames,testScores);
// printTestReport(stuNames,testScores);
out.println("\n\nGoodbye!\n\n");
}
else
{
out.println("Array not successfully created - exiting");
}
}

// Code your 5 methods below...


//createArray
public static int[][] createArray()
{

int[][] theArray;
theArray = new int[students][tests];
return theArray;
}


//populateNames
public static void populateNames(String[]theNames)

for (i=0;i<test.length;i++)
{
system.out.println("Please enter the student's name.");
theName[i]= keyboard.next;
system.out.println(theName[i]);

}

//populateTestScores

public static void populateTestScores(int[][]theScores)
for (i=0; i<tests.length; i++)
{
for(j=0;j<tests[0].length;j++)
{
system.out.println("Please enter test score.");
tests[i] = keyboard.nextInt();
}
}



}
 
Ramen Chatterjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

When posting code please use the code tags. This will preserve formatting and make it easier to read. I suggest you take a closer look at Stan's posting, then at your code. The compiler will tell you roughly where the problem occurred. If you are still stuck then, come back.

Regards

Ramen
[ September 11, 2006: Message edited by: Ramen Chatterjee ]
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the error message tells you the error is on line 47.
So look at line 47 of your source code.

Look at this line:

theName[i]= keyboard.next;

What happens there? Aren't you missing some () there?
 
Frances Hollis
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone. I fixed the braces and the (). That caused 26 more errors to appear. I have figured out all but 2. Still plugging along.
Again, thank you for the help!

Frances
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That caused 26 more errors to appear.


Isn't that just the way life goes? Keep having fun!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be the perfect time to point something out... if you are getting 26 errors after fixing two or three, you are not compiling often enough. it sounds like you wrote the whole program, and are only now compiling it for the first time.

What i'd suggest you do from now on, is every time you write 3-4 new lines of code, it compile it again. that way, if you get an error, you KNOW which 3-4 lines caused the problem.

try to write as little as possible each time you re-compile. test it as you go.

believe me, that will make your life much easier in the long run.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic