aspose file tools*
The moose likes Beginning Java and the fly likes Compiler Error Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compiler Error Question" Watch "Compiler Error Question" New topic
Author

Compiler Error Question

Frances Hollis
Greenhorn

Joined: Sep 02, 2006
Posts: 17
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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, maybe it was just an error copying it ot the post, but did you forget a pair of braces?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Frances Hollis
Greenhorn

Joined: Sep 02, 2006
Posts: 17
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

Joined: Apr 27, 2006
Posts: 62
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 ]

Could try harder
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

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?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Frances Hollis
Greenhorn

Joined: Sep 02, 2006
Posts: 17
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

Joined: Jan 29, 2003
Posts: 8791
That caused 26 more errors to appear.


Isn't that just the way life goes? Keep having fun!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10908
    
  12

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiler Error Question
 
Similar Threads
Working with OOP
Need practical example of wait() and notify()
SCJP6 book page 298 errata
custom tag and getAttribute
Error: Cannot find any information on property