0

I am getting this strange error:

  R.id cannot be resolved 

on lines:

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

I tried to clean 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 is: 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 help!

Vitaly Menchikovsky
  • 7,684
  • 17
  • 57
  • 89
  • 1
    includin `xmlns:android` in parent Layout Container is enough. you don't need to include in it every tag. – Adil Soomro Aug 30 '11 at 09:51
  • Please stick to one problem per question. Otherwise when someone else is going through this question for an answer he will be throughly confused with multiple answers.. If you have multiple problems, shoot out different questions. – bluefalcon Aug 30 '11 at 11:45

3 Answers3

1

The message R.id cannot be resolved means that the R class is not properly built or at least is not according to your file list_item.xml as it defines an id.

The probable causes are the following:

  • Eclipse is lost and does not manage to build your project properly (this happens sometime): try to clean and rebuild your project (menu project/clean of Eclipse).

  • Sometimes this is not sufficient either, so try to

    • clean you project
    • modify your AndroidManifest.xml by adding a blank char in it
    • Close your project in Eclipse
    • Open it again
    • Re-clean it and build it


  • Your file list_item.xml is not in the right directory. It should be in the directory [project_root]/res/layout

  • You have an Android framework installation problem. Check in the menu "Windows/Android SDK and ADT manager" of Eclipse whether everything is fine.

Shlublu
  • 10,917
  • 4
  • 51
  • 70
0

It should be just

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

No view before the R

bluefalcon
  • 4,225
  • 1
  • 32
  • 41
  • are you getting some other errors before this? Can you clean and build the project?(after you make the above changes) – bluefalcon Aug 30 '11 at 10:03
  • I tried to run the project without the pronlem lines and my program crashed because of the xml. it works only if xml without the view and witout the LinearLayout like – Vitaly Menchikovsky Aug 30 '11 at 10:14
0

try this way

WebView myWebView = (WebView) findViewById(R.id.webview);
Kartik Domadiya
  • 29,868
  • 19
  • 93
  • 104
Pratik
  • 30,639
  • 18
  • 84
  • 159