2014-07-13 27 views
2

我想从这样的一个的AsyncTask设置一些TextView中的文本:资源ID NOTFOUND时设置的TextView的文本从的AsyncTask

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是从我的ListView,和IM确保它们不为空,但我取回此错误:

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) 

但即时通讯相当肯定,我做了一些这样的事之前,你看到了什么事错在这里家伙?

回答

2

您正在传递一个整数参数,它对应于采用资源标识符的setText版本。您应该使用类似:

populationTV.setText(Integer.toString(info.getOccupantsCount())); 
+0

妈呀,怎么我傻的,生病尝试和回来尽快 – dasdas

+0

这工作,非常感谢亲爱的,所有的时间我想有些事情是错的TextView的ID – dasdas