Results 1 to 4 of 4
  1. #1
    Java_Lover is offline Member
    Join Date
    Apr 2010
    Location
    Virginia, USA
    Posts
    12
    Rep Power
    0

    Default Javac Error Message Interpretation

    Hello All.

    I am reading the book Java in easy steps and I am getting a javac error when compiling the code in the book. Here's the error:

    The serializable class HelloWorldApplet does not declare a static final serialVersionUID field of type long
    public class HelloWorldApplet extends JApplet

    The code:
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    
    public class HelloWorldApplet extends JApplet
    {
    	String message;
    	
    	public void init()
    	{
    		message = "Hello World2";
    	}
    
    	public void paint(Graphics artist)
    	{
    	
    		artist.drawString(message, 20,30);
    	}
    
    }
    This is placed in a BARE BONES html document. My question is what does the error mean?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    First observe that this is not an error, nor is it reported by the javac compiler.

    Java Code:
    C:\Documents and Settings\pbrockway2\Desktop>type HelloWorldApplet.java
    import javax.swing.*;
    import java.awt.*;
    
    public class HelloWorldApplet extends JApplet
    {
            String message;
    
            public void init()
            {
                    message = "Hello World2";
            }
    
            public void paint(Graphics artist)
            {
    
                    artist.drawString(message, 20,30);
            }
    
    }
    C:\Documents and Settings\pbrockway2\Desktop>javac -cp . HelloWorldApplet
    .java
    
    C:\Documents and Settings\pbrockway2\Desktop>

    You can get the compiler to report this message by using one of the -X options.

    Java Code:
    C:\Documents and Settings\pbrockway2\Desktop>javac -Xlint -cp . HelloWorl
    dApplet.java
    HelloWorldApplet.java:4: warning: [serial] serializable class HelloWorldApplet h
    as no definition of serialVersionUID
    public class HelloWorldApplet extends JApplet
           ^
    1 warning
    
    C:\Documents and Settings\pbrockway2\Desktop>

    So, it's a warning not an error. And you can basically ignore it. (Or compile from the command line in which case ... you never see it).

    --------------

    There is a description of what this (not really "New to Java") problem is at stackoverflow. Where the recommend telling your IDE to ignore the lack of id, or to autogenerate one.

  3. #3
    Java_Lover is offline Member
    Join Date
    Apr 2010
    Location
    Virginia, USA
    Posts
    12
    Rep Power
    0

    Default

    Thanks for your reply. I do see now where it's just a warning and not an error. My code did run as expected. I did look at the link and attempt to decipher the thread - I've still got the training wheels on so I am not grasping everything but do want to immerse myself.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    That's a good approach. You should be curious about messages as they always mean *something* even if, as in this case, you can ignore the warning. Your book should really have anticipated this situation (especially if you are using an IDE it recommends).

Similar Threads

  1. Javac error
    By Sotsiak in forum New To Java
    Replies: 5
    Last Post: 06-04-2010, 09:33 AM
  2. Javac error
    By Zorobay in forum New To Java
    Replies: 14
    Last Post: 03-03-2010, 01:00 AM
  3. error while compile code using javac
    By suri in forum New To Java
    Replies: 3
    Last Post: 01-20-2010, 10:10 AM
  4. ===javac error===
    By solt in forum New To Java
    Replies: 21
    Last Post: 12-06-2009, 10:18 AM
  5. Interpretation of regex?
    By Ms.Ranjan in forum New To Java
    Replies: 2
    Last Post: 04-23-2009, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •