Intent传递数据的时候 报错空指针

RaidenMei 2016-03-28 10:29:34
错误信息:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=10, result=10, data=Intent { cmp=com.amobletool.bluetooth.le/.ShowActivity (has extras) }} to activity {com.amobletool.bluetooth.le/com.amobletool.bluetooth.le.ShowActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.amobletool.bluetooth.le.TongDao.gett1()' on a null object reference

showactivity.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 10:
if (resultCode == RESULT_OK) {
TextView s1 = (TextView) findViewById(R.id.s1);
TextView s2 = (TextView) findViewById(R.id.s2);
TextView s3 = (TextView) findViewById(R.id.s3);
TextView s4 = (TextView) findViewById(R.id.s4);
TextView s5 = (TextView) findViewById(R.id.s5);
TextView s6 = (TextView) findViewById(R.id.s6);

TongDao shuju = (TongDao)getIntent().getParcelableExtra("shuju");
s1.setText(shuju.gett1());
s2.setText(shuju.gett2());
s3.setText(shuju.gett3());
s4.setText(shuju.gett4());
s5.setText(shuju.gett5());
s6.setText(shuju.gett6());
}
break;
default:
}
}

amocomactivity.java
public synchronized void run() {
for (int i=pd;i<(pd+sd);i++){
String t="";
t = Integer.toString(Integer.parseInt(cuandi.substring(9+6*(i-6),14+6*(i-6)).replaceAll(" ",""),16));
switch (i) {
case 6:
shuju.sett1(t);
break;
case 7:
shuju.sett2(t);
break;
case 8:
shuju.sett3(t);
break;
case 9:
shuju.sett4(t);
break;
case 10:
shuju.sett5(t);
break;
case 11:
shuju.sett6(t);
break;
}
}
public void onBackPressed() {
Intent mIntent = new Intent(AmoComActivity.this,ShowActivity.class);
Bundle mBundle = new Bundle();
mBundle.putParcelable("shuju", shuju);
mIntent.putExtras(mBundle);
setResult(RESULT_OK,mIntent);
finish();
}

tongdao.java
public class TongDao implements Parcelable{
private String t1;
private String t2;
private String t3;
private String t4;
private String t5;
private String t6;
public TongDao(){

}
public String gett1() {
return t1;
}
public void sett1(String t1) {
this.t1 = t1;
}
public String gett2() {
return t2;
}
public void sett2(String t2) {
this.t2 = t2;
}
public String gett3() {
return t3;
}
public void sett3(String t3) {
this.t3 = t3;
}
public String gett4() {
return t4;
}
public void sett4(String t4) {
this.t4 = t4;
}
public String gett5() {
return t5;
}
public void sett5(String t5) {
this.t5 = t5;
}
public String gett6() {
return t6;
}
public void sett6(String t6) {
this.t6 = t6;
}
public static final Parcelable.Creator<TongDao> CREATOR = new Creator<TongDao>() {
public TongDao createFromParcel(Parcel source) {
TongDao shuju = new TongDao();
shuju.t1 = source.readString();
shuju.t2 = source.readString();
shuju.t3 = source.readString();
shuju.t4 = source.readString();
shuju.t5 = source.readString();
shuju.t6 = source.readString();
return shuju;
}
public TongDao[] newArray(int size) {
return new TongDao[size];
}
};
@Override
public int describeContents() {
// TODO 自动生成的方法存根
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO 自动生成的方法存根
dest.writeString(t1);
dest.writeString(t2);
dest.writeString(t3);
dest.writeString(t4);
dest.writeString(t5);
dest.writeString(t6);
}
...全文
258 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
哎,真难 2016-03-28
  • 打赏
  • 举报
回复
没穿过去吧,debug看看intent里面有没有这个对象
RaidenMei 2016-03-28
  • 打赏
  • 举报
回复
本人刚接触android 没多久= =

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧