OK, so before I posted this, I did a few more things to make sure I wasn't posting a stupid question and it turns out it was a stupid mistake. I'd found a couple questions that may have been the same issue but none of them were solved. Since I'd already written this all up I figured I'd post it anyway just so that anyone else with this problem could find the answer a little easier.
It occurred to me that the tutorial said to add the OnClickListener code at the BOTTOM of the onCreate method. I overlooked this and put it just before the setContentView(R.layout.main); line. Coming from the web world where you set your layout last (in certain frameworks), this made sense. But once I realized what setting the layout does, it suddenly clicked that of course the button won't be defined until you tell android to use the layout that includes it. Hope this wasn't a waste. On May 25, 4:46 pm, "Philip H." <[email protected]> wrote: > I'm brand new to developing for android, so this has been driving me > crazy all day even though I'm sure it's simple. > > I'm going through the Hello Form Stuff tutorial and it seems like it > can't find a button resource in the drawable folder. I've tried > placing the three icons and the XML file in the 'drawable' folder and > all three pixel density variants (ie: '-hdpi'). I've run 'Clean...' > on the project many times and it finds the correct R class, but it's > just not finding the button I've defined. > > Here are the relevant parts (almost a straight copy/paste from the > tutorial) > /res/layout/main.xml: > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > android" > android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > > <Button android:id="@+id/button" > android:layout_width="wrap_content" > android:layout_height="wrap_content" > android:padding="10dp" > android:background="@drawable/android_button" /> > </LinearLayout> > > /res/drawable/android_button.xml: > <selector xmlns:android="http://schemas.android.com/apk/res/android"> > <item android:drawable="@drawable/android_pressed" > android:state_pressed="true" /> > <item android:drawable="@drawable/android_focused" > android:state_focused="true" /> > <item android:drawable="@drawable/android_normal" /> > </selector> > > HelloFormStuff.java: > final Button button = (Button) findViewById(R.id.button); > Log.v("HelloForms", button.getClass().toString()); > button.setOnClickListener(new OnClickListener() { ... } > > -------- > It was breaking on the line with button.setOnClickListener() so I put > the log command in there and now it breaks on that line instead (I > assume because you can't call getClass() on a null object). -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en

