![](/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.