Hello, I saved the file as Exercise1.java but when I compile it I receive errors as stated: What must I do to resolve these mistakes? I think it’s got to do with the package statement.
package com.acme; import java.util.*; public class Exercise1 { int counter; public void go() { int sum = 0; int i = 0; while (i<100) { if (i==0) sum = 100; sum = sum +1; i++; System.out.println(sum); } } public void main (String args[]) { Exercise1 instance = new Excercise1(); instance.go(); } } > javac Excercise1.java
c:\jdk1.3\bin>javac Excercise1.java Excercise1.java:5: class Exercise1 is public, should be declared in a file named Exercise1.java public class Exercise1 { ^ Excercise1.java:20: cannot resolve symbol symbol : class Excercise1 location: class com.acme.Exercise1 Exercise1 instance = new Excercise1(); ^ 2 errors
Snigdha Solanki
Ranch Hand
Joined: Sep 07, 2000
Posts: 128
posted
0
It's because of a spelling mistake Inside main change the following line Exercise1 instance = new Excercise1(); to Exercise1 instance = new Exercise1(); and it will work.
Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
You need to compile the code like this javac com/acme/Exercise1.java only if the file Exercise1.java is in folder com/acme. Otherwise you can compile like this: javac -d . Exercise1.java this will create com/acme directories and add the put classfile in it.