classcastexception

JDK8 type inference issue

浪尽此生 提交于 2019-12-05 17:10:32
I'm trying to run the following code which is compiled fine under JDK8 thanks to type inference: public static <A,B> B convert(A a) { return (B) new CB(); } public static void main(String[] args) { CA a = new CA(); CB b = convert(a); //this runs fine List<CB> bl = Arrays.asList(b); //this also runs fine List<CB> bl1 = Arrays.asList(convert(a)); //ClassCastException here } However, running this throws ClassCastException: CB cannot be cast to [Ljava.lang.Object, but the CB b = convert(a) works fine. Any idea why? Holger Whenever you create a generic method with a signature that promises to

Oracle JDBC driver conflict

怎甘沉沦 提交于 2019-12-05 13:32:21
JBoss EAP 6.1 standlone server Application deployed as a war file throws a runtime exception java.lang.ClassCastException: oracle.sql.ARRAY cannot be cast to oracle.sql.ARRAY at line oracle.sql.ARRAY obj = (oracle.sql.ARRAY) rs.getObject("RATINGOBJ"); JDBC libary included is ojdbc6.jar (WEB_INF/lib). All libraries are included in the war file and there are no "global" libaries setup on the server. I have verified no other jdbc libraries are included anywhere in the app. In order to create a JDBC datasource, i created a deployment for ojdbc6.jar. This is the only possible source of conflict i

extending superclass and ClassCastException

喜欢而已 提交于 2019-12-05 12:25:28
I have a superclass, which two methods i want to override. Here's my code: public class MyCustomClass extends SomeSuperClass { protected MyCustomClass(params) { super(params); } @Override public void method1() { super.method1(); /* here goes my code */ } @Override public void method2() { super.method2(); /* here goes my another code */ } I have some constructor, that passes SomeSuperClass object as a parameter, and what i do next: MyCustomClass object; /* now i have object of type SomeSuperClass, but with my own method1() and method2() */ object = (MyCustomClass) MyCustomClass.item(blahblah);

Redis操作异常: java.lang.ClassCastException: java.lang.Long cannot be cast to [B

懵懂的女人 提交于 2019-12-05 08:54:02
背景描述: (1) 某项目,使用redis做存储,用redis的set性质来做实时统计,同时也存放其他统计数据; (2) 用到的key不少,value集合量较多; (3) 每天零点的时候,回清理当前redis中所有的数据; (4) 异常都出现在 零点清理之后; 异常现场: 2018/03/13 00:00:20 OSS INFO [com.xxx.RedisDAO] - error redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202) at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40) at redis.clients.jedis.Protocol.process(Protocol.java:151) at redis.clients.jedis.Protocol.read(Protocol.java:215) at redis.clients.jedis.Connection

Java: Unchecked cast from X to Y / how to implement castOrNull

强颜欢笑 提交于 2019-12-05 07:06:49
I have implemented this function: static <X,Y> Y castOrNull(X obj) { try { return (Y)obj; } catch(ClassCastException e) { return null; } } This gives me the compiler warning: Type safety: Unchecked cast from X to Y Which I don't exactly understand. Isn't the try/catch which I am doing here a check for it? Can I ignore the warning? Will my function work as expected or not? How would I implement it correctly? I also tried with a obj instanceof Y check but that doesn't work because of the way Java handle generics. Btw., this function seems quite useful to me (to make some other code more clean).

SEVERE: Exception springSecurityFilterChain… ClassCastException… DelegatingFilterProxy cannot be cast

自作多情 提交于 2019-12-05 06:49:33
can anyone help me resolve my tomcat run error, I get the following error when i run tomcat: SEVERE: Exception starting filter springSecurityFilterChain java.lang.ClassCastException: org.springframework.web.filter.DelegatingFilterProxy cannot be cast to javax.servlet.Filter at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275) at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115) at org.apache.catalina.core

If A extends B extends C, why can I cast to A but get a ClassCastException casting to C?

▼魔方 西西 提交于 2019-12-05 05:17:55
I am trying to read an ASN1 object using Bouncycastle on Android. I expect it to be a DERSequence, which in Bouncycastle is a subclass of ASN1Sequence, which is a subclass of ASN1Object. import org.bouncycastle.asn1.ASN1InputStream; import org.bouncycastle.asn1.ASN1Object; import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.DERSequence; ... ASN1InputStream ais = ...; Object o = ais.readObject(); // Eclipse's debugger now says o is a DERSequence, as expected. DERSequence o2 = (DERSequence)o; ASN1Sequence o3 = o2; ASN1Object o4 = o3; // And o4 is now exactly what I want.

java.lang.ClassCastException while running new `runnableThread` in `Service` Class

主宰稳场 提交于 2019-12-04 19:15:48
I have an application , contains a broadcastReceiver which listens to all new received SMS . If any new SMS received this BroadcastReceiver starts a background Service which runs GPS and return the coordinates , this coordinate retrieving needs a new thread to be run , in the Service class there is no getApplicationContext() so I used 'getContentBase()' for starting the new thread this is the code ((Activity)getBaseContext()).runOnUiThread(new Runnable() { ((Activity)getBaseContext()).runOnUiThread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub

Cast List<Object[]> to Object[][] in Java

拜拜、爱过 提交于 2019-12-04 14:05:52
How to turn List of arrays into two dimensional array in Java? //Prepare the list List<Object[]> conf = new LinkedList<Object[]>(); conf.add(new Object[]{ "FOO", "BAR"}); conf.add(new Object[]{ "FOO", "BAR"}); I tried: Object[][] array = (Object[][]) conf.toArray(new Object[0]); But it fails at ClassCastException : java.lang.RuntimeException: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [[Ljava.lang.Object; You are missing a pair of square brackets: Object[][] array = conf.toArray(new Object[0][]); ^^ Or, if you wish to save on one unnecessary memory allocation: Object[]

Eclipse ClassCastException when trying to expand XML layout for Android

别等时光非礼了梦想. 提交于 2019-12-04 10:29:06
I am new to java, eclipse, and android development, so I may be missing something simple although I have checked basic stuff like spelling several times. Because there is no number picker control (such as that used in the date picker) in the public Android SDK, the conventional wisdom is to "clone and own" the control that exists in the Android source. In an attempt to do that, I have copied the code for NumberPicker into my project and its dependency, NumberPickerButton. I have also copied the supporting resources. The problem I am having is that when I try to include the NumberPicker in a