This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Compiler Error Question

 
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
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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.
 
(instanceof Sidekick)
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();
}
}



}
 
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 ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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)
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!
 
lowercase baba
Posts: 12753
51
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
Boost this thread!