classcastexception

ClassCastException vs. “cannot cast” compilation error

↘锁芯ラ 提交于 2019-12-01 02:40:56
Studying for my OCA Java SE 7 Programmer I exam, so newbie question. I have an example question I do not understand. The following code compiles, but gives a ClassCastException at runtime: interface Roamable { } class Phone { } public class Tablet extends Phone implements Roamable { public static void main(String... args) { Roamable var = (Roamable) new Phone(); } } When I change Roamable var = (Roamable) new Phone(); into Roamable var = (Roamable) new String(); I get a compilation error right away. Two questions: Why does the code above compile at all? Phone seems unrelated to Roamable to me?

Fragment cannot be cast to android.app.activity

会有一股神秘感。 提交于 2019-12-01 01:58:05
I know this question has been asked before but they haven't been in the same situation I'm in. My problem I need to have my PostPhotosActivity class retainInstance. The way I'm doing that is turning it into a fragment. Unfortunately I'm always getting this error. 12-13 14:38:55.669: E/AndroidRuntime(30234): FATAL EXCEPTION: main 12-13 14:38:55.669: E/AndroidRuntime(30234): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{trade.ly.tradely/trade.ly.tradely.PostPhotosActivity}: java.lang.ClassCastException: trade.ly.tradely.PostPhotosActivity cannot be cast to android.app

HQL IN operator, Array of Enums ClassCastException

流过昼夜 提交于 2019-12-01 01:17:01
Here is my stripped down class and enum. class A { @Enumerated (value = EnumType.STRING) AType type; } enum AType { X,Y } if I run query = FROM A a WHERE a.type = :type query.setParameter("type", AType.X); All is fine and dandy. However if I do the following: AType[] types = new AType[1]; types[0] = AType.X; query = FROM A a WHERE a.type IN (:types) query.setParameter("types", types); I get: Lcom.src.AType; cannot be cast to java.lang.Enum If I do: Enum[] types = new Enum[1]; types[0] = AType.X; query = FROM A a WHERE a.type IN (:types) query.setParameter("types", types); I get: Ljava.lang

Fatal Exception: String can't be cast to Spannable

╄→尐↘猪︶ㄣ 提交于 2019-12-01 00:21:19
问题 My app works greatly with the exception of a few devices. On one such device, I get a FATAL EXCEPTION in one of my activities. The error is java.lang.ClassCastException: java.lang.String cannot be cast to android.text.Spannable ... ... at android.widget.TextView.setEnabled(TextView.java:1432) STACK TRACE 05-02 09:18:19.917: E/AndroidRuntime(20587): FATAL EXCEPTION: main 05-02 09:18:19.917: E/AndroidRuntime(20587): java.lang.ClassCastException: java.lang.String cannot be cast to android.text

Fragment cannot be cast to android.app.activity

北城余情 提交于 2019-11-30 21:10:52
问题 I know this question has been asked before but they haven't been in the same situation I'm in. My problem I need to have my PostPhotosActivity class retainInstance. The way I'm doing that is turning it into a fragment. Unfortunately I'm always getting this error. 12-13 14:38:55.669: E/AndroidRuntime(30234): FATAL EXCEPTION: main 12-13 14:38:55.669: E/AndroidRuntime(30234): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{trade.ly.tradely/trade.ly.tradely

HQL IN operator, Array of Enums ClassCastException

早过忘川 提交于 2019-11-30 21:10:34
问题 Here is my stripped down class and enum. class A { @Enumerated (value = EnumType.STRING) AType type; } enum AType { X,Y } if I run query = FROM A a WHERE a.type = :type query.setParameter("type", AType.X); All is fine and dandy. However if I do the following: AType[] types = new AType[1]; types[0] = AType.X; query = FROM A a WHERE a.type IN (:types) query.setParameter("types", types); I get: Lcom.src.AType; cannot be cast to java.lang.Enum If I do: Enum[] types = new Enum[1]; types[0] = AType

ClassCastException LinearLayout LayoutParams

被刻印的时光 ゝ 提交于 2019-11-30 12:50:44
I got an Actionbar and some Fragments. The Problem is my Homescreen. There is an overview Fragment on the left side and a detail Fragment on the right side. My TabListener is Dynamic so i want to set the weight of my Layout programatically. Whenever i try to get the Layoutparams of my LinearLayout i get a ClassCastException: 12-22 16:00:37.620: W/System.err(7235): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams 12-22 16:00:37.625: W/System.err(7235): at com.coover.eu.lostandfound.ListSearchFragment.onViewCreated

Why wrapping a generic method call with Option defers ClassCastException?

若如初见. 提交于 2019-11-30 08:54:39
问题 Lets say I have an array like this*: val foo: Any = 1 : Int Option(foo.asInstanceOf[String]) which fails for obvious reason: // java.lang.ClassCastException: java.lang.Integer cannot be cast to // java.lang.String // ... 48 elided Next lets consider a following class: case class DummyRow() { val foo: Any = 1 : Int def getAs[T] = foo.asInstanceOf[T] def getAsOption[T] = Option(foo.asInstanceOf[T]) } As far as I can tell getAs should behave the same way as the previous apply followed by

FrameLayout to RelativeLayout ClassCastException even if there is no FrameLayout used

此生再无相见时 提交于 2019-11-30 00:47:41
问题 In my application, I have a layout which has a RelativeLayout to which I want to set margins at runtime programmatically. But when I do that, it gives me ClassCastException saying FrameLayout can not cast to RelativeLayout . I don't have any FrameLayout used, also there are no imports for FrameLayout . Still the problem persists. The xml I am using is: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rl_root"

ClassCastException, casting Integer to Double

☆樱花仙子☆ 提交于 2019-11-29 22:51:35
ArrayList marks = new ArrayList(); Double sum = 0.0; sum = ((Double)marks.get(i)); Everytime I try to run my program, I get a ClassCastException that states: java.lang.Integer cannot be cast to java.lang.Double We can cast an int to a double but we can't do the same with the wrapper classes Integer and Double : int a = 1; Integer b = 1; // inboxing, requires Java 1.5+ double c = (double) a; // OK Double d = (Double) b; // No way. This shows the compile time error that corresponds to your runtime exception. Well the code you've shown doesn't actually include adding any Integers to the ArrayList