Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid tutorial error: R cannot be resolved to a variable
    text
    copied!<p><a href="http://developer.android.com/training/basics/firstapp/building-ui.html" rel="nofollow">http://developer.android.com/training/basics/firstapp/building-ui.html</a></p> <p>I have been following this tutorial, but I have two errors, both "R cannot be resolved to a variable". I have made android apps (easy ones) in the past, and I remember this problem being fixed by checking whether or not I have an import R statement (which I don't) and whether or not the project has been cleaned before being built again (I cleaned it and I still get the error). I am at a loss as to what to do. Thanks!</p> <p>*I also want to mention I did see the thread of the same title with 170 hits, and the solution of "delete the import R statement" does not apply to my problem (I don't think) Thanks again</p> <p>All code is straight from the link above, but here it is for convenience</p> <p>activity_my_first.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"&gt; &lt;EditText android:id="@+id/edit_message" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="@string/edit_message" /&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>MyFirstActivity.java</p> <pre><code>package com.example.myfirstapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.MenuItem; import android.support.v4.app.NavUtils; public class MyFirstActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_first); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_my_first, menu); return true; } } </code></pre> <p>strings.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="app_name"&gt;My First App&lt;/string&gt; &lt;string name="edit_message"&gt;Enter a message&lt;/string&gt; &lt;string name="button_send"&gt;Send&lt;/string&gt; &lt;string name="menu_settings"&gt;Menu Settings&lt;/string&gt; &lt;/resources&gt; </code></pre> <p>edit: When I clean the project, I get this message in the Console:</p> <blockquote> <p>[2012-06-29 11:12:38 - MyFirstApp] W/ResourceType( 6140): Bad XML block: header size 91 or total size 0 is larger than data size 0 [2012-06-29 11:12:38 - MyFirstApp] C:\Users\zhong\workspace\eclipse\MyFirstApp\res\menu\activity_my_first.xml:2: error: Error: No resource found that matches the given name (at 'title' with value '@string/menu_settings').</p> </blockquote> <p>edit: added a line to layout xml file <code>&lt;string name="menu_settings"&gt;Menu Settings&lt;/string&gt;</code> Fixed cleaning project errors, but I still can't run the project from the two R errors.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload