java Compilation

Ads
 

java Compilation

import java .util.*; class ArrayListDemo { public static void main(String[] args) { ArrayList l=new ArrayList(); l.add("A"); l.add(10); l.add(null); System.out.println(l); l.remove(2); System.out.println(l); l.add(2,"M"); l.add("N"); System.out.println(l); } }

in the above java program compilation time following error is occur in my system

Note: ArrayListDemo.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

so plz send me answer why this error is coming............ and what is the reason and solution ....

View Answers

July 30, 2012 at 10:19 AM

This comes up in Java 5 and later if you're using collections without type specifiers (e.g., Arraylist() instead of ArrayList<Object>()). It means that the compiler can't check that you're using the collection in a type-safe way, using generics.

To avoid this error, specify the type of object you're storing in the collection. So, specify the type as the following:

ArrayList<Object> l= new ArrayList<Object>();

In your code, you have added integer as well as string values to list therefore you need to use Object. Otherwise, whatever values you added, specify the type specifier.

Ads









Related Tutorials/Questions & Answers:
java Compilation
java program compilation time following error is occur in my system Note...java Compilation  import java .util.*; class ArrayListDemo... in Java 5 and later if you're using collections without type specifiers (e.g.
java Compilation
java program compilation time following error is occur in my system Note...java Compilation  import java .util.*; class ArrayListDemo... in Java 5 and later if you're using collections without type specifiers (e.g.
Advertisements
java Compilation
java program compilation time following error is occur in my system Note...java Compilation  import java .util.*; class ArrayListDemo... in Java 5 and later if you're using collections without type specifiers (e.g.
Java compilation error - Java Beginners
Java compilation error  Method overridden problems in compile time error
java compilation error - Hibernate
java compilation error  hi, i have made an registration page whosevalues should be inserted into database. i have used hibernate and eclipse it is working fine. but when i make a war file and deploy it using ant and then run
Java Compilation - Java Beginners
Java Compilation  How would i write a complete java program which, using a do-while loop, reads integers from the keyboard and sums them until the sum hits or exceeds 30. Then print out the sum. is it like this: import
Java Compilation - Java Beginners
Java Compilation  I want to write a complete java program that catenates the file named "first" with the named "second" and produces a file named "third". If either input file "first" or "second" does not exist in the current
Java Compilation - Java Beginners
Java Compilation  I want to write a Java program that asks the user for the names of 3 files. I want the first file to be opened for reading and the other two files to be opened for writing. I want the program to read
compilation error - Java Beginners
compilation error  class s { public static... is the reason?  Hi Friend, In Java there are some specific literal... not in the Hexadecimal or Octal. Here is fraction of Java code example which will help you
java compilation error - Java Beginners
java compilation error  i have downloaded java software(version 6... from where i should download java or what to do now?  Have you set the java_home and path in your environmental variables in "My Computer
Java Compilation error. Hibernate code problem. Struts first example - Hibernate
Java Compilation error. Hibernate code problem. Struts first example  Java Compilation error. Hibernate code problem. Struts first example
Does the object type known during compilation in Java?.
Does the object type known during compilation in Java?.  class A { } class B extends class A { } class checkType { public static void main(String[] args) { A ObjA = new B();/// Here ObjA is of type A--> this fact
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot exist ( though i imported it) & cant recognise SUCCESS etc symbol.i think i
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot exist ( though i imported it) & cant recognise SUCCESS etc symbol.i think i
compilation fail
compilation fail  package jsptube.tutorials.servletexample; import javax.servlet.GenericServlet; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import java.io.IOException; import
compilation errors
compilation errors  package jsptube.tutorials.servletexample; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import
compilation error
compilation error  Hi my program below is not compiling,when I try to compile it i'm getting the error message "tool completed with exit code 1".The loop has to be at the end of the program can you help me. Blockquoteimport
command prompt is compilation is not working
command prompt is compilation is not working   Dear java users can anyone help me to run the program in command line prompt i tried by selecting... and the class file is also getting generated when i run the class file using java
result after compilation
c file compilation
program created and compilation error of connection rightly created n tested
program created and compilation error of connection rightly created n tested  // I have made connection as the data source dsn2 and i have also created table named Tab1 in SQL server 2008..it is compiled correctly but is giving
Java
Java  What is a compilation unit
java & c
java & c  why c language is called top down approach? why java is called bottom to top approach?   In C, compilation stats from the very top of the program code. In Java, on the other hand, we have user defined data
Hibernate Configuration
org.hibernate.SessionFactory . Various XML mapping files or Java Annotations compilation build...The configuration of Hibernate is handled by the instance of org.hibernate.cfg.Configuration . It symbolizes the complete mapping between Java data types
java fundamental question related to string
java fundamental question related to string  public class Myclass...??); } } Output? a) the pgm will throw ClassCastException b) compilation fails since s==sb illegal c) compilation fails since s.equals(sb) illegal d
java
java  diff bt core java and java
java
java  what is java
java
java  after compilation of program files ,following error messages were showen on command prompt.identify the causes for those specific errors. i)testing.java:8:package system does not exist. System.out.println("No of items
java
java  after compilation of progra files, following error messages were shown on command prompt.identify the causes for those specific errors. i) System.out.println("No of items:"tooa1Item); ^ 1 error ii
JAVA
JAVA  how the name came for java language as "JAVA
java
java   why iterator in java if we for loop

Ads