尝试使用Hibernate 3.6和MySQL5.1选择一个实体,但我不断得到一个ClassCastException.
@Entity
@Table( name = "USER" )
public class User {
@Id
@Column(name= "user_id")
private Long userId;
@OneToOne()
@JoinColumn(name="status_id")
protected UserStatusType userStatusType;
@OneToOne()
@JoinColumn(name="region_id")
protected Region region;
@Entity
@Table( name = "REGION" )
public class Region
@Id
@Column(name = "region_id")
private Long regionId
@Entity
@Table( name = "USER_STATUS_TYPE" )
public class UserStatusType
@Id
@Column(name = "type_id")
private Long typeId
Run Code Online (Sandbox Code Playgroud)
在createQuery()中尝试使用HQL时,我不断收到ClassCastException:
session.beginTransaction();
User user = (User)session.createQuery(
"from User u, UserStatusType ust, Region r "
+ " where u.userId = ? …Run Code Online (Sandbox Code Playgroud) 我最近决定在我的应用程序中添加一个ViewFlipper,这是我所做的:
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/steve"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
// Child elements here.
</ViewFlipper>
Run Code Online (Sandbox Code Playgroud)
MyApp.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.steve);
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的应用程序时,我得到了一个java.lang.ClassCastException: android.widget.Button用于转换为ViewFlipper的行.
经过调试,结果是findViewById(R.id.steve)返回一个Button,而不是一个ViewFlipper.
我怎样才能解决这个问题?
我遇到了以下代码的问题.类id为Long,B类id是嵌入式id,其中一个字段为A类.
DetachedCriteria dc = DetachedCriteria.forClass(A.class,"a").setProjection(Property.forName("a.id"));
Criteria cr= this.sessionFactory.getCurrentSession().createCriteria(B.class,"b").add(Subqueries.in("b.id.a.id", dc));
List<B> bb = cr.list();
Run Code Online (Sandbox Code Playgroud)
这给出了例外:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
Run Code Online (Sandbox Code Playgroud)
但是这个:
List<Long> dd = this.sessionFactory.getCurrentSession().createCriteria(A.class,"a").setProjection(Property.forName("a.id")).list();
Criteria cr= this.sessionFactory.getCurrentSession().createCriteria(B.class,"b").add(Restrictions.in("b.id.a.id", dd));
List<B> bb = cr.list();
Run Code Online (Sandbox Code Playgroud)
作品.我究竟做错了什么?
我想要处理其中一个菜单项(我用XML声明这个).
<item android:id="@+id/menu_shape_shifter"
android:title="@string/menu_search"
android:icon="@drawable/ic_action_refresh"
android:orderInCategory="0"
android:visible="true"
android:showAsAction="always" />
Run Code Online (Sandbox Code Playgroud)
所以我这样做,
MenuItem item_shape_shifter = (MenuItem)findViewById(R.id.menu_shape_shifter);
但它失败并出现异常:ClassCastException:com.android.internal.view.menu.ActionMenuItemView无法强制转换为android.view.MenuItem.
如果没有获得此菜单项的句柄,我无法继续.但是,找不到任何线索.
注意:我正在使用Action Bar兼容包,因为我支持的版本<3.0
android handle menuitem classcastexception android-actionbar
try{
System.out.println(surveyReportList.get(0).getEmploymentStatus());
}
catch(Exception e){
System.out.println(e.getCause());
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试获取列表中的一个字段值,并且我收到了ClassCastException.我使用的列表大小合适surveyReportList.size();.
这是堆栈跟踪,我surveyReportList的类型是List<SurveyReport>第103行try.
at com.action.survey.SurveyReportAction.generateReports(SurveyReportAction.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) …Run Code Online (Sandbox Code Playgroud) 我试图从数据库中检索值并将其存储在List,
数据被检索并正常工作,但当我转换List成Object<pojo class>我得到一个例外,
我的代码是
Query qry=session.createQuery("select personaldetails.fname,personaldetails.lname from Personaldetails as personaldetails where refId=1001");
List<Personaldetails> l=(List<Personaldetails>)qry.list();
session.getTransaction().commit();
session.close();
System.out.println("--->"+l.size()); //List 'l' holds the values from DB
Personaldetails p; //This is an pojo class
p=(Personaldetails)l.get(i); //Here i am getting the exception here
System.out.println("Person name "+p.getFname());
Run Code Online (Sandbox Code Playgroud)
在上面提到的行我得到了Exception ClassCastException,我不知道为什么,我试过它在编译时没有显示错误.
任何建议将不胜感激....
我使用ION(https://github.com/koush/ion)从网页中的图像加载到ListView的ImageView.目前我想从中获取位图ImageView,但是我得到一个强制关闭我的应用程序的异常:
java.lang.ClassCastException: com.koushikdutta.ion.IonDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
Run Code Online (Sandbox Code Playgroud)
这些是我正在使用的行:
final ImageView itemImageView = (ImageView)view.findViewById(R.id.photoImage);
final Bitmap itemDrawable = ((BitmapDrawable) itemImageView.getDrawable()).getBitmap();
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?提前致谢!
我想得到 PGConnection从 JBOSS AS7 中的 PosgreSQL 连接(数据源 postgresql-9.0-801.jdbc4.jar)
我在使用时遇到了强制转换异常(WrappedConnection)connection。所以现在我使用反射(JDK 1.7):
private static PGConnection getPGConnction(Connection connection) throws SQLException {
if(connection instanceof PGConnection) {
return (PGConnection)connection;
}
try {
Class[] parms = null;
Method method =(connection.getClass()).getMethod("getUnderlyingConnection", parms);
return (PGConnection) jdbc4Conn;
} catch ...
Run Code Online (Sandbox Code Playgroud)
并捕获异常
java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4Connection cannot be cast to org.postgresql.jdbc4.Jdbc4Connection
Run Code Online (Sandbox Code Playgroud)
是同一个班!!!怎么会这样?
因此,ClassCastException当我试图将我投入我的时Node<T>,我会得到这个AVLNode<T>.不知道为什么.
这是它抛出异常的地方.
Node<Integer> n1 = new Node<Integer>(3, null);
AVLNode<Integer> n2 = (AVLNode<Integer>) n1;
Run Code Online (Sandbox Code Playgroud)
课程看起来如何......
public class Node<T extends Comparable<T>> {
public Node<T> right;
public Node<T> left;
public Node<T> parent;
public T data;
public Node(T data, Node<T> parent) {
this.data = data;
this.parent = parent;
} // ...
Run Code Online (Sandbox Code Playgroud)
而另一个类在单独的文件中:
public class AVLNode<T extends Comparable<T>> extends Node<T> {
public int height = 1;
public AVLNode(T data, Node<T> parent) {
super(data, parent);
} //...
Run Code Online (Sandbox Code Playgroud)
错误消息:线程"main"中的异常java.lang.ClassCastException:custom.trees.Node无法强制转换为custom.trees.AVLNode
嗨,我是Java的新手,在这段代码中,我想我不是在Main中正确创建Bag?请帮忙谢谢!
线程"main"中的异常java.lang.ClassCastException:[Ljava.lang.Object; 无法转换为[Ljava.lang.Comparable; atBag.(Bag.java:12)mid.Bag.main(Bag.java:91)
public class Bag<T extends Comparable<T>> implements Iterable<T> {
private int MAX_ITEMS = 10; // initial array size
private int size;
private T[] data;
public Bag( ) {
data = (T []) new Object[MAX_ITEMS];
size = 0;
}
public void add(T newItem) {
// check if it's full, then extend (array resizing)
if (size == data.length) {
T[ ] temp = (T [ ] ) new Object[data.length*2];
for (int i = 0; i < size; ++i)
temp[i] …Run Code Online (Sandbox Code Playgroud) java ×5
android ×3
hibernate ×2
android-ion ×1
button ×1
casting ×1
collections ×1
generics ×1
handle ×1
image ×1
imageview ×1
jboss7.x ×1
list ×1
menuitem ×1
nodes ×1
postgresql ×1
subquery ×1
viewflipper ×1