This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes illegal start of an expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "illegal start of an expression" Watch "illegal start of an expression" New topic
Author

illegal start of an expression

Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
I am getting a gigantic pile of errors that clearly arent correct, which tells me a lot of this can be fixed with just one or two changes.


BenHultinProg4.java:22: illegal start of type
for (i = 1; i < 13; i++) {
^
BenHultinProg4.java:22: <identifier> expected
for (i = 1; i < 13; i++) {
^
BenHultinProg4.java:22: ';' expected
for (i = 1; i < 13; i++) {
^
BenHultinProg4.java:24: <identifier> expected
saver1.getBalance()
^
BenHultinProg4.java:24: ';' expected
saver1.getBalance()
^
BenHultinProg4.java:27: <identifier> expected
saver2.getBalance()
^
BenHultinProg4.java:27: ';' expected
saver2.getBalance()
^
BenHultinProg4.java:30: <identifier> expected
System.out.printf(DATA_FMT_STR, 0, saver1.getACCOUNT_NUMBER(), saver1.ba
lance,
^
BenHultinProg4.java:30: <identifier> expected
System.out.printf(DATA_FMT_STR, 0, saver1.getACCOUNT_NUMBER(), saver1.ba
lance,
^
BenHultinProg4.java:30: illegal start of type
System.out.printf(DATA_FMT_STR, 0, saver1.getACCOUNT_NUMBER(), saver1.ba
lance,
^
BenHultinProg4.java:30: <identifier> expected
System.out.printf(DATA_FMT_STR, 0, saver1.getACCOUNT_NUMBER(), saver1.ba
lance,
^
BenHultinProg4.java:30: ';' expected
System.out.printf(DATA_FMT_STR, 0, saver1.getACCOUNT_NUMBER(), saver1.ba
lance,
^
BenHultinProg4.java:30: illegal start of type
System.out.printf(DATA_FMT_STR, 0, saver1.getACCOUNT_NUMBER(), saver1.ba
lance,
^
BenHultinProg4.java:30: ';' expected
System.out.printf(DATA_FMT_STR, 0, saver1.getACCOUNT_NUMBER(), saver1.ba
lance,
^
BenHultinProg4.java:30: <identifier> expected
System.out.printf(DATA_FMT_STR, 0, saver1.getACCOUNT_NUMBER(), saver1.ba
lance,

^
BenHultinProg4.java:31: ';' expected
saver2.getACCOUNT_NUMBER(), save
r2.balance);
^
BenHultinProg4.java:31: invalid method declaration; return type required
saver2.getACCOUNT_NUMBER(), save
r2.balance);
^
BenHultinProg4.java:31: ';' expected
saver2.getACCOUNT_NUMBER(), save
r2.balance);
^
BenHultinProg4.java:44: class, interface, or enum expected
}
^
49 errors






Here is my driver file:




here is my driven class:




I appreciate any help in the matter
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

The main problem with your class BenHultinProg4 is that you are putting all kinds of statements directly in the class declaration. That doesn't work. You need to create methods, and put those statements inside methods. You can't, for example, call System.out.printf(...) at class level. You can only do that inside a method.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Or a method or (static) initializer block. But no, not directly in the class.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38044
    
  22
And don't write more than about 5 lines of code before you try compiling it. That many errors suggests you are trying to write dozens of lines, and will get all confused by the many errors.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: illegal start of an expression
 
Similar Threads
Help on testprogram and subclass please
Compound Interest on an object
Calculating a total after a "for" loop
printf problems
Having trouble understanding an error code i keep getting. Please help!