• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

illegal start of an expression

 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or a method or (static) initializer block. But no, not directly in the class.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic