The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Changing Name

Posted by Kishori Sharan on July 07, 2000 at 2:33 PM

It seems your CLASSPATH environment variable is not set correctly. Set CLASSPATH in your c:\autoexec.bat file like
CLASSPATH= your class path where java will look for .class file at run time
Please look in your C:\jdk1.2.2\bin directory if by mistake you have saved ButtonAbc.java there. I will suggest you to save all your files in one directory like C:\my_java and include C:\jdk1.2.2\bin in your PATH environment variable. On command line compile your java program like
C:\my_java>javac Button1.java

The second error
"error: File C:\JDK1.2.2\BIN\Button.java does not contain type Button as expected. Please adjust the class path so that the file does not appear in the unnamed package" you are getting is bacause you still have Button.java ( that you had creaded initially ) file in your current directory. Please delete it before you try next time.

But you must change the name of the class from Button to something else. I hope it may help you out.

Thanx
Kishori

> Hi

> I'm using JDK1.2.2. Initially, I thought about the Button name
> as well, since there is already a Button class in java.awt.*.
> Therefore I changed the name to ButtonAbc.java

> However I still get these errors....

> C:\JDK1.2.2\BIN\Button.java:4: Class ButtonAbc already defined in C:\jdk1.2.2\bin\ButtonAbc.java.
> public class ButtonAbc extends Applet{
> ^
> error: File C:\JDK1.2.2\BIN\Button.java does not contain type Button as expected. Please adjust the class path so that the file does not appear in the unnamed package.
> C:\jdk1.2.2\bin\ButtonAbc.java:6: Class Button not found.
> Button b1=new Button("Button 1");
> ^
> C:\jdk1.2.2\bin\ButtonAbc.java:6: Class Button not found.
> Button b1=new Button("Button 1");
> ^
> C:\jdk1.2.2\bin\ButtonAbc.java:7: Class Button not found.
> Button b2=new Button("Button 2");
> ^
> C:\jdk1.2.2\bin\ButtonAbc.java:7: Class Button not found.
> Button b2=new Button("Button 2");
> ^
> C:\jdk1.2.2\bin\ButtonAbc.java:11: Class Button not found in void init().
> add(b1);
> ^
> C:\jdk1.2.2\bin\ButtonAbc.java:12: Class Button not found in void init().
> add(b2);

> After explicitly importing Button class ( import java.awt.Button; ),
> everything in fine.

> Shanu

>
> > There is no problem initializing b1 and b2 in one declaration. The problem is the name of the applet. Change the name from Button to anything else like Button1 and your code will compile fine. It's because Button is a Java defined class.

> > Thanx
> > Kishori

> > > import java.awt.*;
> > > import java.applet.*;

> > > public class Button extends Applet{
> > > Button
> > > b1=new Button("Button 1"),
> > > b2=new Button("Button 2");
> > > public void init(){
> > > add(b1);
> > > add(b2);
> > > }
> > > }

> > > the above is a little program direct from the book Thinking in Java.But I can not interpret it.two error message prompt up saying" wrong number of arguments in constructor"
> > > I also saw other books, this program is proved to be correct . But Why can't it be complied with JDK1.2.2?
> > >






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us