Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old April 1st, 2011, 05:19 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Mar 2011
Posts: 10
 
Device(s): HTC Thunderbolt, ex Samsung Continuum (Loved it)
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Angry WTF... Why aren't my ID tags working at all.

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.

falkon114 is offline  
Reply With Quote
sponsored links
Old April 1st, 2011, 05:21 PM   #2 (permalink)
Member
 
Join Date: Apr 2010
Location: Netherlands
Posts: 142
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 1
Thanked 23 Times in 23 Posts
Default

how are you defining your id's?
can you give an example of your layout xml?
id0001 is offline  
Reply With Quote
Old April 1st, 2011, 05:27 PM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Mar 2011
Posts: 10
 
Device(s): HTC Thunderbolt, ex Samsung Continuum (Loved it)
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Default

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?
falkon114 is offline  
Last edited by falkon114; April 1st, 2011 at 05:31 PM.
Reply With Quote
Old April 2nd, 2011, 02:46 AM   #4 (permalink)
Member
 
Join Date: Apr 2010
Location: Netherlands
Posts: 142
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 1
Thanked 23 Times in 23 Posts
Default

It doesn't generate any errors if I try it.

Do you have any error reports in your error window?
id0001 is offline  
Last edited by id0001; April 2nd, 2011 at 02:50 AM.
Reply With Quote
Old April 2nd, 2011, 03:44 AM   #5 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 313
 
Device(s): Samsung Galaxy Nexus
Carrier: Not Provided

Thanks: 0
Thanked 53 Times in 51 Posts
Default

You can try to "Clean" the project by clicking: Project->Clean
miXer is offline  
Reply With Quote
Old April 2nd, 2011, 11:54 AM   #6 (permalink)
New Member
Thread Author (OP)
 
Join Date: Mar 2011
Posts: 10
 
Device(s): HTC Thunderbolt, ex Samsung Continuum (Loved it)
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Default

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...
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?
falkon114 is offline  
Last edited by falkon114; April 2nd, 2011 at 12:00 PM.
Reply With Quote
Old April 3rd, 2011, 03:00 AM   #7 (permalink)
Member
 
Join Date: Apr 2010
Location: Netherlands
Posts: 142
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 1
Thanked 23 Times in 23 Posts
Default

You should be able to cast it to a button normally.
then you could access the properties Button has.
id0001 is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:22 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.