• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Package Question

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should compile the code like this:

and run it like this:

/Rene
 
Snigdha Solanki
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic