我正在尝试从AsyncTask中设置一些TextView的文本,如下所示:
class InfoLoader extends AsyncTask<Params, String, Result>{
final String groupName;
final TextView populationTV;
final TextView passwordstateTV;
final TextView publicstateTV;
RoomInfo info;
protected InfoLoader(final String groupName,final TextView populationTV, final
TextView passwordstateTV, final TextView publicstateTV) {
super();
this.groupName = groupName;
this.populationTV = populationTV;
this.passwordstateTV = passwordstateTV;
this.publicstateTV = publicstateTV;
}
@Override
protected Result doInBackground(Params... params) {
try {
info =
MultiUserChat.getRoomInfo(MyService.connection,groupName+"@conference.reza-hp");
} catch (NoResponseException | XMPPErrorException
| NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
if(populationTV==null){
System.out.println("Its null");
}
if(info==null){
System.out.println("Info null");
}
populationTV.setText(info.getOccupantsCount());
if(info.isPasswordProtected()==true){
passwordstateTV.setText("Yes");
}else if(info.isPasswordProtected()==false){
passwordstateTV.setText("No");
}
if(info.isMembersOnly()==true){
publicstateTV.setText("Members Only");
}else if(info.isMembersOnly()==false){
publicstateTV.setText("Public");
}
}
});
return null;
}
}
TextViews来自My ListView,我确定它们不是null,但是我检索到了这个错误:
07-12 20:40:57.909: E/AndroidRuntime(3063): FATAL EXCEPTION: main
07-12 20:40:57.909: E/AndroidRuntime(3063): Process: com.lifemate.lmmessenger, PID:
3063
07-12 20:40:57.909: E/AndroidRuntime(3063):
android.content.res.Resources$NotFoundException: String resource ID #0x0
07-12 20:40:57.909: E/AndroidRuntime(3063): at
android.content.res.Resources.getText(Resources.java:244)
07-12 20:40:57.909: E/AndroidRuntime(3063): at
android.widget.TextView.setText(TextView.java:3888)
07-12 20:40:57.909: E/AndroidRuntime(3063): at
com.lifemate.lmmessenger.listviewengine.SelfMUCPinnedHeaderAdapter$InfoLoader$1.
run(SelfMUC
PinnedHeaderAdapter.java:328)
07-12 20:40:57.909: E/AndroidRuntime(3063): at
android.os.Handler.handleCallback(Handler.java:733)
但是我很确定我以前做过这样的事,你在这里看到了什么错吗?
答案 0 :(得分:2)
您正在传递一个整数参数,该参数对应于采用资源标识符的setText版本。你应该使用类似的东西:
populationTV.setText(Integer.toString(info.getOccupantsCount()));