r.java file - Android Development : id cannot be resolved or is not a field -


so started android development, , i've hit wall. have been looking around whole lot online , on website, can't seem find answer works me. have written down far in activity file following.

import android.app.activity; import android.os.bundle; import android.widget.button; public class commanderactivity extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate)    {      super.oncreate(savedinstancestate);      setcontentview(r.layout.main);      final button button = (button) findviewbyid( r.id.button_id );   }     } 

it in last line of code ( r.id.button_id ) error arises. xml file looks this:

<?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" > <tablelayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="wrap_content" >     <tablerow>     <button          android:layout_height="wrap_content"         android:layout_width="match_parent"         android:text="@string/parameters"         android:onclick="openparameters" />      <button         android:layout_height="wrap_content"         android:layout_width="match_parent"         android:text="@string/waves"         android:onclick="openwaves" />     </tablerow>     <tablerow>     <button         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:text="@string/moreparameters"         android:onclick="openmoreparameters" />     <button         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:text="@string/status"         android:onclick="openstatus" />     </tablerow>     <tablerow>     <button         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:text="@string/operations"         android:onclick="openoperations" />      <button         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:text="@string/monitor"         android:onclick="openmonitor" />     </tablerow>     <tablerow>     <button         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:text="@string/cebus"         android:onclick="opencebus" />     <button         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:text="@string/advanced"         android:onclick="openadvanced" />     </tablerow> </tablelayout> </linearlayout> 

just add following line button android:id="@+id/my_button"
within activity can use method findviewbyid(r.id.my_button);

hope helps. recommend reading -> http://developer.android.com/guide/topics/ui/declaring-layout.html


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -