Android - activity_main cannot be resolved or is not a field

后端 未结 11 1709
栀梦
栀梦 2020-12-05 05:40

Previous people have had the same error message, but the solution has always been to remove or modify some import \"android.R\". I have no such import so I\'m really lost

相关标签:
11条回答
  • 2020-12-05 06:17

    I had same error im my app and i solved it by 1.removing import android.R; and 2.import com.example.yourpakagename.R;.3. After that clean the project.4. run project

    0 讨论(0)
  • 2020-12-05 06:17

    this is a common problem in eclipse. so 90% it is the problem with R.java file. so do following steps it will work for shore

    1.Remove your import android.R

    2.Ctrl+Shift+O.

    3.clean the project

    0 讨论(0)
  • 2020-12-05 06:19

    1) Where does your layout file exist? is it under layout folder then shouldn't it be

    R.layout.activity_main
    

    2) You still have to import your projects R file

    com.example.mapssample.R;
    

    3) R file is automatically generated if there's no error in your code. Sometimes when you get can't resolve R file error means you have problem somewhere else in the project. Try clean project. It might help.

    4) You don't really need menu for testing this project. Also the activity_main file you showed is already included in the project and that's in layout folder. Just comment the menu part and see.

    0 讨论(0)
  • 2020-12-05 06:21

    when you faced a red wave line under the Capital "R" just hold mouse there and Select second Line "import your_package_name.R" Because it link all related files of your project

    Don't select first fix that says "import android.R"

    and it still shows error under activity_main, It means can't find those files in your project,check that file names like activity_main.xml etc..

    Hope it Works..

    0 讨论(0)
  • 2020-12-05 06:21

    I'm following the Deitel Android, How to program-book, and when I tried building my first own application I experienced similar problems. What I did:

    In windows environment variables: HOME=%USERPROFILE% JAVA_HOME=\Program Files\Java\jre7\bin (or what/where you have it)

    In the code: Mainactivity.java: Added Import com.deitel.welcome.R (that is package.R) Changed the call R.layout.activity_main to R.layout.main (check the generated R.java file)

    Working!

    0 讨论(0)
  • 2020-12-05 06:23

    I am not sure if this will solve your problem, but I have always declared fragment's type in xml with the "name" attribute, not the "class" attribute. Try making your fragment

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.google.android.gms.maps.MapFragment" />
    
    0 讨论(0)
提交回复
热议问题