Welcome to Dream.In.Code
Become a Java Expert!

Join 149,823 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,671 people online right now. Registration is fast and FREE... Join Now!




Teaching myself Java

2 Pages V  1 2 >  
Reply to this topicStart new topic

Teaching myself Java, Eclipse SDK

mattman059
6 Feb, 2007 - 09:04 PM
Post #1

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 362


Dream Kudos: 175
My Contributions
When i run the following code i recieve this error at the class def for Message2:

The serializable class Message2 does not declare a static final serialVersionUID field of type long

CODE

import java.awt.*;

class Message2 extends Frame
{
    Font f;
    
    Message2(){
        f = new Font("SansSerif",Font.BOLD, 24);
        setBackground(Color.yellow);
        setSize(400,150);
    }
    
    public void paint(Graphics g){
        g.setFont(f);
        g.setColor(Color.blue);
        g.drawString("Welcome to Java",100,100);
        
    }

    public static void main(String[] arg){
        Message2 m2 = new Message2();
        m2.setVisible(true);
        
    }
    
}


What am i doign wrong? i typed the example straight from the book...

thanks.
User is offlineProfile CardPM
+Quote Post

horace
RE: Teaching Myself Java
7 Feb, 2007 - 01:44 AM
Post #2

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 5 times
Dream Kudos: 50
My Contributions
have a look at
http://forum.java.sun.com/thread.jspa?thre...04&tstart=0
User is offlineProfile CardPM
+Quote Post

mattman059
RE: Teaching Myself Java
7 Feb, 2007 - 05:45 AM
Post #3

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 362


Dream Kudos: 175
My Contributions
Since im completely new to java, the explanations given didnt make very much sense...im still not sure what I'm supposed to do inorder to make my program work..is there a specific function that needs to be written?
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Teaching Myself Java
7 Feb, 2007 - 07:39 AM
Post #4

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
I don't think that it is supposed to be a compilation error. Eclipse likes to complain about some idiot things, that you should simply ignore (it is one of those, it is most likely a warning, or problem, or whatever the heck it calls 'em).
So if your program doesn't stat, try to look at the compilation errors (Console tab/view). What you quoted here, is most likely from the problems view, and should be ignored.
User is offlineProfile CardPM
+Quote Post

Programmist
RE: Teaching Myself Java
7 Feb, 2007 - 07:42 AM
Post #5

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,252



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
What you are receiving is a warning, not an error, so it won't stop your program from compiling and running, if you're using Eclipse. If you're compiling from the command line you'll have to use "javac -Xlint yourClass.java." Since you're just now learning Java, I wouldn't worry too much about this. Just remember that, down the road, you will want to include this SerialVersionID. If you want to include it now (and you're using Eclipse), click on the little yellow warning icon on the left margin and it will give you some options to automagically generate it in for you.
User is online!Profile CardPM
+Quote Post

1lacca
RE: Teaching Myself Java
7 Feb, 2007 - 09:14 AM
Post #6

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
QUOTE(alcdotcom @ 7 Feb, 2007 - 04:42 PM) *

Just remember that, down the road, you will want to include this SerialVersionID.


Why? It is computed automatically. There is an urban legend surfacing from time to time, that declaring it makes serialization faster, because the JVM has to recalculate this value a lot of times. It is only half true: the JVM calculates it, but only once (either when the class is loaded, or when it is first needed, I am not sure). So generally, you can forget about it, unless you want to override serialization in a way, so that it lets you import a class into a different version from the one it was serlialized as (can be quite risky!).

User is offlineProfile CardPM
+Quote Post

beef
RE: Teaching Myself Java
7 Feb, 2007 - 01:00 PM
Post #7

D.I.C Head
Group Icon

Joined: 2 Nov, 2006
Posts: 128


My Contributions
I usually find myself dropping it in so eclipse will shut up but I've yet to actually use it for anything.

Here's what I drop in to get it to leave me alone:
CODE
public class blahblah extends whatever
{
    private static final long serialVersionUID = 1;

    ...everything else...


Sounds like it may be worth looking into for an actual use though.
User is offlineProfile CardPM
+Quote Post

mattman059
RE: Teaching Myself Java
7 Feb, 2007 - 01:41 PM
Post #8

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 362


Dream Kudos: 175
My Contributions
Okay so I clicked the console tab and this is the error that it gives


java.lang.NoClassDefFoundError: message
Exception in thread "main"
User is offlineProfile CardPM
+Quote Post

Programmist
RE: Teaching Myself Java
8 Feb, 2007 - 02:08 PM
Post #9

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,252



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
QUOTE(1lacca @ 7 Feb, 2007 - 11:14 AM) *

QUOTE(alcdotcom @ 7 Feb, 2007 - 04:42 PM) *

Just remember that, down the road, you will want to include this SerialVersionID.


Why? It is computed automatically. There is an urban legend surfacing from time to time, that declaring it makes serialization faster, because the JVM has to recalculate this value a lot of times. It is only half true: the JVM calculates it, but only once (either when the class is loaded, or when it is first needed, I am not sure). So generally, you can forget about it, unless you want to override serialization in a way, so that it lets you import a class into a different version from the one it was serlialized as (can be quite risky!).

Why not? If you're nimble with the mouse it only takes a few seconds to generate one, so - I say again - why not just be in compliance? But it does actually have a purpose, unrelated to any speed enhancements.

QUOTE
In anticipating the need to evolve a serializable class, Java serialization provides a serialVersionUID, also called suid, in the ObjectStreamClass for version control. suid is used to inform the Java serialization mechanism which version of the class is compatible with this serialized object. However, the importance of this field is often overlooked, resulting in release incompatibility...

read more
User is online!Profile CardPM
+Quote Post

mattman059
RE: Teaching Myself Java
9 Feb, 2007 - 08:31 PM
Post #10

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 362


Dream Kudos: 175
My Contributions
still havent found out what the error means..lots of sites that mention it, non say how to fix it
User is offlineProfile CardPM
+Quote Post

horace
RE: Teaching Myself Java
9 Feb, 2007 - 11:21 PM
Post #11

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 5 times
Dream Kudos: 50
My Contributions
QUOTE(mattman059 @ 7 Feb, 2007 - 09:41 PM) *

Okay so I clicked the console tab and this is the error that it gives


java.lang.NoClassDefFoundError: message
Exception in thread "main"

it cannot find class message
check you have the name correct - in particular capital letters etc - java is case sensitive, e.g. message is not the same as Message, etc
User is offlineProfile CardPM
+Quote Post

Programmist
RE: Teaching Myself Java
10 Feb, 2007 - 10:39 AM
Post #12

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,252



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
Are you using Eclipse? If so, you should see little red icons that will lead you to the problem. Or look in the "Problems" tab and when you see a red icon, double-click it and it will take you to the problem.
User is online!Profile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:00AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month