我有这个连接到 Facebook 的应用程序。出于某种原因,我收到此错误:
android.view.ViewRoot$CalledFromWrongThreadException:只有创建视图层次结构的原始线程才能触摸其视图。
这是我的代码:
活动:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
app = (AppVariables)getApplicationContext();
context = getBaseContext();
facebook = app.getFacebook();
facebookRunner = new AsyncFacebookRunner(facebook);
facebookConnection = new FacebookConnection(this);
internetStatus = (TextView)findViewById(R.id.internetStatus);
facebookRunner.request("me", facebookConnection);
}
@Override
public void onFacebookResponse(String response) {
internetStatus.setText(response);
}
这是 FacebookConnection 类:
public class FacebookConnection implements RequestListener {
private FacebookConnectionListener listener;
public FacebookConnection (FacebookConnectionListener listener)
{
this.listener = listener;
}
public void updateFacebookListener(String response)
{
listener.onFacebookResponse(response);
}
@Override
public void onComplete(String response, Object state) {
updateFacebookListener(response);
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
这是我的监听器界面:
public interface FacebookConnectionListener {
public void onFacebookResponse(String response);
}
怎么了?