Question:
Hi! I’m hoping for help with understanding and fixing my code or files. I am trying to create an assignment for students to use that utilizes static graphics through the acm package. I have uploaded an acm.jar file but when I try to run the file, it gives me errors.
Repl link:
https://replit.com/@AmyWang51/Graphics-Starter-Code#MyProgram.java
This is all the code I have in my MyProgram.java.
import acm.program.*;
import acm.graphics.*;
import acm.util.*;
import java.util.*;
import java.io.*;
import java.awt.*;
public class MyProgram extends GraphicsProgram {
public void run(){
GRect hi = new GRect(50,50,50,50);
add(hi);
}
}
When I run it, I get the following errors:
./MyProgram.java:9: error: cannot find symbol
public class MyProgram extends GraphicsProgram {
^
symbol: class GraphicsProgram
./MyProgram.java:1: error: package acm.program does not exist
import acm.program.*;
^
./MyProgram.java:2: error: package acm.graphics does not exist
import acm.graphics.*;
^
./MyProgram.java:3: error: package acm.util does not exist
import acm.util.*;
^
./MyProgram.java:11: error: cannot find symbol
GRect hi = new GRect(50,50,50,50);
^
symbol: class GRect
location: class MyProgram
./MyProgram.java:11: error: cannot find symbol
GRect hi = new GRect(50,50,50,50);
^
symbol: class GRect
location: class MyProgram
Try to change the run
command in your .replit
file to this:
run = "javac -cp .:acm.jar MyProgram.java && java -cp .:acm.jar MyProgram"
So replit will compile your Java file with the ACM library included
1 Like
Thank you Windlother! I tried doing that but still received the same errors. Maybe this context might be helpful:
I forked this Replit from a former colleague (another teacher), so I’m not familiar with how the files all work. I see a .replit file AND a .replit.backup file.
The contents of the .replit file are:
compile = "javac -classpath .:target/dependency/* -d . $(find . -type f -name '*.java')"
run = ["java", "-classpath", ".:target/dependency/*", "Main"]
entrypoint = "Main.java"
hidden = ["**/*.class"]
[packager]
language = "java"
[packager.features]
packageSearch = true
[languages.java]
pattern = "**/*.java"
[languages.java.languageServer]
start = ["jdt-language-server"]
[unitTest]
language = "java"
[nix]
channel = "stable-21_11"
[debugger]
support = true
[debugger.compile]
command = "javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -g -d . $(find . -type f -name '*.java')"
[debugger.interactive]
transport = "localhost:0"
connectTimeout = 60
startCommand = "java-debug"
[debugger.interactive.initializeMessage]
command = "initialize"
type = "request"
[debugger.interactive.initializeMessage.arguments]
adapterID = "cppdbg"
clientID = "replit"
clientName = "replit.com"
columnsStartAt1 = true
linesStartAt1 = true
locale = "en-us"
pathFormat = "path"
supportsInvalidatedEvent = true
supportsProgressReporting = true
supportsRunInTerminalRequest = true
supportsVariablePaging = true
supportsVariableType = true
[debugger.interactive.launchMessage]
command = "launch"
type = "request"
[debugger.interactive.launchMessage.arguments]
classPaths = ["."]
mainClass = "Main"
The contents of the .replit.backup file are:
run ="javac -cp .:acm.jar MyProgram.java && java -cp .:acm.jar MyProgram"
Could this be where the potential issue is?
Oh yes, there is a bunch of things wrong.
Tbh, just erase all of the content of .replit and just let this in the file:
run = "javac -cp .:acm.jar MyProgram.java && java -cp .:acm.jar MyProgram"
entrypoint = "MyProgram.java"
(And transfer to .replit.backup)