My row layout is in a separate XML. It appears that findViewById only can find an inflated view.
To solve that, I think I will need to create a custom ListAdapter that will bind an event to each button while inflating each view. If you see any better way, let me know. Cheers On 7 avr, 20:14, e-satis <info.ksam...@googlemail.com> wrote: > Update : setContentView first and before all, checked :-) > > On 7 avr, 20:09, e-satis <info.ksam...@googlemail.com> wrote: > > > Update : Reading other posts, I tried to trash the R.java file but it > > was not the cause. > > > On 7 avr, 19:48, e-satis <info.ksam...@googlemail.com> wrote: > > > > Hi, > > > > My java code look like this : > > > > // right_arrow button > > > ImageButton arrow_button = (ImageButton)findViewById > > > (R.id.arrow); > > > arrow_button.setOnClickListener(new OnClickListener() { > > > public voidonClick(View v) { > > > ((View)v.getParent().getParent()).setSelected(true); > > > } > > > }); > > > > And the corresponding XML look like : > > > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > > > android" > > > android:id="@+id/row_layout" > > > > > <LinearLayout android:id="@+id/row_checkbox_container"> > > > > <CheckBox android:id="@+id/row_checkbox" /> > > > > </LinearLayout> > > > > <LinearLayout android:id="@+id/item_title_container"> > > > > <TextView android:id="@+id/item_title"/> > > > > </LinearLayout> > > > > <LinearLayout android:id="@+id/right_arrow_container" > > > > > <ImageButton android:id="@+id/arrow" > > > android:layout_width="18px" > > > android:layout_height="fill_parent" > > > android:layout_gravity="bottom" > > > android:layout_weight="1" > > > android:src="@drawable/arrow" > > > android:background="#00000000"/> > > > > </LinearLayout> > > > > </LinearLayout> > > > > I got anullpointerexceptionright after running the app in the > > > emulator from eclipse on Ubuntu 8.10 : > > > > E/AndroidRuntime( 1426): java.lang.RuntimeException: Unable to start > > > activity ComponentInfo{com.getincontext/com.getincontext.InContext}: > > > java.lang.NullPointerException > > > E/AndroidRuntime( 1426): at > > > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > > > 2141) > > > E/AndroidRuntime( 1426): at > > > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: > > > 2157) > > > E/AndroidRuntime( 1426): at android.app.ActivityThread.access$1800 > > > (ActivityThread.java:112) > > > E/AndroidRuntime( 1426): at > > > android.app.ActivityThread$H.handleMessage > > > (ActivityThread.java:1581) > > > E/AndroidRuntime( 1426): at android.os.Handler.dispatchMessage > > > (Handler.java:88) > > > E/AndroidRuntime( 1426): at android.os.Looper.loop(Looper.java:123) > > > E/AndroidRuntime( 1426): at android.app.ActivityThread.main > > > (ActivityThread.java:3739) > > > E/AndroidRuntime( 1426): at java.lang.reflect.Method.invokeNative > > > (Native Method) > > > E/AndroidRuntime( 1426): at java.lang.reflect.Method.invoke > > > (Method.java:515) > > > E/AndroidRuntime( 1426): at com.android.internal.os.ZygoteInit > > > $MethodAndArgsCaller.run(ZygoteInit.java:739) > > > E/AndroidRuntime( 1426): at com.android.internal.os.ZygoteInit.main > > > (ZygoteInit.java:497) > > > E/AndroidRuntime( 1426): at dalvik.system.NativeStart.main(Native > > > Method) > > > E/AndroidRuntime( 1426): Caused by: java.lang.NullPointerException > > > E/AndroidRuntime( 1426): at com.getincontext.InContext.onCreate > > > (InContext.java:51) > > > E/AndroidRuntime( 1426): at > > > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: > > > 1122) > > > E/AndroidRuntime( 1426): at > > > android.app.ActivityThread.performLaunchActiv > > > > I searched in the other posts something similar, and It seems that it > > > must be because the ImageButton is set tonull. > > > > Unfortunately I can't find anything that would lead to it in the XML > > > or the Java code. The button is displayed properly and eclipse does > > > not detect any error. I guess this is runtime. > > > > I tried to cast from ImageButton to button but it doesn't change > > > anything. So I image the trouble is from findViewById(), but arrow to > > > exists, is a regular pgn file and is displayed by the emulator if this > > > line is commented. > > > > The weirdest is that I got a similar statement just above, and I can't > > > see any difference. > > > > Any clue ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---