Java very basic problem ... "Hello World"

b4u

Golden Member
Nov 8, 2002
1,380
2
81
Hi,

I'm having a really n00b problem over here ... can't seem to put a "Hello World" program to work ... :(

C'mon, don't laugh at me ... :)

I'm getting the error message Exception in thread "main" java.lang.NoClassDefFoundError: cript/class. Searching google, I think it has something to do with classpaths or something similar, but can't seem to set them up ... I attached code with the steps I took.

For quick reference:

Filename: cript.java
Contents:
class cript {
public static void main(String[] args) {
System.out.println("This s**t doesn't work!\n");
}
}

My set environment variables:

CLASSPATH=.;C:\Program Files\SQLLIB\java\db2java.zip;C:\Program Files\SQLLIB\java\runtime.zip;C:\Program Files\SQLLIB\bin
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\SQLLIB\BIN;C:\Program Files\SQLLIB\FUNCTION;C:\Program Files\SQLLIB\HELP;C:\Program Files\j2sdk1.4.2_05\bin



Thanks for help ...
 

Aso

Senior member
Aug 16, 2000
381
0
76
You forgot to make the class public. By default java makes classes and methods private. I attached code with the fix.
 

b4u

Golden Member
Nov 8, 2002
1,380
2
81
I've tried it ... no result, same problem ...

Also checking Java Sun Tutorials, they have a similar code (but one that works) - I pasted it on attach.

Here on my machine, it comes up dead :(


Any ideas?
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Don't type "java cript.class". You don't want to add the .class file extension. Just type "java cript".
 

b4u

Golden Member
Nov 8, 2002
1,380
2
81
Originally posted by: MrChad
Don't type "java cript.class". You don't want to add the .class file extension. Just type "java cript".

I can only say ... :Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q

I was getting shocked as I read your answer! I tried everything! Well, everything except what you told me!

I was sure it should be something simple, but even the simplest thing has it's own bottom limitations! lol


Thanks. It works now.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: b4u
Originally posted by: MrChad
Don't type "java cript.class". You don't want to add the .class file extension. Just type "java cript".

I can only say ... :Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q

I was getting shocked as I read your answer! I tried everything! Well, everything except what you told me!

I was sure it should be something simple, but even the simplest thing has it's own bottom limitations! lol


Thanks. It works now.

Consider yourself shot
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: b4u
Originally posted by: MrChad
Don't type "java cript.class". You don't want to add the .class file extension. Just type "java cript".

I can only say ... :Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q:Q

I was getting shocked as I read your answer! I tried everything! Well, everything except what you told me!

I was sure it should be something simple, but even the simplest thing has it's own bottom limitations! lol


Thanks. It works now.

Very common mistake. Don't sweat it. ;)
 

b4u

Golden Member
Nov 8, 2002
1,380
2
81
Hi, I'm re-using this thread for another question:

I'm trying to create a class, as an extention of another one. I want a class to have all functionality of the java.io.File class, plus another method I want to add.

So, I created the class as follows (I'm using Eclipse 3.0):

package pckTeste;

import java.io.File;

public class FileExtend extends File {
public FileExtend() {

}
}


The problem is that eclipse underlines the text "FileExtend()", as an error, and gives me the following error description:

"Implicit super constructor File() is undefined. Must explicitly invoke another constructor"

I'm trying to put it to work, but there is some basic point I'm missing here ... anyone can help?


<edit>
I believe this as something to do with the super(); contructor maybe, but this is still a bit confusing to me ... I'm googling for any info about this, but any help would certainly be welcomed ... :)
</edit>

Thank you.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: b4u
Hi, I'm re-using this thread for another question:

I'm trying to create a class, as an extention of another one. I want a class to have all functionality of the java.io.File class, plus another method I want to add.

So, I created the class as follows (I'm using Eclipse 3.0):

package pckTeste;

import java.io.File;

public class FileExtend extends File {
public FileExtend() {

}
}


The problem is that eclipse underlines the text "FileExtend()", as an error, and gives me the following error description:

"Implicit super constructor File() is undefined. Must explicitly invoke another constructor"

I'm trying to put it to work, but there is some basic point I'm missing here ... anyone can help?


<edit>
I believe this as something to do with the super(); contructor maybe, but this is still a bit confusing to me ... I'm googling for any info about this, but any help would certainly be welcomed ... :)
</edit>

Thank you.


As you can see- http://java.sun.com/j2se/1.4.2.../api/java/io/File.html - , there isn't a defualt constructor(no args) so the compiler is confused about what it should call. You can help it by making an explicit call to a certain one by calling super(args, go, here) and it will call that constructor.

 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
To elaborate: if you don't explicitly call some super constructor the compiler will insert a call for you. It will either be to the no-arg constructor. In your case, it doesn't exist and for good reason. You can't have a File that isn't linked to a real file somewhere. Therefore you should at least define FileExtend(String filename) from which you should call super(filename). If you really only want to change your one method then you should also implement the other constructors as pass-throughs in the same manner
 

b4u

Golden Member
Nov 8, 2002
1,380
2
81
Originally posted by: kamper
To elaborate: if you don't explicitly call some super constructor the compiler will insert a call for you. It will either be to the no-arg constructor. In your case, it doesn't exist and for good reason. You can't have a File that isn't linked to a real file somewhere. Therefore you should at least define FileExtend(String filename) from which you should call super(filename). If you really only want to change your one method then you should also implement the other constructors as pass-throughs in the same manner

Yes, I understand now, thank you for the explanation ;)