![](/img/trans.png)
[英]Android: cannot resolve method 'findViewById(int)' in AsyncTask
[英]Android findViewById cannot resolve variable
我是 Android 开发的新手
我有这个活动课
public class ElencoNotificheActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_elenco_notifiche);
}
private void setRefreshListener()
{
ListView elencoNotificheView = (ListView)findViewById(R.layout.elencoNotificheView);
}
}
在我的活动类中,我有以下错误:
错误:(18, 71) 错误:找不到符号变量 elencoNotificheView
但是在我的布局 XML 中,我有:
<ListView
android:id="@+id/elencoNotificheView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="true"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
/>
它应该是R.id.elencoNotificheView
而不是R.layout. elencoNotificheView
R.layout. elencoNotificheView
所以你的 ListView 应该是这样的:
ListView elencoNotificheView = (ListView)findViewById(R.id.elencoNotificheView);
你应该有R.id.elencoNotificheView
:
private void setRefreshListener()
{
ListView elencoNotificheView = (ListView)findViewById(R.id.elencoNotificheView);
}
它应该是
ListView elencoNotificheView = (ListView)findViewById(R.id.elencoNotificheView);
代替
ListView elencoNotificheView = (ListView)findViewById(R.layout.elencoNotificheView);
你需要在代码下面修复它..
private void setRefreshListener()
{
ListView elencoNotificheView = (ListView)findViewById(R.layout.elencoNotificheView);
}
更新
ListView elencoNotificheView = (ListView)findViewById(R.id.elencoNotificheView);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.