Results 1 to 10 of 10
  1. #1
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default [SOLVED]Unchecked or Unsafe Operations Error Message

    So I am trying to compile two classes (User and ArrayListDemo) from the command prompt. When doing so, I encountered the following error message:

    Java Code:
    C:\tomcat\webapps\begjsp-ch08\WEB-INF\classes>javac com\wrox\utilities\ArrayList
    Demo.java
    Note: com\wrox\utilities\ArrayListDemo.java uses unchecked or unsafe operations.
    
    Note: Recompile with -Xlint:unchecked for details.
    Now, the User.java compiled fine. But when compiling ArrayListDemo.java, the above error message keeps appearing. Both files are saved in the same folder. In addition to that error, this is the message retrieved from the trace stack:

    Java Code:
     C:\tomcat\webapps\begjsp-ch08\WEB-INF\classes>java ArrayListDemo
    Exception in thread "main" java.lang.NoClassDefFoundError: ArrayListDemo
    Caused by: java.lang.ClassNotFoundException: ArrayListDemo
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Could not find the main class: ArrayListDemo.  Program will exit.

    Please find attached the two classes and the command prompt error message.

    Thanks in advance for your help. It is greatly appreciated.
    Attached Thumbnails Attached Thumbnails Unchecked or Unsafe Operations Error Message-unchecked-unsafe-operation-recompile-xlint.jpg  
    Attached Files Attached Files
    Last edited by littleone; 10-29-2010 at 04:37 PM. Reason: [SOLVED]

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Inside ArrayListDemo you have

    Java Code:
    ArrayList userlist = new ArrayList();
    This could be causing the unchecked problems.

    add this on top of static void main()

    Java Code:
    @SuppressWarnings("unchecked")
    There are other ways around this but I will leave you investigate a bit

  3. #3
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    al_Marshy_1981,

    The code that you provided me allowed for the class to compile. However, it is still indicating that it can not find the class.

    Please see attached jpg.

    Still cannot understand why it can not find the class. I am compiling the files in the right folders. In other words, is the structure of the folder appropriate.
    Attached Thumbnails Attached Thumbnails Unchecked or Unsafe Operations Error Message-cannot-find-main-class-noclassdeffounderror.jpg  

  4. #4
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Here is copy of my folder structure and where I saved the java class.

    Should I be compiling in a different folder since their is a main class? Just asking because I have never compiled a file with main method before from the command prompt.
    Attached Thumbnails Attached Thumbnails Unchecked or Unsafe Operations Error Message-folder-structure-location-java-classes.jpg  

  5. #5
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    You are not running ArrayListDemo inside the Utilities folder, try

    C:\tomcat\webapps\begjsp-ch08\WEB-INF\classes\com\wrox\utilities\java ArrayListDemo

  6. #6
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Hey,

    I tried to run the ArrayListDemo from inside the utilities folder and I still did not have any success.

    Please see a screenshot of Command Prompt.

    What could possible be the problem?
    Attached Thumbnails Attached Thumbnails Unchecked or Unsafe Operations Error Message-running-inside-utilities-folder.jpg  

  7. #7
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    Maybe you could leave out the package declaration all together? The demo isn't about packages but about the ArrayList right?

    So, remove the lines package com.wrox.utilities from both files, add al marshy's SuppressWarning line, move both files to your classes folder.

    Recompile both files and run ArrayListDemo.

    Worked on my machine.

    Cheers,
    Erik

  8. #8
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    venerik,

    If this worked on your machine, then something is wrong with my configuration somewhere.

    Compiling the ArrayListDemo.java file as been solved. I used the

    Java Code:
    @SuppressWarnings("unchecked")
    I will closed this out.
    Last edited by littleone; 10-29-2010 at 04:13 PM.

  9. #9
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Don't use .java on the file you want to execute

  10. #10
    bonthala007 is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

Similar Threads

  1. Compile error - unchecked
    By pahiker in forum New To Java
    Replies: 18
    Last Post: 06-24-2010, 10:27 AM
  2. unchecked or unsafe operations-Recompile with -Xlint
    By pronetin in forum Advanced Java
    Replies: 15
    Last Post: 05-31-2010, 06:41 PM
  3. Unchecked or unsafe operations warning
    By sky in forum New To Java
    Replies: 3
    Last Post: 12-06-2009, 04:41 AM
  4. Replies: 22
    Last Post: 05-08-2008, 01:00 PM
  5. Uses unchecked or unsafe operations message
    By Robbinz in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 11:56 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
  •