2014-07-13 64 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