不会Gson这个json也才刚刚学加了之后没有报错。但是有感叹号 The value of the local variable test is not used要用全局变量
不会Gson这个json也才刚刚学加了之后没有报错。但是有感叹号 The value of the local variable test is not used要用全局变量 也不行 那个test用全局还是传出不去,用test拿到数据之后可以直接放到adapter里面去吧 因为是解析好的,还是报java.lang.NullPointerException,还是另外怎么写,还有那个hanlder我是放在主线程外面写的,adapter是放在里面写的,有影响没,而且如果用handler从子线程得到的值接收然后定义全局变量,在另一个方法里面使用这个值不行额 里面应该是空的。。我也不知道我是不是按你想法写的 我把代码贴你看看private List test; Handler handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == NEWSCOUNT) { String string = msg.getData().getString("ok"); test = getSpcCatNews(string); } } }; //adapter SimpleAdapter adapter = new SimpleAdapter(this, test, R.layout.new_list, new String[] { "newslist_item_title", "newslist_item_digest", "newslist_item_source", "newslist_item_ptime" }, new int[] { R.id.newslist_item_title, R.id.newslist_item_digest, R.id.newslist_item_source, R.id.newslist_item_ptime }); newlist = (ListView) findViewById(R.id.news_list); newlist.setAdapter(adapter);
也不行 那个test用全局还是传出不去,用test拿到数据之后可以直接放到adapter里面去吧 因为是解析好的,还是报java.lang.NullPointerException,还是另外怎么写,还有那个hanlder我是放在主线程外面写的,adapter是放在里面写的,有影响没,而且如果用handler从子线程得到的值接收然后定义全局变量,在另一个方法里面使用这个值不行额 里面应该是空的。。我也不知道我是不是按你想法写的 我把代码贴你看看private List test;
Handler handler = new Handler() { public void handleMessage(Message msg) {
if (msg.what == NEWSCOUNT) {
String string = msg.getData().getString("ok"); test = getSpcCatNews(string); }
}
};
//adapter
SimpleAdapter adapter = new SimpleAdapter(this, test,
R.layout.new_list, new String[] { "newslist_item_title",
"newslist_item_digest", "newslist_item_source",
"newslist_item_ptime" }, new int[] {
R.id.newslist_item_title, R.id.newslist_item_digest,
R.id.newslist_item_source, R.id.newslist_item_ptime }); newlist = (ListView) findViewById(R.id.news_list);
newlist.setAdapter(adapter);
list add《Hasmap》之后吗?但是上面那个newData拿不到值,adapter差一个数据怎么弄newData=getSpcCatNews(null); 这个null传进去有影响没