R.id cannot be resolved in android ListActivity

I get this strange error:

  R.id cannot be resolved 

in lines:

 WebView myWebView = (WebView) findViewById(view.R.id.webview);
 myWebView.loadUrl(s);

I tried to clear the project and restart it. here is my code:

public class NewsActivity  extends ListActivity {
 public ReadXML ReadXML=new ReadXML();
 public  ArrayList<String> ynetList =new ArrayList<String>();

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

for(int i=0;i<ReadXML.hadashotListItems.size();i++)
ynetList.add(ReadXML.hadashotListItems.get(i).title+"\n"+ReadXML.hadashotListItems.get(i).pubDate);

      setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, ynetList));
    //  setContentView(R.layout.main);
      ListView lv = getListView();
      lv.setTextFilterEnabled(true);

      lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
          // When clicked, show a toast with the TextView text
        String s=   ReadXML.hadashotListItems.get(position).link;

        WebView myWebView = (WebView) findViewById(view.R.id.webview);
        myWebView.loadUrl(s);
    //


      //Toast.makeText(getApplicationContext(((TextView)view).getText(),Toast.LENGTH_SHORT).show();
        }
      }
      );
    }}

my xml code: list_item.xml

  <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="15sp" >
</TextView>


<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</LinearLayout>

thanks for the help!

0
source share
3 answers

A message R.id cannot be resolvedmeans that the class is Rnot built properly or at least does not match your file list_item.xmlas it defines id.

Possible reasons are as follows:

  • Eclipse is lost and the project cannot be built correctly (this happens sometime): try to clean and rebuild the project (project menu / clear Eclipse).

  • Sometimes this is also not enough, so try

    • clear project
    • AndroidManifest.xml, char
    • Eclipse
    • .


  • list_item.xml . [project_root]/res/layout

  • Android. " Windows/Android SDK ADT" Eclipse, .

+1

WebView myWebView = (WebView) findViewById(R.id.webview); 

R

0

try this way

WebView myWebView = (WebView) findViewById(R.id.webview);
0
source

Source: https://habr.com/ru/post/1622585/


All Articles