For Programmers: Free Programming Magazines  


Home > Archive > Java Help > February 2006 > Problem Creating instances in Java









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem Creating instances in Java
carlito@whitmore.fsnet.co.uk

2006-02-22, 9:57 pm

Hi guys can anyone help im at my wits end with this.

i have many java programs on my computer that i have done in the past
and they all have worked fine. But!!! now i have a problem creating
instances of other classes for example:

Convert con = new Convert();

does not work. it says Cannot identify symbol Convert. But i know for a
fact the class Convert is compiled and also is in same directory.

Every time i try and compile a program it does not like any instance
methods.
(with all java files on my computer);

Many thanks

Andrew

Hal Rosser

2006-02-22, 9:57 pm


<carlito@whitmore.fsnet.co.uk> wrote in message
news:1140658929.449640.32150@f14g2000cwb.googlegroups.com...
> Hi guys can anyone help im at my wits end with this.
>
> i have many java programs on my computer that i have done in the past
> and they all have worked fine. But!!! now i have a problem creating
> instances of other classes for example:
>
> Convert con = new Convert();
>
> does not work. it says Cannot identify symbol Convert. But i know for a
> fact the class Convert is compiled and also is in same directory.
>
> Every time i try and compile a program it does not like any instance
> methods.
> (with all java files on my computer);


If you create a Convert constructor which accepts an arg - and you did not
create a no-arg constructor, that error will occur. Java provides the
no-arg constructor free of charge, unless you create a constructor - in
which case the no-arg constructor is -not- provided.


carlito@whitmore.fsnet.co.uk

2006-02-23, 3:57 am

actually my class Convert has a contructor with one argument. and i
call instance as follows

Convert con = new Convert(temp);

however when i compile from the command line it will not compile but if
i use a program such as netbeans or JCreate it compiles.

I dont understand why though

Cheers

Roedy Green

2006-02-23, 3:57 am

On 22 Feb 2006 17:42:09 -0800, carlito@whitmore.fsnet.co.uk wrote,
quoted or indirectly quoted someone who said :

>Convert con = new Convert();


You either screwed up your import or your classpath.

It is time to start putting all your code in a package. Package-less
stuff is just for experiments.


See http://mindprod.com/jgloss/classpath.html
http://mindprod.com/jgloss/import.html
http://mindprod.com/jgloss/package.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green

2006-02-23, 3:57 am

On Wed, 22 Feb 2006 21:58:59 -0500, "Hal Rosser"
<hmrosser@bellsouth.net> wrote, quoted or indirectly quoted someone
who said :

>If you create a Convert constructor which accepts an arg - and you did not
>create a no-arg constructor, that error will occur. Java provides the
>no-arg constructor free of charge, unless you create a constructor - in
>which case the no-arg constructor is -not- provided.

see http://mindprod.com/jgloss/gotchas.html#CONSTRUCTOR

You might check out the other gotchas lying in wait for you while you
are there.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green

2006-02-23, 7:03 pm

On 22 Feb 2006 20:07:56 -0800, carlito@whitmore.fsnet.co.uk wrote,
quoted or indirectly quoted someone who said :

>however when i compile from the command line it will not compile but if
>i use a program such as netbeans or JCreate it compiles.


see http://mindprod.com/jgloss/gettingstarted.html
http://mindprod.com/jgloss/helloworld.html
http://mindprod.com/jgloss/classpath.html

there are dozens of ways to do it wrong.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
carlito@whitmore.fsnet.co.uk

2006-02-23, 7:03 pm

Thanks Guys everything really helped i have subsequently fixed the
problem.
The problem was that when setting my classpath i did not include
working directory as follows:

Classpath = C:\SomeFolder;C:\SomeOtherFolder\Some.jar; . ;

I needed to include the dot to include working dir

Cheers Again

Andrew

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com