android - Getting compilation error "activity_main" can not be resolved or is not a filed -


i trying instrument android application sdk enables me test mobile application on device. needed create mainactivity class in app have following method:

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main); 

but following compilation errors:

"activity_main can not resolved or not field"

i have seen postings in regards , provided solution has been:

remove "import android.r;"

add "import application.package_name.r;

i have done follow:

import com.mymobileapp.r

where "com.mymobileapp" package name r.java resides error persists after re-build\clean project.

if provide name of application import statement can not resolved , not think necessary since referencing package in same application.

also, checked r.java class generated file , seems can not modified since eclipse gives me warning file can not edited. in r.java file under layout not see "activity_main" filed in there. have following in r.java class under layout:

public static final class layout {     public static final int cycleslistheader=0x7f030000;     public static final int feedback=0x7f030001;     public static final int login=0x7f030002;     public static final int master=0x7f030003;     public static final int overlay=0x7f030004;     public static final int problem=0x7f030005;     public static final int testcycle=0x7f030006;     public static final int testcycles=0x7f030007;     public static final int user=0x7f030008;     public static final int userlistheader=0x7f030009;  

so has applied solution other 1 explained above. appreciate help.

as simple example of layout, call activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >      <textview        android:id="@+id/hello_world"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" />     <button         android:id="@+id/button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/app_name" />  </linearlayout> 

go eclipse, right click on project -> new -> android xml file. name activity_main.xml , paste above it. save , go.

android dev page layouts: http://developer.android.com/guide/topics/ui/declaring-layout.html

in oncreate() method, calling setcontentview(r.layout.activity_main); telling android want layout activity 1 described in xml in activity_main.xml layout file (in layout folder in res folder). if don't have 1 there, won't able inflate layout , error. give simple view, can change needed project. note there tons of layouts , views, , can make own custom ones fit needs.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -