我是 Java 和 Android 开发的新手,我无法修复错误。我想TextView
用变量更改 a 的文本,但视图类是静态的。这是代码:
public static class FirstTab extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.first_tab, null);
new Thread() {
public void run() {
MCQuery mcQuery = new MCQuery(serverAddress, 25565);
QueryResponse response = mcQuery.basicStat();
int Onlineplayers = response.getOnlinePlayers();
Log.d("MCQuery", "" + Onlineplayers + " Online Players");
}
}.start();
TextView onlinePlayersView = (TextView) findViewById(R.id.online_players);
onlinePlayersView.setText(Onlineplayers);
return v;
}
}
错误是:“无法findViewById(int)
从 Activity 类型对非静态方法进行静态引用”
我怎么解决这个问题?