FAQ Database Discussion Community


Class Cast Exception starting on a certain KeyEvent

java,debugging,classcastexception
Still improving on the same game as one of my older questions, only this time I now have four classes and another exception error. Still same "Java is 2nd language, still can't seem to prove my intermediate C++ sticker." Briefer: Making game in span of 2-2.5 years, have to do...

JdbcTemplate Mockito ClassCastException

spring,mockito,classcastexception
I am trying to mock a method of the Spring framework's JdbcTemplate class. The method has the following signature: public <T> T queryForObject(String sql, Class<T> requiredType) throws DataAccessException {...} The mocking is being done as mentioned below: when(jdbcTemplate.queryForObject(anyString(), eq(String.class))).thenReturn("data"); However, this call throws the following exception java.lang.ClassCastException:...

on Map causes ClassCastException on java.lang.String

jsf,jsf-2,hashmap,el,classcastexception
private Map<Linha, Long> mapLinhas = new HashMap<Linha, Long>(); for (final Linha linha : this.mapLinhas.keySet()) { final Long idLinha = this.mapLinhas.get(linha); final Unidade b = Cache.getInstance().getUnidade(a); linha.setUnidade(b); } The map values are of Long type, but when I assign it to another Long variable it throws the following exception: 02/02/2015...

java.lang.ClassCastException: - Arrays.asList()

java,arrays,collections,classcastexception
Exception in thread "main" java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList at BinarySearch.main(BinarySearch.java:14) below is my code- import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Scanner; public class BinarySearch{ public static void main(String s[]) throws InterruptedException{ int result=-1; Integer[] array ={34,67,12,32,07,11,25} ; ArrayList<Integer> list=new ArrayList<Integer>();...

ClassCastException even after providing casting class [duplicate]

java,jpa,classcastexception
This question already has an answer here: why simple select query returns List<Mymodel> but join query return List<Object> in jpa 3 answers I have the following code snippet, when I execute, I am getting java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to test.hr.Employee Code: Query query = getEntityManager().createNamedQuery("Employee.findEmployees"); List<Employee> result =...

HtmlUnit Page response (Downloading File)

java,json,htmlunit,classcastexception
So im trying to use HtmlUnit to go to a URL but once you visit that url it downloads a json file regarding the data you want. Not sure how to word this but basically in HtmlUnit how can I get the result from a downloaded file. I suck at...

ClassCastException when casting Object[] array to generic type array in Java

java,classcastexception
Hi I'm very new to Java and in this code, I think I'm not creating the Bag correctly in the Main? Please help thanks! Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Comparable; at mid.Bag.(Bag.java:12) at mid.Bag.main(Bag.java:91) public class Bag<T extends Comparable<T>> implements Iterable<T> { private int MAX_ITEMS...

Programatcally remove margin from FrameLayout with LayoutParams

android,relativelayout,classcastexception,framelayout
I have a FrameLayout that looks like this: <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <FrameLayout android:layout_marginTop="56dp" android:layout_marginBottom="50dp" android:id="@+id/main_frag" android:layout_width="match_parent" android:layout_height="match_parent" /> // other stuff </RelativeLayout> However when I change the margins programitcally I get a ClassCastException. FrameLayout fl = (FrameLayout) findViewById(R.id.main_frag); FrameLayout.LayoutParams params =...

Getting Integer value from JComboBox in java

java,swing,integer,jcombobox,classcastexception
I am using JComboBox to give Integer value as input.Tell me which fuction i can use to get the value from combobox. My combox will have these values. cb1=new JComboBox(); for(int i=1;i<=31;i++) { if(i<10) { cb1.addItem("0"+i); } else { cb1.addItem(i); } } I used this function to get the value....

Hazelcast - Jacache cacheManager.getCache returning null - Throwning ClassCastException

java,classcastexception,hazelcast,jcache
I am using Jache and Hazelcast as the implenentation in my web application, when I am deploying my application on tomcat I have a context listener which calls CacheManager and loads some data, Now when it tries to get the Cache from CacheManager with specified (cacheName, Class, Class) it returns...

GenericApplicationContext cannot be cast to WebApplicationContext : Spring Web Flow

java,spring,spring-mvc,classcastexception,spring-webflow-2
I'm trying to set up Spring Web Flow using only Java annotations in a Spring environment that also uses only Java annotations. However when I attempt to access my flow I get the following exception SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/forms] threw exception [Request processing failed;...

How do I refactor findViewById without class cast exception?

android,classcastexception,findviewbyid
Usually when I have many elements in my android app, onCreate looks like this: onCreate(){ ImageButton b1 = (ImageButton)findViewById(R.id.b1) ; ImageButton b2 = (ImageButton)findViewById(R.id.b2) ; ImageVuew v3 = (ImageButton)findViewById(R.id.v3) ; ViewSwitcher v4 = (ViewSwitcher)findViewbyId(R.id.v4) ; TextView v5 = (TextView)findViewById(R.id.v5) ; //and so on } Android requires to do this class...

ClassCastException when asInstanceOf in for comprehension

scala,playframework,classcastexception,for-comprehension
In PlayFramework 2.4 I try to transform all controllers methods into JavaScript routes. val jsRoutesClass = classOf[routes.javascript] val controllers = jsRoutesClass.getFields.map(_.get(null)) for ( controller <- controllers; method <- controller.getClass.getDeclaredMethods ) yield method.invoke(controller).asInstanceOf[JavaScriptReverseRoute] But the following error occur: Error injecting constructor, java.lang.ClassCastException: java.lang.String cannot be cast to play.api.routing.JavaScriptReverseRoute at...

Validator in composite throws ClassCastException when using java.lang.Double value

validation,jsf,double,classcastexception,composite-component
I had a two field validator working without the composite as follows public class DoubleMustBeGreaterThanSecondDouble implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { Double firstDouble = (Double) value; Double secondDouble = (Double) component.getAttributes().get("secondDouble"); if (firstDouble <= secondDouble) { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,...

How to fix ClassCastException in enhanced for-loop? [closed]

java,arraylist,foreach,classcastexception
List<Object[]> listOfObjectArray = new ArrayList<Object[]>(); // List of object arrays, where each element is an array. .... listOfObjectArray = ##Somerecords; (Eg : [12.0,13.0,14.0,15.0....]) ... for(Object[] obj : listOfObjectArray) {...} Here if the length of array in the list is 1, I am getting ClassCastException. How to fix this?...

No compiler error about incompatible casts

java,generics,java-7,classcastexception
Sorry if this was already explained, but i didn't find similar threads anywhere in web. Today I opened one project class in IDE and saw an error (red underline), though project was compiled successfully. So, the code is: public interface DatasourceImplementation<T extends Entity> { .... } public interface Datasource<T extends...

Java ClassCastException

java,classcastexception
Hi I'm very new to Java and have this problem with building a DoublyLinkedList. I'm getting this error when running the test program. Can anyone advice any fix on my code? Any help is greatly appreciated! Error message: Exception in thread "main" java.lang.ClassCastException: hw3.Deque$Node cannot be cast to java.lang.Integer @SuppressWarnings("unchecked")...

java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.support.v4.app.Fragment

android-fragments,tabs,classcastexception,fragmentpageradapter,pagerslidingtabstrip
I get this error java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.support.v4.app.Fragment when I try to open my activity CuteCollection.java in my app. The strange part is that when I click on the first line (FragmentPagerAdapter.java:122) in the logcat error, it shows me a line from a file in the v4.support...

[D cannot be cast to java.lang.Double

java,arraylist,classcastexception
I wrote below code. It get this message: Exception in thread "main" java.lang.ClassCastException: [D cannot be cast to java.lang.Double double[] xyz = {1, 11, 111, 2, 22, 222}; ArrayList array = new ArrayList(); array.add(xyz); double[] vals = new double[array.size()]; vals[0] = (double) array.get(0); vals[1] = (double) array.get(1); vals[2] = (double)...

Swift class cast fails while casting AnyObject to NSMutableDictionary

class,swift,nsmutablearray,classcastexception
var fetchEachStory = Firebase(url: "\(self.individualStoryUrl)\(eachStory)") // Read data and react to changes fetchEachStory.observeEventType(.Value) { snapshot in let storyDetails = snapshot.value as NSMutableDictionary? let score = storyDetails!["score"] as Int? var thisStory = eachStory if score? > self.minSetScore { self.showStories[thisStory] = storyDetails } } While Assigning Snapshot.value to story details, it fails...

MergeAdapter ClassCastException only w/ Genymotion

android,android-layout,classcastexception,genymotion,commonsware-cwac
I am getting a class cast exception that only occurs when I am using genymotion. Whenever I try this on a real device I do not have an issue. Stacktrace: 5-11 19:05:10.217 1278-1278/com.vast.homestory.betadebug E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams at android.widget.ListView.setupChild(ListView.java:1874) at android.widget.ListView.makeAndAddView(ListView.java:1843) at...

class cast exception in hibernate

java,hibernate,classcastexception
Test.java public static void main(String[] args) { System.out.println("Enter reporting manager empid"); Scanner sc = new Scanner(System.in); Integer in = sc.nextInt(); Session session=new AnnotationConfiguration().configure().buildSessionFactory().openSession(); Query query=session.createQuery("select count(*)from MisRecords where empReportingManagerId=:i"); query.setParameter("i", in); List<MisRecords> list=query.list();{ for(MisRecords employee:list){ // System.out.println(employee.getFirstName()); //...

Unable to use DefaultTableModel in JTable

java,swing,jtable,classcastexception,defaulttablemodel
Object rowData[][] = { {1, "", null, "", "", false, ""}, {2, "", null, "", "", false, ""}, {3, "", null, "", "", false, ""}, {4, "", null, "", "", false, ""}, {5, "", null, "", "", false, ""}, {6, "", null, "", "", false, ""} }; DefaultTableModel model =...

Clojure reduce unable to cast Long to IFn

clojure,classcastexception
This weekend I decided to learn clojure. I am stuck with reduce.I get a class cast exception for (reduce #((cond (= %1 0) %2 :else %1)) 0 '(1 1 1)) ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn user/eval2092/fn--2093 (form-init1869535703328200664.clj:1) I am not sure what exactly am I doing wrong. Any...

ClassCast Exception Error

android,bluetooth-lowenergy,classcastexception,android-bluetooth
When I am trying to use Application object for maintain bluetooth service in whole android app, My application throw me Classcast Exception. When I am trying to connect bluetooth Peripheral. 04-27 09:11:37.704 3289-3289/com.xemodex.bluetooth.xemodex E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.xemodex.bluetooth.xemodex, PID: 3289 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xemodex.bluetooth.xemodex/com.xemodex.bluetooth.xemodex.DeviceControlActivity}: java.lang.ClassCastException: android.app.Application...

Class cast exception to same class on Android

android,classcastexception,findviewbyid
I'm having a strange problem with ClassCastException on Android. One class cannot be casted to the same class: java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.ClassCastException: com.example.model.BadeWrapper cannot be cast to com.example.model.BadgeWrapper java.lang.ClassCastException: com.example.events.widgets.TouchyWebView cannot be cast to com.example.events.widgets.TouchyWebView java.lang.ClassCastException: com.example.friends.widgets.FriendsTabView cannot be cast to...

Cast exception with android drawers

java,android,classcastexception
Ave, i'm learning Android Drawers from: "http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/" and i encountered a weird problem. When application start it throws: 05-13 12:50:08.325 2030-2030/? E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.lanceit.haito.lanceit, PID: 2030 java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:1100) at...

ClassCastException: Class implementing the interface, still getting classcast

java,android,classcastexception
I have a class which is implementing an interface with generics. class MainClass { interface MyInterface <T extends MyInterface.A> { static class A { } } } //I have another class which implements this interface: class ImplementingClass implements MyInterface<A> { } //I am loading MyInterface class from a jar in...

Getting java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams

android,android-layout,android-contentprovider,classcastexception,android-relativelayout
Here I need to add textview at runtime. first I took reference of RelativeLayout to get layout params but unfortunately its throwing ClassCastException at RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams)contentLayout.getLayoutParams() I also checked - FrameLayout to RelativeLayout ClassCastException even if there is no FrameLayout used, but it didn't work. Since after replacing...

How to fix: java.lang.ClassCastException: java.util.ArrayList cannot be cast to double[]

java,android,generics,classcastexception
I encountered a problem when I tried to run the following code: When I trying to get item from ArrayList<double[]> list but it throws ClassCastException Method list.get(i) also throws excexption public void drawRoutes(ArrayList<String> routes) { if (routes.isEmpty()) return; for (int i = 0; i < routes.size(); i++) { PolylineOptions polylineOptions...

How to fetch data from a custom list view with multiple radio buttons

android,eclipse,android-layout,classcastexception
I have gone through a lot of links here, but yet i was not able to get my stuff working. Can you please help me fetch data from my custom list. Details are as under :- My custom list view <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RadioGroup...

ClassCastException when iterating over HashSet

java,set,hashset,classcastexception
I have a HashSet<String> that's filled with strings called shingles (if you take the string "Fizzbuzz" and break it into shingles, you'd get "Fi", "iz", "zz", "zb", "bu", "uz", "zz". Not important, but that's what a shingle is in this context). I'm trying to return a string of the HashSet's...

Wildfly 8 - Multiple EAR - ClassCastException

jpa,jboss,classpath,classcastexception,wildfly-8
I've been trying to fix an issue for some time now. I have two EAR files being deployed to Wildfly 8.1.0 with the same EJB.jar and the same JPA.jar, but with seperate EJB.jars for 'Scheduling' A.K.A running the different functions within the EJBs. The schedulers access the EJB.jars which in...