//客户端:
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范型接口

解决方案 »

  1.   

    麻烦懂的哥哥姐姐们帮忙看看,PHPRPC这个协议在这中间没就一个桥梁作用。就是不知道这两块代码哪里出了问题。之前我的范型是business_news类型(一个封装类)出现了空指针异常,同样是客户端最后一条。他们说通过接口是不能那样访问的,我又把它换成了String类型。只要我的客户端能取到值,就好了
      

  2.   

    居然没人来踩踩,伤心啊!
    不过我自己弄出来了。之后再PHPRPC官网看到。这转码问题。PHPRPC自带了一个工具---Cast
    专门用来解决转码问题的。我的代码并没有错。直接在取出来的那个System.out.println(list.get(i));加上一个东西就搞定了
    System.out.println(Cast.toString(list.get(i));
      

  3.   

    String.valueOf这种方法试过的,也不行的