我有一个小问题。我尝试给处理程序一个字符串。我试过 bundle.putString("key","String"); ,但是如果我尝试获取字符串,我得到了一个 nullpointerException。有人可以告诉我我做错了什么吗?
代码:
Message msg = new Message();
Bundle b = new Bundle();
b.putString("note","4.25");
b.putString("fach", "Math");
Log.d("DEBUG ",b.getString("note")+" "+fach); //--> Here isn't a nullPointerException
msg.setData(b);
handler.sendMessage(msg);
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
Bundle b = msg.getData();
Log.d("DEBUG,HANDLER","note "+b.getString("note")+" fach"+b.getString("fach")); //Throws 2 times null
}
}
希望您能够帮助我。对不起英语不好:)