//客户端:
public class Client {
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PHPRPC_Client client = new PHPRPC_Client("http://localhost:8080/GovernmentAffairs/Query");
INewsService inews = (INewsService) client.useService(INewsService.class);//创建服务端类
ArrayList<String> news_tit = new ArrayList<String>();
news_tit = inews.GetAllNews();
System.out.println(news_tit.isEmpty());
System.out.println(news_tit.size());
for (int i = 0; i < news_tit.size(); i++) {
System.out.println(news_tit.get(i)); }
}}
//服务端:
public class NewsQuery extends DataConnection implements INewsService {
private Connection conn; public ArrayList<String> GetAllNews() {
ArrayList<String> list = new ArrayList<String>();
String sql = "SELECT * FROM government_business_news";
try {
this.conn = DataConnection.getConn();
this.stm = conn.createStatement();
this.rst = this.stm.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
try {
while (this.rst.next()) {
Business_news news = new Business_news();
news.setNews_title(rst.getString("news_title"));
list.add(news.getNews_title());
}
;
} catch (Exception e) {
// TODO: handle exception
}
System.out.println(list.size());
System.out.println(list.isEmpty());
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
return list; }
}
我在服务端能够用for循环输出list中的数据,但是在客户端报错了(最后一行输出):Exception in thread "main" java.lang.ClassCastException: [B cannot be cast to java.lang.String
at com.aoda.zm.bussiness.Client.main(Client.java:31)
客户端我测试了news_tit这个list中size有2个,服务端能输出这个两个,但是在客户端确出错了。跪求哥哥姐姐们帮我看看异常PHPRPC范型接口
public class Client {
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PHPRPC_Client client = new PHPRPC_Client("http://localhost:8080/GovernmentAffairs/Query");
INewsService inews = (INewsService) client.useService(INewsService.class);//创建服务端类
ArrayList<String> news_tit = new ArrayList<String>();
news_tit = inews.GetAllNews();
System.out.println(news_tit.isEmpty());
System.out.println(news_tit.size());
for (int i = 0; i < news_tit.size(); i++) {
System.out.println(news_tit.get(i)); }
}}
//服务端:
public class NewsQuery extends DataConnection implements INewsService {
private Connection conn; public ArrayList<String> GetAllNews() {
ArrayList<String> list = new ArrayList<String>();
String sql = "SELECT * FROM government_business_news";
try {
this.conn = DataConnection.getConn();
this.stm = conn.createStatement();
this.rst = this.stm.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
try {
while (this.rst.next()) {
Business_news news = new Business_news();
news.setNews_title(rst.getString("news_title"));
list.add(news.getNews_title());
}
;
} catch (Exception e) {
// TODO: handle exception
}
System.out.println(list.size());
System.out.println(list.isEmpty());
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
return list; }
}
我在服务端能够用for循环输出list中的数据,但是在客户端报错了(最后一行输出):Exception in thread "main" java.lang.ClassCastException: [B cannot be cast to java.lang.String
at com.aoda.zm.bussiness.Client.main(Client.java:31)
客户端我测试了news_tit这个list中size有2个,服务端能输出这个两个,但是在客户端确出错了。跪求哥哥姐姐们帮我看看异常PHPRPC范型接口
解决方案 »
- 我认为最好的java视频教程
- Hibernate 中getcurrentsession()问题
- webwork:打开网站任何一页前先查询变量然后设置到session里
- 画图:Java实现流程图节点控制,可以实现节点更改,备注
- 如何用java把 wor的转为pdf ,不要调用dll,纯java 实现
- java工作流引擎
- 求助:学习hibernate+mysql,Query时出错.check the manual that corresponds to your MySQL server version
- 初学struts的问题
- redhat 9.0下装过weblogic 7.0.
- 请教OSGI外部启动问题
- 一个HQL语句,不知错在哪里,求指教
- 请教一个有关hibernate更新的奇葩问题!
不过我自己弄出来了。之后再PHPRPC官网看到。这转码问题。PHPRPC自带了一个工具---Cast
专门用来解决转码问题的。我的代码并没有错。直接在取出来的那个System.out.println(list.get(i));加上一个东西就搞定了
System.out.println(Cast.toString(list.get(i));