Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiler error when trying to compile my program.  RSS feed

 
Bill foster
Ranch Hand
Posts: 63
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm Bill and I just started again programming I have this program and I'm getting a error on the compiler that reads:

jGRASP exec: javac -g RectangleMover.java
RectangleMover.java:12: error: invalid method declaration; return type required
public static main(String[] args){
^
1 error

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete

In the code below I trying to create a program that uses the Rectangle class to create and move the rectangle so that when you are finish you should have four rectangles two on the top and two on the bottom. This should create one big rectangle. Then after each translation it prints the new coordinates on the screen.

This exercise is from an old book and I have do not know how to create a class. that is in a later chapter.





Thank you for the help.


Bill
 
Paul Clapham
Sheriff
Posts: 22471
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need

 
Bill foster
Ranch Hand
Posts: 63
Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks actually I also found another error it was on the command system.out.println I had[syste.out.println] I forgot the m in system I was able to glean over my code and noticed that syntax error.

Thanks again!



Bill
 
fred rosenberger
lowercase baba
Bartender
Posts: 12541
48
Chrome Java Linux
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, i'd say your first step should have been to delete most of your code. You should NEVER write more than a couple of lines before trying to compile. Personally, even if just copying this code from a book, I'd have done this much before compiling the first time:


Compile that first. If you have an error, there's really only a couple of places to look. Line 1 and line 2.
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another trick about compiler errors. If you have managed to write too much code and have hundreds of errors, correct the first one after where you wrote javac. That may remove dozens of other error messages because you can get multiple messages for the same error.

You also have far too much code in the main method, and you are probably using the Rectangle class for something it was not designed for.
 
Bill foster
Ranch Hand
Posts: 63
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the input, I actually copied from a book, and tried to cut and paste. I think I created the two bugs the code when I did this.

I was working from a old text book and it was one of the exercises that explained how to create objects using the constructors. Next chapter we the book will be creating a bank account program where the user can deposit, withdraw and get balances of the accounts This will be where I will create a class(blue print of the objects).


Since the book is old (2007) should I be looking at a newer book? What do you guys think?

I was just thinking just use the book to learn the basics like polymorphism, encapsulation and creating methods.

Thanks,
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which book was it? Rather than getting rid of the book, you might consider getting a book to update you to Java8, e.g. Java8 in Action by Urma, Fusco and Mycroft, or Java8 for the Really Impatient by Cay Horstmann. If the book were older than 2004 it would not cover Java5, but a 2007 book probably covers Java6. There were many changes from Java6 to Java8, but I think at your stage you need to know about these three Java7 changes:-
  • 1: Try with resources
  • 2: Updates to the switch statement
  • 3: New types of file input
  • Later you can find out about new threading capabilities, e.g. fork/join, and new forms of number literals with the _ character. I think Horstmann covers some Java7 changes, too.
     
    Bill foster
    Ranch Hand
    Posts: 63
    Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have the Book:"Java Concepts" By Cay Horstmann. This is the first book I learn Java from. I think it was when Java 5.0 came out.
     
    Campbell Ritchie
    Marshal
    Posts: 55672
    161
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is as close as I can get to Java Concepts 2007 edition. It would appear to cover Java6, so maybe you could still consider the suggestion I made yesterday.
     
    Bill foster
    Ranch Hand
    Posts: 63
    Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Ritchie,

    I think your idea is better, I should learn the java 8, I read up on lambda and it seems like it is pretty complex. I'm thinking about taking the java associate/java 8 cert in the future.
    Thanks again!
     
    Campbell Ritchie
    Marshal
    Posts: 55672
    161
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    A λ is less complicated than you think, but you have to start small and take it slowly to learn. And be sure to have a good look at Streams.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!