类强制转换异常 [英] Class cast Exception

查看:109
本文介绍了类强制转换异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下代码中收到错误



  String  str = jTable1.getModel()的toString(); 
jTable2.setModel(str);





我想存储表模型以字符串格式访问数据库并检索此数据来自数据库的字符串格式并将其分配给表。



如何转换它?

解决方案

为什么,为什么要使用字符串呢?这是许多现代初学者的最大缺陷和误解:认为所有对象都是字符串。您需要自己处理对象,而不是表示这些对象的字符串。在您的情况下,通过 toString()从模型中获取的字符串甚至不代表模型。



-SA

I am getting error during following code

String str=jTable1.getModel().toString();
jTable2.setModel(str);



I want to store table model to access database in string format and retrieve this data from database in string format and assign it to table.

How I can convert this?

解决方案

Why, why using the string at all? This is the biggest flaw and misconception of many present-day beginners: thinking that all objects are string. You need to work with objects themselves, not strings representing those objects. In your case, the string obtained from the model via toString() does not even represent the model.

—SA


这篇关于类强制转换异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆