• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps WTF... Why aren't my ID tags working at all.

falkon114

Newbie
I'm trying to do the most basic program in the world. Seriously, the most basic, rudimentary conversion app never invented for my class. All i want to do is have someone enter a number, then click whether they want that number converted to KM or Mi.
So I have an edit text field and two buttons, one each for KM and Mi... when I try to do the Button km = (Button) findViewById(R.id.km); code, id is underlined because the program never even creates an id method in the auto generated R file.
What the ****! I haven't found this error on the internet, and none of my classmates have any idea, since no one else gets this error.
Any ideas? This is extremely frustrating.
 
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText android:layout_width="match_parent"
        android:layout_height="wrap_content" android:id="@+id/editText1"
        android:text="EditText"></EditText>
    <TableLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:id="@+id/tableLayout1">
        <Button android:layout_width="wrap_content"
            android:text="@string/km" android:layout_height="wrap_content" android:id="@+id/km"></Button>
        <Button android:id="@+id/mi" android:layout_width="wrap_content"
            android:text="@string/mi" android:layout_height="wrap_content"></Button>
    </TableLayout>
</LinearLayout>
Code:
// imported methods here
public class Assn08 extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
    private Button km;
    private Button mi;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button km = (Button)this.findViewById(R.id.); //////EAGDZ
        Button mi = (Button) findViewById(R.id.);
    }
}

Also, i remember seeing a setting for having each xml element on it's own line in the coding window... Know where it's at?
 
It doesn't generate any errors if I try it.

Do you have any error reports in your error window?
 
No errors, no error reports, except underlining id and saying the method isn't there, but if I try to create the method in R, it does this deal:
Code:
public static Object id;
and doesn't add the button or memory location anyway...

The Clean... thing worked perfectly, except now this is underlined...
Falkon114Picture2-14.png
http://s10.photobucket.com/albums/a115/Falkon114/Picture2-14.png
says "The method findViewById(int) in the type Activity is not applicable for the arguments (Class<R.id>)"
.. =/

Edit:
So i casted it like this
((Button) findViewById(R.id.mi)).setOnClickListener(this);

and it works fine. now all I'm confused about is how do I store a number from an edit text field into a variable so I can work with it?
 
You should be able to cast it to a button normally.
then you could access the properties Button has.
 
Back
Top Bottom