Android tutorial error: R cannot be resolved to a variable

前端 未结 12 582
野性不改
野性不改 2020-12-11 20:35

http://developer.android.com/training/basics/firstapp/building-ui.html

I have been following this tutorial, but I have two errors, both \"R cannot be resolved to a v

相关标签:
12条回答
  • 2020-12-11 21:14

    Make sure the executables (aapt etc.) in sdk/build-tools/android-xyz/* are executable if you are running the default download on your Linux box...

    0 讨论(0)
  • 2020-12-11 21:15

    I'm working my way through the same example, and had the same (or very similar) problem.

    Finally I noticed that there was a tiny little red x on the manifest.xml. Sure enough, it was complaining about this:

    android:label="@string/title_activity_hello_world" >
    

    So I added:

    <string name="title_activity_hello_world">Hello World</string>
    

    to strings.xml and now it works.

    0 讨论(0)
  • 2020-12-11 21:15

    I found the solution:

    go to your project->res->menu than open the XML file there and delete this line:

    android:title="@string/menu_settings"
    

    I deleted it and it start to work,after 3 hours of the same warning in the problem section.

    It even make sense when you read it, "at title with value @string/menu_settings"

    0 讨论(0)
  • 2020-12-11 21:17

    In my case, the problem was that I was on 64-bit Linux, and the required 32-bit libraries were not installed, meaning that the build tools could not generate R.java.

    Running this command, then cleaning the project, fixed the problem:

    sudo apt-get install ia32-libs
    
    0 讨论(0)
  • 2020-12-11 21:20

    I had android:text="@string/button_send"
    Which gave the error: No resource found that matches the given name (at 'text' with value '@string/button_send').

    I tried to solve the error using the tuturial. But the tutorial fails to tell me to write all the lines required one by one. So I miss to write "<string name="button_send">Send</string>" in the strings.xml.

    After adding the previous line the error disappear! Which I believe is something similar to the original problem in this thread.

    So if I had copied the whole lines from the given tutorial it may had not happened, but by typing our-self is how I think is the best way of learning.

    0 讨论(0)
  • 2020-12-11 21:21

    I had the same error trying to do the first tutorial. To get the app to run I edited MainActivity.java so it looked like this

    package com.example.myfirstapp;
    

    import android.app.Activity; import android.os.Bundle;

    public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    }
    

    }

    0 讨论(0)
提交回复
热议问题