java unchecked or unsafe operations error

Discussion in 'Java' started by solomon13000@gmail.com, Oct 4, 2007.

  1. Guest

    I am getting the following error

    Note: C:\Documents and Settings\Eugene\Desktop\client\LocalBoard.java
    uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    for the code bellow:


    Toobar.java
    ----------------

    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.Vector;
    import java.util.Iterator;

    public class Toolbar extends JPanel implements ChangeListener{
    private WhiteboardState whiteboardState;
    private Vector toolButtons;
    public Toolbar(WhiteboardState w, LayoutManager l){
    super(l);
    whiteboardState = w;
    toolButtons = new Vector();
    }

    public Component add(Component c){
    if (c instanceof ToolButton){
    toolButtons.add(c);
    }
    return super.add(c);
    }

    public void stateChanged(ChangeEvent e){
    ToolButton changed = (ToolButton)e.getSource();
    if (changed.isSelected()){
    whiteboardState.currentTool = changed.tool;
    changed.setSelected(true);
    } else {
    whiteboardState.currentTool = null;
    }
    Iterator i = toolButtons.iterator();
    ToolButton t;
    while(i.hasNext()){
    t = (ToolButton) i.next();
    if (t != changed){
    t.setSelected(false);
    }
    }
    repaint();
    }
    }


    LocalBoard.java
    ----------------------

    import java.util.*;
    import java.rmi.*;

    public class LocalBoard implements ShapeBuffer {

    protected Hashtable shapes; // our list of shapes
    protected int minZ = Integer.MAX_VALUE;
    protected int maxZ = Integer.MIN_VALUE;

    public LocalBoard() {
    shapes = new Hashtable();
    }

    public Updater trylock(Shape s) {
    // Unimplemented in LocalBoard
    // (don't modify this class; just write RemoteBoard)
    return null;
    }

    /** Returns read-only list of content in the canvas */
    public Collection getAllShapes() throws RemoteException {
    Enumeration e;
    Integer crKey;
    List v = new ArrayList();
    Shape shp;

    for(e = shapes.keys();e.hasMoreElements();) {
    crKey = (Integer)e.nextElement();
    shp = (Shape)shapes.get(crKey);
    v.add(shp);
    }

    // sorting by ID
    Collections.sort(v,new Comparator(){

    public int compare(Object arg0, Object arg1) {
    Shape s1, s2;

    s1 = (Shape)arg0;
    s2 = (Shape)arg1;

    return s1.getID() - s2.getID();
    }
    });

    return v;
    }

    /** Add a subscriber */
    public void attach(Subscriber o) {
    // Unimplemented in LocalBoard
    // (don't modify this class; just write RemoteBoard)
    }

    /** Remove a subscriber */
    public void detach(Subscriber o) {
    // Unimplemented in LocalBoard
    // (don't modify this class; just write RemoteBoard)
    }

    public int addShape(Shape newShape) throws InvalidShapeException,
    OverflowException, RemoteException {
    int ID;
    int zIndex = newShape.getZIndex();

    if(newShape == null) throw new InvalidShapeException("Null
    shape data in addShape!");
    if(getShapeCount() >= MAX_CAPACITY) throw new
    OverflowException("Shape buffer overflow!");

    ID = newShape.getID();
    shapes.put(new Integer(ID),newShape);

    if(minZ > zIndex) minZ = zIndex;
    if(maxZ < zIndex) maxZ = zIndex;

    return ID;
    }

    public boolean containsShape(int ID) throws RemoteException {
    return shapes.containsKey(new Integer(ID));
    }

    public boolean isEmpty() throws RemoteException {
    return (shapes.size() == 0);
    }

    public int getShapeCount() throws RemoteException {
    return shapes.size();
    }

    public Shape getShape(int ID) throws NoSuchShapeException,
    RemoteException {
    if(containsShape(ID)) return (Shape)shapes.get(new
    Integer(ID));
    else throw new NoSuchShapeException("No shape with ID " + ID);
    }

    public void bringToFront(int ID) throws NoSuchShapeException,
    RemoteException {
    }

    public void sendToBack(int ID) throws NoSuchShapeException,
    RemoteException {
    }

    public Collection getByZIndex(int z) throws RemoteException {
    return null;
    }

    public int getMinZIndex() throws RemoteException {
    return 0;
    }

    public int getMaxZIndex() throws RemoteException {
    return 0;
    }

    }


    How do I solve the problem?

    Your help is kindly appreciated.
     
    , Oct 4, 2007
    #1
    1. Advertising

  2. wrote:
    > I am getting the following error
    >
    > Note: C:\Documents and Settings\Eugene\Desktop\client\LocalBoard.java
    > uses unchecked or unsafe operations.
    > Note: Recompile with -Xlint:unchecked for details.
    >
    > for the code bellow:


    > import java.util.Vector;


    > private Vector toolButtons;


    I am pretty sure that it want you to use generics.

    private Vector<Something> toolButtons;

    possible:

    private Vector<ToolButton> toolButtons;

    Arne
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Oct 4, 2007
    #2
    1. Advertising

  3. Chris Dollin Guest

    wrote:

    > I am getting the following error
    >
    > Note: C:\Documents and Settings\Eugene\Desktop\client\LocalBoard.java
    > uses unchecked or unsafe operations.
    > Note: Recompile with -Xlint:unchecked for details.
    >
    > for the code bellow:


    ("below", not "bellow". A "code bellow" would be some loud programming.)

    (fx:snip)

    > How do I solve the problem?


    Recompile with -Xlint:unchecked for details, then fix the details.

    --
    Chris "DWIS" Dollin

    Hewlett-Packard Limited Cain Road, Bracknell, registered no:
    registered office: Berks RG12 1HN 690597 England
     
    Chris Dollin, Oct 4, 2007
    #3
  4. xen Guest

    On Thu, 04 Oct 2007 05:13:36 -0700, wrote:

    >I am getting the following error
    >
    >Note: C:\Documents and Settings\Eugene\Desktop\client\LocalBoard.java
    >uses unchecked or unsafe operations.
    >Note: Recompile with -Xlint:unchecked for details.
    >
    >for the code bellow:
    >


    <snip>

    >
    >How do I solve the problem?
    >
    >Your help is kindly appreciated.


    It's not a problem, but you can 'solve' it by learning how to use
    generics:

    http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
     
    xen, Oct 5, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Axl
    Replies:
    2
    Views:
    15,640
    John C. Bollinger
    Sep 2, 2004
  2. rockdale
    Replies:
    3
    Views:
    3,272
    rockdale
    Nov 3, 2006
  3. Eric I.
    Replies:
    6
    Views:
    675
    Eric I.
    Aug 15, 2008
  4. justineee

    "unsafe and unchecked" error

    justineee, Oct 23, 2008, in forum: Java
    Replies:
    5
    Views:
    583
    justineee
    Oct 24, 2008
  5. RVic
    Replies:
    19
    Views:
    1,404
Loading...

Share This Page