Home Answers Viewqa Java-Beginners try to execute this code getting class cast exception, please resolve it.

 
 


pavans
try to execute this code getting class cast exception, please resolve it.
0 Answer(s)      a year and 5 months ago
Posted in : Java Beginners

package test;

import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set;

public class Over { static int k[] = new int[5];

public static void main(String... ab) {
    int aa[] = new int[] { 2, 1, 2, 3 };
    int b[] = Over.removeDuplicates(aa);
    for (int ac = 0; ac < b.length; ac++) {
        System.out.println(b[ac]);
    }
}

public static int[] removeDuplicates(int[] a) {

    /*
     Please implement this method to
     remove all duplicates from the original array. Retain the order of the elements and
     always retain the first occurrence of the duplicate elements.
     For example, parameter: {2,1,2,3}, result: {2,1,3}
     */

    List list = Arrays.asList(a);
    System.out.println(list);
    Set<Integer> set = new HashSet<Integer>(list);
    Object obj[] = set.toArray();
    Integer o[] = new Integer[obj.length];
    for (int i = 0; i < obj.length; i++) {
        o[i] = (Integer) obj[i];
    }
    for (int i = 0; i < o.length; i++) {
        k[i] = o[i].intValue();
    }
    return k;

}

}

View Answers









Related Pages:
try to execute this code getting class cast exception, please resolve it.
try to execute this code getting class cast exception, please resolve it. ... java.util.List; import java.util.Set; public class Over { static int k... int[] removeDuplicates(int[] a) { /* Please implement this method
class cast Exception - Development process
class cast Exception  hi deepak this sampath,am facing the problem with printer connection with java application. Every time am getting the class cast exception and iam sending the code please check this and correct me
Getting Exception on UseDefinedException sample program - Please help me how to resolve
Getting Exception on UseDefinedException sample program - Please help me how to resolve  class UseDefinedException extends Exception{ String msg...); } } } Hi, I tried above code but getting Exception : MyException cannot
Class Cast & illegal state Exception in blackberry
Class Cast & illegal state Exception in blackberry  tell me please i m facing class cast exception. when i click on Maps & iGoogle in Google Homepage on my emulator then it gives class cast & Illegal State exception
Getting an exception - JSP-Servlet
Getting an exception   sir i am Getting following exception when... running it will throwing an exception please help me sir thanks.../apache/poi/poifs/filesystem/POIFSFileSystem I have used ur code import
Getting an exception - JSP-Servlet
exception please help me sir if an changes tel me sir thanks in advance..., Try the following code: 1)excel.jsp: Enter XLS file name...Getting an exception  sir i changed to that ie InputStream myInput1
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it  while running my...;<td class="s2">ZIP Code:</td> <td class="s3"><input...; <tr align="center"> <div class="ab"> <td> <a href="E
how to resolve this JDBC Error?
but when i am executing this code i am getting this Error: Exception in thread...how to resolve this JDBC Error?  i am trying to Exceute this code... java.sql.DriverManager; import java.sql.SQLException; public class ConnectionDemo
Nested try
Nested try  Each time when i execute this code in eclipse i get different answers pl help me with this code class Demo { static void nestedTry... is converted to int and gives 1. java Demo 2 0, it will give exception, the try
org.apache.struts.action.ActionMessage cannot be cast to org.apache.struts.action.ActionError - Struts
org.apache.struts.action.ActionMessage cannot be cast... write validation code(validation.xml) for that application,form submit without... - -------------------------------------------------------------------------------- type Exception
How to resolve NumberFormatException(Unlnown Source)?
How to resolve NumberFormatException(Unlnown Source)?  I'm using some code where I'm getting NumberFormatException in the code but logically it seem... the exception. Code i'm is some thing like that:`print("<% String t
Nested try
Nested try  Hi, In eclipse without providing input i am getting different outputs ie my exception gets executed first then finally block and vice versa.pl explain me class Demo { static void nestedTry(String args[]) { try
try catch
try catch  why following code gives compile time error.please reply. class ThreadDemo1 extends Thread { public void run() { for(int i=1;i<=3;i++) { System.out.println(i); try
error occured in following page ... how to resolve it?
error occured in following page ... how to resolve it?  // to convert image into thumbnail i used following code. But netbeans has given me following....... error is:::: Exception in thread "main" java.lang.IllegalArgumentException
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it
Resolve it   I have tried the following code Database creation... this code on tomcat server i caught with following exception after clicking...!!!!! Please Resolve it , thanks in advance  Please visit the following
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it   I have tried the following code Database creation... what was wrong!!!!! Please Resolve it , thanks in advance  
Getting an exception - JSP-Servlet
Getting an exception  Dear sir,while executing this code i am getting a following error ,i am sending my code also please help me sir... //following is a code int a = 0, b = 1, c = 2, d = 3, e = 4,f=0; //int a, b, c, d, e
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me if any changes in code . thanks in advance.. java.io.IOException: Invalid
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me if any changes in code . thanks in advance.. java.io.IOException: Invalid
Getting Exception
Getting Exception  How to get exception from commented code in java
Try and catch in Exception Handling.
Try and catch in Exception Handling.  How can we use try and catch...; try{ x=a/b; }catch (Exception er.... Then to perform exception handling, we have used try and catch block where we have
ajax code please help to solve this........
ajax code please help to solve this.  in this i am trying to get data.../javascript"> var ob; function fun(str) { try...) { try { ob=new ActiveXObject
exception
exception  example for numberformat exception   Hi Friend, Try the following code: class NumberFormatExceptionEx{ public static void main(String[] args) { try{ String st="Rose India
Exception
Exception  public class FooException extends Exception { public..."); } public void calculate() throws FooException, Exception { try { int... help me.   public class FooException extends Exception { public
exception
Try this: import java.sql.*; class InsertData{ public static void main...exception  Identify the reason for SQLException exception, which is encountered when the developer tries to run the following code snippet to insert
could not execute native bulk manipulation query
could not execute native bulk manipulation query  I am insert data in mysql through struts hibernate integration. But above error is coming. Please help me I am sending our Insert Class coding My Insert class coding package
Getting NumberFormatException
it in a JSP it continuously throws the exception. below is the code I used. Please...Getting NumberFormatException  Hello Sir, I'm using Integer.parseInt... also used Integer.parseInt(String str, int radix) but it also throws the exception
UIButton sender type cast
into UIButton. Please provide me code. Thanks   HI, Its very easy to typecast the sender object into UIButton. Please see the following code: UIButton... to typecast the sender object into UIButton. Please see the following code: UIButton
Exception
as if it were an array. * Throwing null value. In the following code if you try...: class HelloWorld { public static void main(String[] args
How to resolve this error The filename, directory name, or volume label syntax is incorrect
How to resolve this error The filename, directory name, or volume label syntax... + createTimeStampStr() + ".PNG"; this my program public class Image... fileLocation, String extension) { try { BufferedImage bi = img; File outputfile = new
JDBC Execute Statement
a database. In this Tutorial, the code illustrates an example from JDBC Execute... in the database of your backend. The code include a class JdbcExecuteStatement.The... of database. If there exists an exception in try block, the catch block
Getting error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. The following is the code of connection. Please suggest the solution or give sample code of mysql connection. Your inputs are very...Getting error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. 
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it  while running my...; <tr align="center"> <div class="ab"> <td> <a href="E:\JE...; <tr></tr> <tr></tr> </table> <h1 class="s1
Exception Handling with and without using try catch block
to explicitly make try catch block then to you program write throws Exception to your method where Exception handling is required  Codeclass... is by using try catch block shown in following code sample:  class
getting classnotfound exception while running login application
getting classnotfound exception while running login application  hi, I am getting Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference
could anyone please help with the code.
could anyone please help with the code.  protected void doPost...(request, response); } } could anyone please check the code. If i enter... the details to the bean class */ userLogin_bean obj=new userLogin_bean
JDBC Execute Query
want to describe you a code that helps you to understand JDBC Execute Query... driver  in the try block. The catch block check the exception and println print... JDBC Execute Query       The 
try Java Keyword
: -- The try keyword in java programming language is used to wrap the code in a block... of  an exception object. -- Every try block in java programming language must... mechanism, if an exception class is not handled by any catch block
Getting an exception - JSP-Servlet
Getting an exception  Dear Sir , While sending a mail am getting an following exception javax.mail.MessagingException: 554 mail server permanently rejected message (#5. 3.0)so how to over come from this please help
JDBC Execute Update Example
to describe you a code that helps you in understanding JDBC Execute update Example. For this we have a class JDBC Execute update, Inside this class we have a main... ( ) : This method return you a connection class object. This try to built
different output trying to execute same java code
different output trying to execute same java code  i am using net... javax.comm.*; public class SimpleRead implements Runnable, SerialPortEventListener... = new SimpleRead(); } } } } public SimpleRead() { try
different output trying to execute same java code
different output trying to execute same java code  i am using net... javax.comm.*; public class SimpleRead implements Runnable, SerialPortEventListener... = new SimpleRead(); } } } } public SimpleRead() { try
different output trying to execute same java code
there is different output trying to execute same java code...different output trying to execute same java code  i am using net... javax.comm.*; public class SimpleRead implements Runnable, SerialPortEventListener
Getting an exception - JSP-Servlet
Getting an exception  thanks sir for u r reply ,but i already added that jar file sir even though i m getting an exception sir please help me sir ... thanks in advance..  Hi Friend, You can do one thing, replace
Exception in thread "main" java.lang.ClassCastException
to connect the database. I am stuck with this exception that is getting thrown. Anyone help me please. Java Code: import java.sql.*; import org.postgis....) { sqle.printStackTrace(); } finally { try {stmt.close();} catch (Exception e
Exception in thread "main" java.lang.ClassCastException
to connect the database. I am stuck with this exception that is getting thrown. Anyone help me please. Java Code: import java.sql.; import org.postgis....) { sqle.printStackTrace(); } finally { try {stmt.close();} catch (Exception e
Getting an exception - JSP-Servlet
Getting an exception  sir i m Getting an following exception while... sending message; nested exception is: java.io.FileNotFoundException... (); try{ Properties props = System.getProperties(); if (host != null
my hibernate showing the following exception so how i can resolve it
my hibernate showing the following exception so how i can resolve it   Caused by: java.lang.ClassNotFoundException: org.hibernate.Session...) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class
exception - MobileApplications
exception  Hi friend, again i am getting exception.Entire code... class ImageItemMIDlet extends MIDlet implements CommandListener{ private... Display display; private Form form; public ImageItemMIDlet(){ try
Please help with this code
Please help with this code  I need some help getting the Search method below to work with the menu, and I also cannot figure out how to get my bubble... at this point! :( import java.util.*; public class StudentProcessor2