3 Replies - 650 Views - Last Post: 15 November 2011 - 12:24 AM Rate Topic: -----

#1 felicitybright  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-November 11

Compilation Errors in Graphics Programs

Posted 14 November 2011 - 11:24 AM

Hi

I am a newbie to Java, if you could please help me with this problem. I am trying to run some graphics programs. I have downloaded acm.jar, and included its path in my eclipse reader. The errors I get in almost all my graphics programs are:

java.lang.Error: Unresolved compilation problems:
The import acm cannot be resolved
The import acm cannot be resolved
GraphicsProgram cannot be resolved to a type
The method getHeight() is undefined for the type BouncingBall
GRect cannot be resolved to a type
GRect cannot be resolved to a type

at BouncingBall.<init>(BouncingBall.java:3)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

The program goes like:


import acm.program.*;
import acm.graphics.*;
 import java.awt.*;
 import acm.program.GraphicsProgram;
 
public class BouncingBall extends GraphicsProgram {
 
/** Runs the program */
   public void run() {
      double sqSize = (double) getHeight() / NROWS;
      for (int i = 0; i < NROWS; i++) {
         for (int j = 0; j < NCOLUMNS; j++) {
            double x = j * sqSize;
            double y = i * sqSize;
            GRect sq = new GRect(x, y, sqSize, sqSize);
            sq.setFilled((i + j) % 2 != 0);
            add(sq);
         }
      }
   }
 
/* Private constants */
   private static final int NROWS = 8;     /* Number of rows    */
   private static final int NCOLUMNS = 8;  /* Number of columns */
 
} 


I dont understand the error. Perhaps defining GraphicsProgram would solve the problem? How do I define that, I think it is suppose to be predefined.

Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Compilation Errors in Graphics Programs

#2 masijade  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: Compilation Errors in Graphics Programs

Posted 14 November 2011 - 01:22 PM

You do not have the library containg these "acm" classes on your classpath when compiling. Regardless of what you did that might make you think you included it, you haven't.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Compilation Errors in Graphics Programs

Posted 14 November 2011 - 02:28 PM

I have downloaded acm.jar, and included its path in my eclipse reader. 


Should be in your Eclipse "external JAR" properties

- Project
-- Properties
--- Java Build Path
---- Libraries
----- Add External JAR
Was This Post Helpful? 0
  • +
  • -

#4 felicitybright  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-November 11

Re: Compilation Errors in Graphics Programs

Posted 15 November 2011 - 12:24 AM

View Postmasijade, on 14 November 2011 - 01:22 PM, said:

You do not have the library containg these "acm" classes on your classpath when compiling. Regardless of what you did that might make you think you included it, you haven't.



View Postpbl, on 14 November 2011 - 02:28 PM, said:

I have downloaded acm.jar, and included its path in my eclipse reader. 


Should be in your Eclipse "external JAR" properties

- Project
-- Properties
--- Java Build Path
---- Libraries
----- Add External JAR


Thanks for replying. I have included acm in external JAR's properties. It still shows the same errors. I think I have correctly added the JAR because lines such as "import acm.graphics.GImage;" in my program do not have any 'red warnings' on the left side. However, when I try to open acm directly, it says "Invalid or corrupt jarfile at --location--". I have tried taking the acm from different websites, but it hasn't made a difference.

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1