Results 1 to 4 of 4

Thread: "unchecked or unsafe operations" compile error

  1. #1

    Thread Starter
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Resolved "unchecked or unsafe operations" compile error

    This error is driving me nuts. I've just got back to using Java again, after half a year or so, and now I can't seem to compile this very simple project.

    I cannot add items (strings) to an ArrayList. I get the compile error ''Staafdiagram.java uses unchecked or unsafe operations.".

    Can anyone help me with this?
    Code:
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.util.*;
    
    public class Staafdiagram extends Applet {
    
    	public void paint(Graphics g) {
    		ArrayList uni;
    	        uni = new ArrayList();
            	uni.add("abc");
    	}
    }
    Last edited by TheVader; Nov 22nd, 2004 at 07:24 PM.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    This compiled fine for me. You might be using an older version of java or something.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Actually, I think he's using a very new version. Some Java 5 compilers I've seen emit this warning (a warning, mind you, the compiling still works) if you're not using generics when you can, which is generally less safe than using them. ArrayList being the case. Make it an ArrayList<String> and it should compile fine.

    If your code is really Java 1.4, pass the "-source 1.4" switch to the compiler. This will eliminate the warning/error as well.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    Thanks, that was it indeed. I was using Java 1.5. I downgraded to version 1.4.2. Perhaps later on I'll reinstall 1.5 and see what advantages it brings; but for now I have a deadline to overcome.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

Posting Permissions

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



Click Here to Expand Forum to Full Width