1. Are you ready for the Galaxy S20? Here is everything we know so far!

Cannot access variables from main.xml

Discussion in 'Android Development' started by eljainc, Oct 28, 2010.

  1. eljainc

    eljainc Lurker
    Thread Starter

    Hello, I'm new to Android programming. I have a program that looks like this:
    Here is the main java block:



    public class MyAndroid extends Activity {
    private EditText input1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;

    setContentView(R.layout.main);

    input1 = (EditText) findViewById(R.id.input1);

    }





    This is what my main.xml file looks like:

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout android:id="@+id/widget45"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <EditText android:id="@+id/input1" android:layout_width="160px"
    android:layout_height="wrap_content" android:textSize="18sp"

    android:numeric = "decimal|signed"
    android:layout_x="8px" android:layout_y="13px">
    </EditText>

    </AbsoluteLayout>



    However, I'm getting an error message:
    R.id.input1 cannot be resolved. Why can't I access 'input1' from main.xml?
    I've looked around on the web and haven't found this answer.
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Clean your projects and recompile, sometime Eclipse don't generate the link correctly.
    You can check also the import, if is there "import android.R;" delete it.
     
Loading...
Similar Threads - Cannot access variables
  1. mikewax
    Replies:
    0
    Views:
    152
  2. unet
    Replies:
    0
    Views:
    260
  3. DridriLaBastos
    Replies:
    0
    Views:
    229
  4. kgash
    Replies:
    6
    Views:
    435
  5. ixoni
    Replies:
    8
    Views:
    712
  6. oneytlam
    Replies:
    2
    Views:
    570
  7. Not_Rich
    Replies:
    7
    Views:
    773
  8. FreeAlconWild2020
    Replies:
    3
    Views:
    543
  9. izabelle221
    Replies:
    2
    Views:
    1,350
  10. 77l3r
    Replies:
    1
    Views:
    604

Share This Page

Loading...