Re: [android-developers] Re: multiple buttons + dialog box
you need to use: Button3 = (Button) dialog.findViewById(R.id.button3); Button4 = (Button) dialog.findViewById(R.id.button4); Button5 = (Button) dialog.findViewById(R.id.button5); Button6 = (Button) dialog.findViewById(R.id.button6); because button 3-6 are in the layout of the dialog and not the activity, just calling findViewById will search for views in the activity's layout. I think this will fix your problem. Cheers, Chrigi On Wed, Feb 10, 2010 at 11:22 PM, André wrote: > Done! To the email in your profile. > > > > On Feb 10, 11:00 pm, Christoph Renner wrote: >> I cannot see the problem. Could you maybe send me (or upload) a zip >> file with the xml, java and Manifest files (or maybe the whole >> directory containing your project). >> >> Chrigi >> >> >> >> On Wed, Feb 10, 2010 at 10:43 PM, André wrote: >> > No problem, here it is: >> >> > http://schemas.android.com/apk/res/ >> > android" >> > android:orientation="vertical" >> > android:layout_width="fill_parent" >> > android:layout_height="fill_parent" >> > android:padding="10dp" > >> >> > > > android:id="@+id/button3" >> > android:text="@string/button3" >> > android:layout_width="110px" >> > android:layout_height="35px" >> > android:textSize="8pt" >> > android:layout_column="1" >> > android:layout_gravity="center" /> >> > > > android:id="@+id/button4" >> > android:text="@string/button4" >> > android:layout_width="110px" >> > android:layout_height="35px" >> > android:textSize="8pt" >> > android:layout_column="1" >> > android:layout_gravity="center" /> >> > > > android:id="@+id/button5" >> > android:text="@string/button5" >> > android:layout_width="110px" >> > android:layout_height="35px" >> > android:textSize="8pt" >> > android:layout_column="1" >> > android:layout_gravity="center" /> >> > > > android:id="@+id/button6" >> > android:text="@string/button6" >> > android:layout_width="110px" >> > android:layout_height="35px" >> > android:textSize="8pt" >> > android:layout_column="1" >> > android:layout_gravity="center" /> >> >> > >> >> > To me it looks right, but I am new to this. >> >> > On Feb 10, 10:03 pm, Christoph Renner wrote: >> >> Hi Andre >> >> >> On Wed, Feb 10, 2010 at 9:45 PM, André wrote: >> >> > Hi Chrigi, >> >> >> > except for for the id name and the string name the button is an exact >> >> > copy of button1 + 2. Eclipse accepts both popup_new and R.id.button3, >> >> > it turns the text blue. Doesn't that mean it has found them? >> >> >> That simply means that some view has id button3 and that there exists >> >> a layout popup_new.xml but it does not mean that popup_new.xml >> >> contains a view with id button3. >> >> >> > If I put // in front of the 4 buttons that doesn't seem to work the >> >> > popup >> >> > window works and the buttons show but nothing happens when you click >> >> > them of course. >> >> >> So this means that popup_new.xml contains 4 buttons. >> >> >> > I tried to make a new button and assigned it the same value as button >> >> > 1 and then after the findViewById for button3 I assigned it the value >> >> > of button3 and then the value was null. But you already knew that. >> >> >> > Then I tried to make a new xml file like popup_new but with a >> >> > different name, but still the same problem. I also tried to change the >> >> > name of the id in the xml file and myButtonTest1.java. >> >> >> > Do you think it could be R.layout.popup_new that is faulty or the >> >> > findviewbyid? >> >> >> That's hard to say, could you post popup_new.xml, (or at least the >> >> part with the 4 buttons). >> >> >> > André >> >> >> > On Feb 10, 8:47 pm, Christoph Renner wrote: >> >> >> Hi Andre >> >> >> >> from the logcat: >> >> >> >> 192): java.lang.NullPointerException >> >> >> E/AndroidRuntime( 192): at >> >> >> com.button.test1.ButtonTest1.onCreateDialog(ButtonTest1.java:90) >> >> >> >> This means that a NullPointerException was thrown at line 90 in >> >> >> ButtonTest1.java. This usually happens if you try to access use a >> >> >> reference which was null. If line 90 is >> >> >> button3.setOnClickListener(this); than button3 == null. findViewById >> >> >> returns null if the view with the given id is not found. Are you sure >> >> >> that in the layout of the dialog (R.layout.popup_new) a View with id >> >> >> button3 exists? >> >> >> >> Chrigi >> >> >> >> On Wed, Feb 10, 2010 at 7:
Re: [android-developers] Re: multiple buttons + dialog box
I cannot see the problem. Could you maybe send me (or upload) a zip file with the xml, java and Manifest files (or maybe the whole directory containing your project). Chrigi On Wed, Feb 10, 2010 at 10:43 PM, André wrote: > No problem, here it is: > > http://schemas.android.com/apk/res/ > android" > android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:padding="10dp" > > > android:id="@+id/button3" > android:text="@string/button3" > android:layout_width="110px" > android:layout_height="35px" > android:textSize="8pt" > android:layout_column="1" > android:layout_gravity="center" /> > android:id="@+id/button4" > android:text="@string/button4" > android:layout_width="110px" > android:layout_height="35px" > android:textSize="8pt" > android:layout_column="1" > android:layout_gravity="center" /> > android:id="@+id/button5" > android:text="@string/button5" > android:layout_width="110px" > android:layout_height="35px" > android:textSize="8pt" > android:layout_column="1" > android:layout_gravity="center" /> > android:id="@+id/button6" > android:text="@string/button6" > android:layout_width="110px" > android:layout_height="35px" > android:textSize="8pt" > android:layout_column="1" > android:layout_gravity="center" /> > > > > To me it looks right, but I am new to this. > > On Feb 10, 10:03 pm, Christoph Renner wrote: >> Hi Andre >> >> On Wed, Feb 10, 2010 at 9:45 PM, André wrote: >> > Hi Chrigi, >> >> > except for for the id name and the string name the button is an exact >> > copy of button1 + 2. Eclipse accepts both popup_new and R.id.button3, >> > it turns the text blue. Doesn't that mean it has found them? >> >> That simply means that some view has id button3 and that there exists >> a layout popup_new.xml but it does not mean that popup_new.xml >> contains a view with id button3. >> >> > If I put // in front of the 4 buttons that doesn't seem to work the popup >> > window works and the buttons show but nothing happens when you click >> > them of course. >> >> So this means that popup_new.xml contains 4 buttons. >> >> >> >> > I tried to make a new button and assigned it the same value as button >> > 1 and then after the findViewById for button3 I assigned it the value >> > of button3 and then the value was null. But you already knew that. >> >> > Then I tried to make a new xml file like popup_new but with a >> > different name, but still the same problem. I also tried to change the >> > name of the id in the xml file and myButtonTest1.java. >> >> > Do you think it could be R.layout.popup_new that is faulty or the >> > findviewbyid? >> >> That's hard to say, could you post popup_new.xml, (or at least the >> part with the 4 buttons). >> >> >> >> >> >> > André >> >> > On Feb 10, 8:47 pm, Christoph Renner wrote: >> >> Hi Andre >> >> >> from the logcat: >> >> >> 192): java.lang.NullPointerException >> >> E/AndroidRuntime( 192): at >> >> com.button.test1.ButtonTest1.onCreateDialog(ButtonTest1.java:90) >> >> >> This means that a NullPointerException was thrown at line 90 in >> >> ButtonTest1.java. This usually happens if you try to access use a >> >> reference which was null. If line 90 is >> >> button3.setOnClickListener(this); than button3 == null. findViewById >> >> returns null if the view with the given id is not found. Are you sure >> >> that in the layout of the dialog (R.layout.popup_new) a View with id >> >> button3 exists? >> >> >> Chrigi >> >> >> On Wed, Feb 10, 2010 at 7:38 PM, André wrote: >> >> > Ok, I think I got it. >> >> >> > Try this link, >> >> >http://www.andreborud.com/android/trace3.txt >> >> >> > On Feb 10, 3:34 pm, Christoph Renner wrote: >> >> >> It should look like the second example >> >> >> onhttp://youtrack.jetbrains.net/issue/IDEA-24746. If you run "adb >> >> >> logcat" this text should appear when your application crashes. >> >> >> >> On Wed, Feb 10, 2010 at 3:24 PM, André wrote: >> >> >> > I've never used logcat before but I think I got it right. Here is a >> >> >> > link to it: >> >> >> >> >http://www.andreborud.com/android/trace2.txt >> >> >> >> > Thanks >> >> >> >> > André >> >> >> >> > On Feb 10, 3:01 pm, Christoph Renner wrote: >> >> >> >> This is not really useful, could you use logcat (either in eclipse >> >> >> >> or >> >> >> >> by running adb logcat) to get to the stack trace which gives >>
Re: [android-developers] Re: multiple buttons + dialog box
Hi Andre On Wed, Feb 10, 2010 at 9:45 PM, André wrote: > Hi Chrigi, > > except for for the id name and the string name the button is an exact > copy of button1 + 2. Eclipse accepts both popup_new and R.id.button3, > it turns the text blue. Doesn't that mean it has found them? That simply means that some view has id button3 and that there exists a layout popup_new.xml but it does not mean that popup_new.xml contains a view with id button3. > If I put // in front of the 4 buttons that doesn't seem to work the popup > window works and the buttons show but nothing happens when you click > them of course. So this means that popup_new.xml contains 4 buttons. > > I tried to make a new button and assigned it the same value as button > 1 and then after the findViewById for button3 I assigned it the value > of button3 and then the value was null. But you already knew that. > > Then I tried to make a new xml file like popup_new but with a > different name, but still the same problem. I also tried to change the > name of the id in the xml file and myButtonTest1.java. > > Do you think it could be R.layout.popup_new that is faulty or the > findviewbyid? That's hard to say, could you post popup_new.xml, (or at least the part with the 4 buttons). > > André > > On Feb 10, 8:47 pm, Christoph Renner wrote: >> Hi Andre >> >> from the logcat: >> >> 192): java.lang.NullPointerException >> E/AndroidRuntime( 192): at >> com.button.test1.ButtonTest1.onCreateDialog(ButtonTest1.java:90) >> >> This means that a NullPointerException was thrown at line 90 in >> ButtonTest1.java. This usually happens if you try to access use a >> reference which was null. If line 90 is >> button3.setOnClickListener(this); than button3 == null. findViewById >> returns null if the view with the given id is not found. Are you sure >> that in the layout of the dialog (R.layout.popup_new) a View with id >> button3 exists? >> >> Chrigi >> >> >> >> On Wed, Feb 10, 2010 at 7:38 PM, André wrote: >> > Ok, I think I got it. >> >> > Try this link, >> >http://www.andreborud.com/android/trace3.txt >> >> > On Feb 10, 3:34 pm, Christoph Renner wrote: >> >> It should look like the second example >> >> onhttp://youtrack.jetbrains.net/issue/IDEA-24746. If you run "adb >> >> logcat" this text should appear when your application crashes. >> >> >> On Wed, Feb 10, 2010 at 3:24 PM, André wrote: >> >> > I've never used logcat before but I think I got it right. Here is a >> >> > link to it: >> >> >> >http://www.andreborud.com/android/trace2.txt >> >> >> > Thanks >> >> >> > André >> >> >> > On Feb 10, 3:01 pm, Christoph Renner wrote: >> >> >> This is not really useful, could you use logcat (either in eclipse or >> >> >> by running adb logcat) to get to the stack trace which gives >> >> >> information about the exception thrown? >> >> >> >> On Wed, Feb 10, 2010 at 2:54 PM, André wrote: >> >> >> > This is what I get on the InvocationTargetExce >> >> >> >> > // Compiled from InvocationTargetException.java (version 1.5 : 49.0, >> >> >> > super bit) >> >> >> > public class java.lang.reflect.InvocationTargetException extends >> >> >> > java.lang.Exception { >> >> >> >> > // Method descriptor #8 ()V >> >> >> > // Stack: 3, Locals: 1 >> >> >> > protected InvocationTargetException(); >> >> >> > 0 aload_0 [this] >> >> >> > 1 invokespecial java.lang.Exception() [1] >> >> >> > 4 new java.lang.RuntimeException [2] >> >> >> > 7 dup >> >> >> > 8 ldc [3] >> >> >> > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> >> >> > 13 athrow >> >> >> > Line numbers: >> >> >> > [pc: 0, line: 5] >> >> >> > Local variable table: >> >> >> > [pc: 0, pc: 14] local: this index: 0 type: >> >> >> > java.lang.reflect.InvocationTargetException >> >> >> >> > // Method descriptor #14 (Ljava/lang/Throwable;)V >> >> >> > // Stack: 3, Locals: 2 >> >> >> > public InvocationTargetException(java.lang.Throwable exception); >> >> >> > 0 aload_0 [this] >> >> >> > 1 invokespecial java.lang.Exception() [1] >> >> >> > 4 new java.lang.RuntimeException [2] >> >> >> > 7 dup >> >> >> > 8 ldc [3] >> >> >> > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> >> >> > 13 athrow >> >> >> > Line numbers: >> >> >> > [pc: 0, line: 6] >> >> >> > Local variable table: >> >> >> > [pc: 0, pc: 14] local: this index: 0 type: >> >> >> > java.lang.reflect.InvocationTargetException >> >> >> > [pc: 0, pc: 14] local: exception index: 1 type: >> >> >> > java.lang.Throwable >> >> >> >> > // Method descriptor #17 (Ljava/lang/Throwable;Ljava/lang/String;)V >> >> >> > // Stack: 3, Locals: 3 >> >> >> > public InvocationTargetException(java.lang.Throwable exception, >> >> >> > java.lang.String detailMessage); >> >> >> > 0 aload_0 [this] >> >> >> > 1 invokespecial java.lang.Exception() [1] >> >> >> > 4 new java.lang.RuntimeException [2] >> >> >> > 7
Re: [android-developers] Re: multiple buttons + dialog box
Hi Andre from the logcat: 192): java.lang.NullPointerException E/AndroidRuntime( 192):at com.button.test1.ButtonTest1.onCreateDialog(ButtonTest1.java:90) This means that a NullPointerException was thrown at line 90 in ButtonTest1.java. This usually happens if you try to access use a reference which was null. If line 90 is button3.setOnClickListener(this); than button3 == null. findViewById returns null if the view with the given id is not found. Are you sure that in the layout of the dialog (R.layout.popup_new) a View with id button3 exists? Chrigi On Wed, Feb 10, 2010 at 7:38 PM, André wrote: > Ok, I think I got it. > > Try this link, > http://www.andreborud.com/android/trace3.txt > > > > On Feb 10, 3:34 pm, Christoph Renner wrote: >> It should look like the second example >> onhttp://youtrack.jetbrains.net/issue/IDEA-24746. If you run "adb >> logcat" this text should appear when your application crashes. >> >> >> >> On Wed, Feb 10, 2010 at 3:24 PM, André wrote: >> > I've never used logcat before but I think I got it right. Here is a >> > link to it: >> >> >http://www.andreborud.com/android/trace2.txt >> >> > Thanks >> >> > André >> >> > On Feb 10, 3:01 pm, Christoph Renner wrote: >> >> This is not really useful, could you use logcat (either in eclipse or >> >> by running adb logcat) to get to the stack trace which gives >> >> information about the exception thrown? >> >> >> On Wed, Feb 10, 2010 at 2:54 PM, André wrote: >> >> > This is what I get on the InvocationTargetExce >> >> >> > // Compiled from InvocationTargetException.java (version 1.5 : 49.0, >> >> > super bit) >> >> > public class java.lang.reflect.InvocationTargetException extends >> >> > java.lang.Exception { >> >> >> > // Method descriptor #8 ()V >> >> > // Stack: 3, Locals: 1 >> >> > protected InvocationTargetException(); >> >> > 0 aload_0 [this] >> >> > 1 invokespecial java.lang.Exception() [1] >> >> > 4 new java.lang.RuntimeException [2] >> >> > 7 dup >> >> > 8 ldc [3] >> >> > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> >> > 13 athrow >> >> > Line numbers: >> >> > [pc: 0, line: 5] >> >> > Local variable table: >> >> > [pc: 0, pc: 14] local: this index: 0 type: >> >> > java.lang.reflect.InvocationTargetException >> >> >> > // Method descriptor #14 (Ljava/lang/Throwable;)V >> >> > // Stack: 3, Locals: 2 >> >> > public InvocationTargetException(java.lang.Throwable exception); >> >> > 0 aload_0 [this] >> >> > 1 invokespecial java.lang.Exception() [1] >> >> > 4 new java.lang.RuntimeException [2] >> >> > 7 dup >> >> > 8 ldc [3] >> >> > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> >> > 13 athrow >> >> > Line numbers: >> >> > [pc: 0, line: 6] >> >> > Local variable table: >> >> > [pc: 0, pc: 14] local: this index: 0 type: >> >> > java.lang.reflect.InvocationTargetException >> >> > [pc: 0, pc: 14] local: exception index: 1 type: >> >> > java.lang.Throwable >> >> >> > // Method descriptor #17 (Ljava/lang/Throwable;Ljava/lang/String;)V >> >> > // Stack: 3, Locals: 3 >> >> > public InvocationTargetException(java.lang.Throwable exception, >> >> > java.lang.String detailMessage); >> >> > 0 aload_0 [this] >> >> > 1 invokespecial java.lang.Exception() [1] >> >> > 4 new java.lang.RuntimeException [2] >> >> > 7 dup >> >> > 8 ldc [3] >> >> > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> >> > 13 athrow >> >> > Line numbers: >> >> > [pc: 0, line: 7] >> >> > Local variable table: >> >> > [pc: 0, pc: 14] local: this index: 0 type: >> >> > java.lang.reflect.InvocationTargetException >> >> > [pc: 0, pc: 14] local: exception index: 1 type: >> >> > java.lang.Throwable >> >> > [pc: 0, pc: 14] local: detailMessage index: 2 type: >> >> > java.lang.String >> >> >> > // Method descriptor #21 ()Ljava/lang/Throwable; >> >> > // Stack: 3, Locals: 1 >> >> > public java.lang.Throwable getTargetException(); >> >> > 0 new java.lang.RuntimeException [2] >> >> > 3 dup >> >> > 4 ldc [3] >> >> > 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> >> > 9 athrow >> >> > Line numbers: >> >> > [pc: 0, line: 8] >> >> > Local variable table: >> >> > [pc: 0, pc: 10] local: this index: 0 type: >> >> > java.lang.reflect.InvocationTargetException >> >> >> > // Method descriptor #21 ()Ljava/lang/Throwable; >> >> > // Stack: 3, Locals: 1 >> >> > public java.lang.Throwable getCause(); >> >> > 0 new java.lang.RuntimeException [2] >> >> > 3 dup >> >> > 4 ldc [3] >> >> > 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> >> > 9 athrow >> >> > Line numbers: >> >> > [pc: 0, line: 9] >> >> > Local variable table: >> >> > [pc: 0, pc: 10] local: this index: 0 type: >> >> >
Re: [android-developers] Re: multiple buttons + dialog box
Salam I am trying to used the android emulator services except maps please tell me if any one know Thanx kamran Manzoor Student of FAST_NU -- 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
Re: [android-developers] Re: multiple buttons + dialog box
It should look like the second example on http://youtrack.jetbrains.net/issue/IDEA-24746 . If you run "adb logcat" this text should appear when your application crashes. On Wed, Feb 10, 2010 at 3:24 PM, André wrote: > I've never used logcat before but I think I got it right. Here is a > link to it: > > http://www.andreborud.com/android/trace2.txt > > Thanks > > André > > On Feb 10, 3:01 pm, Christoph Renner wrote: >> This is not really useful, could you use logcat (either in eclipse or >> by running adb logcat) to get to the stack trace which gives >> information about the exception thrown? >> >> >> >> On Wed, Feb 10, 2010 at 2:54 PM, André wrote: >> > This is what I get on the InvocationTargetExce >> >> > // Compiled from InvocationTargetException.java (version 1.5 : 49.0, >> > super bit) >> > public class java.lang.reflect.InvocationTargetException extends >> > java.lang.Exception { >> >> > // Method descriptor #8 ()V >> > // Stack: 3, Locals: 1 >> > protected InvocationTargetException(); >> > 0 aload_0 [this] >> > 1 invokespecial java.lang.Exception() [1] >> > 4 new java.lang.RuntimeException [2] >> > 7 dup >> > 8 ldc [3] >> > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> > 13 athrow >> > Line numbers: >> > [pc: 0, line: 5] >> > Local variable table: >> > [pc: 0, pc: 14] local: this index: 0 type: >> > java.lang.reflect.InvocationTargetException >> >> > // Method descriptor #14 (Ljava/lang/Throwable;)V >> > // Stack: 3, Locals: 2 >> > public InvocationTargetException(java.lang.Throwable exception); >> > 0 aload_0 [this] >> > 1 invokespecial java.lang.Exception() [1] >> > 4 new java.lang.RuntimeException [2] >> > 7 dup >> > 8 ldc [3] >> > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> > 13 athrow >> > Line numbers: >> > [pc: 0, line: 6] >> > Local variable table: >> > [pc: 0, pc: 14] local: this index: 0 type: >> > java.lang.reflect.InvocationTargetException >> > [pc: 0, pc: 14] local: exception index: 1 type: >> > java.lang.Throwable >> >> > // Method descriptor #17 (Ljava/lang/Throwable;Ljava/lang/String;)V >> > // Stack: 3, Locals: 3 >> > public InvocationTargetException(java.lang.Throwable exception, >> > java.lang.String detailMessage); >> > 0 aload_0 [this] >> > 1 invokespecial java.lang.Exception() [1] >> > 4 new java.lang.RuntimeException [2] >> > 7 dup >> > 8 ldc [3] >> > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> > 13 athrow >> > Line numbers: >> > [pc: 0, line: 7] >> > Local variable table: >> > [pc: 0, pc: 14] local: this index: 0 type: >> > java.lang.reflect.InvocationTargetException >> > [pc: 0, pc: 14] local: exception index: 1 type: >> > java.lang.Throwable >> > [pc: 0, pc: 14] local: detailMessage index: 2 type: >> > java.lang.String >> >> > // Method descriptor #21 ()Ljava/lang/Throwable; >> > // Stack: 3, Locals: 1 >> > public java.lang.Throwable getTargetException(); >> > 0 new java.lang.RuntimeException [2] >> > 3 dup >> > 4 ldc [3] >> > 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> > 9 athrow >> > Line numbers: >> > [pc: 0, line: 8] >> > Local variable table: >> > [pc: 0, pc: 10] local: this index: 0 type: >> > java.lang.reflect.InvocationTargetException >> >> > // Method descriptor #21 ()Ljava/lang/Throwable; >> > // Stack: 3, Locals: 1 >> > public java.lang.Throwable getCause(); >> > 0 new java.lang.RuntimeException [2] >> > 3 dup >> > 4 ldc [3] >> > 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] >> > 9 athrow >> > Line numbers: >> > [pc: 0, line: 9] >> > Local variable table: >> > [pc: 0, pc: 10] local: this index: 0 type: >> > java.lang.reflect.InvocationTargetException >> > } >> >> > And when I run the program on the emulator it starts, but when I press >> > button 1 that opens the dialog it has to force shut down. >> >> > Any suggestions? >> >> > On Feb 10, 2:43 pm, Christoph Renner wrote: >> >> What exactly is the problem? Is there a compiler error or is an >> >> exception thrown when executing? In both cases, an error message might >> >> be useful. >> >> >> Cheers, >> >> Chrigi >> >> >> On Wed, Feb 10, 2010 at 2:39 PM, André wrote: >> >> > Thanks for you reply Chrigi! >> >> >> > I tried what you suggested but the problem still looks exactly the >> >> > same. Would you happen to have any other suggestions? >> >> >> > Cheers >> >> > André >> >> >> > On Feb 10, 2:01 pm, Christoph Renner wrote: >> >> >> Hi Andre >> >> >> >> I assume that buton 3-6 are in R.layout.poput_new and not >> >> >> R.layout.main, in that case you call findViewById on the activity >> >> >> which does not contain those buttons. You need to call findViewById on >> >> >> the dialog after
Re: [android-developers] Re: multiple buttons + dialog box
This is not really useful, could you use logcat (either in eclipse or by running adb logcat) to get to the stack trace which gives information about the exception thrown? On Wed, Feb 10, 2010 at 2:54 PM, André wrote: > This is what I get on the InvocationTargetExce > > // Compiled from InvocationTargetException.java (version 1.5 : 49.0, > super bit) > public class java.lang.reflect.InvocationTargetException extends > java.lang.Exception { > > // Method descriptor #8 ()V > // Stack: 3, Locals: 1 > protected InvocationTargetException(); > 0 aload_0 [this] > 1 invokespecial java.lang.Exception() [1] > 4 new java.lang.RuntimeException [2] > 7 dup > 8 ldc [3] > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] > 13 athrow > Line numbers: > [pc: 0, line: 5] > Local variable table: > [pc: 0, pc: 14] local: this index: 0 type: > java.lang.reflect.InvocationTargetException > > // Method descriptor #14 (Ljava/lang/Throwable;)V > // Stack: 3, Locals: 2 > public InvocationTargetException(java.lang.Throwable exception); > 0 aload_0 [this] > 1 invokespecial java.lang.Exception() [1] > 4 new java.lang.RuntimeException [2] > 7 dup > 8 ldc [3] > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] > 13 athrow > Line numbers: > [pc: 0, line: 6] > Local variable table: > [pc: 0, pc: 14] local: this index: 0 type: > java.lang.reflect.InvocationTargetException > [pc: 0, pc: 14] local: exception index: 1 type: > java.lang.Throwable > > // Method descriptor #17 (Ljava/lang/Throwable;Ljava/lang/String;)V > // Stack: 3, Locals: 3 > public InvocationTargetException(java.lang.Throwable exception, > java.lang.String detailMessage); > 0 aload_0 [this] > 1 invokespecial java.lang.Exception() [1] > 4 new java.lang.RuntimeException [2] > 7 dup > 8 ldc [3] > 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] > 13 athrow > Line numbers: > [pc: 0, line: 7] > Local variable table: > [pc: 0, pc: 14] local: this index: 0 type: > java.lang.reflect.InvocationTargetException > [pc: 0, pc: 14] local: exception index: 1 type: > java.lang.Throwable > [pc: 0, pc: 14] local: detailMessage index: 2 type: > java.lang.String > > // Method descriptor #21 ()Ljava/lang/Throwable; > // Stack: 3, Locals: 1 > public java.lang.Throwable getTargetException(); > 0 new java.lang.RuntimeException [2] > 3 dup > 4 ldc [3] > 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] > 9 athrow > Line numbers: > [pc: 0, line: 8] > Local variable table: > [pc: 0, pc: 10] local: this index: 0 type: > java.lang.reflect.InvocationTargetException > > // Method descriptor #21 ()Ljava/lang/Throwable; > // Stack: 3, Locals: 1 > public java.lang.Throwable getCause(); > 0 new java.lang.RuntimeException [2] > 3 dup > 4 ldc [3] > 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] > 9 athrow > Line numbers: > [pc: 0, line: 9] > Local variable table: > [pc: 0, pc: 10] local: this index: 0 type: > java.lang.reflect.InvocationTargetException > } > > And when I run the program on the emulator it starts, but when I press > button 1 that opens the dialog it has to force shut down. > > Any suggestions? > > On Feb 10, 2:43 pm, Christoph Renner wrote: >> What exactly is the problem? Is there a compiler error or is an >> exception thrown when executing? In both cases, an error message might >> be useful. >> >> Cheers, >> Chrigi >> >> >> >> On Wed, Feb 10, 2010 at 2:39 PM, André wrote: >> > Thanks for you reply Chrigi! >> >> > I tried what you suggested but the problem still looks exactly the >> > same. Would you happen to have any other suggestions? >> >> > Cheers >> > André >> >> > On Feb 10, 2:01 pm, Christoph Renner wrote: >> >> Hi Andre >> >> >> I assume that buton 3-6 are in R.layout.poput_new and not >> >> R.layout.main, in that case you call findViewById on the activity >> >> which does not contain those buttons. You need to call findViewById on >> >> the dialog after you called setContentView. >> >> >> Try the following: >> >> >> in onCreate: >> >> remove the following lines >> >> button3 = (Button) findViewById(R.id.button3); >> >> button4 = (Button) findViewById(R.id.button4); >> >> button5 = (Button) findViewById(R.id.button5); >> >> button6 = (Button) findViewById(R.id.button5); // typo at >> >> this line, should probably be R.id.button6 >> >> >> in onCreateDialog: >> >> add the following lined just before "button3.setOnClickListener(this);" >> >> button3 = (Button) dialog.findViewById(R.id.button3); >> >> button4 = (Button) dialog.findViewById(R.id.button4); >> >> button5 = (Button) dialog.findViewById(R.id.button5); >> >>
Re: [android-developers] Re: multiple buttons + dialog box
What exactly is the problem? Is there a compiler error or is an exception thrown when executing? In both cases, an error message might be useful. Cheers, Chrigi On Wed, Feb 10, 2010 at 2:39 PM, André wrote: > Thanks for you reply Chrigi! > > I tried what you suggested but the problem still looks exactly the > same. Would you happen to have any other suggestions? > > Cheers > André > > On Feb 10, 2:01 pm, Christoph Renner wrote: >> Hi Andre >> >> I assume that buton 3-6 are in R.layout.poput_new and not >> R.layout.main, in that case you call findViewById on the activity >> which does not contain those buttons. You need to call findViewById on >> the dialog after you called setContentView. >> >> Try the following: >> >> in onCreate: >> remove the following lines >> button3 = (Button) findViewById(R.id.button3); >> button4 = (Button) findViewById(R.id.button4); >> button5 = (Button) findViewById(R.id.button5); >> button6 = (Button) findViewById(R.id.button5); // typo at >> this line, should probably be R.id.button6 >> >> in onCreateDialog: >> add the following lined just before "button3.setOnClickListener(this);" >> button3 = (Button) dialog.findViewById(R.id.button3); >> button4 = (Button) dialog.findViewById(R.id.button4); >> button5 = (Button) dialog.findViewById(R.id.button5); >> button6 = (Button) dialog.findViewById(R.id.button6); >> >> Cheers, >> Chrigi >> >> >> >> On Wed, Feb 10, 2010 at 1:28 PM, André wrote: >> > Hello, >> >> > I am trying to use 6 buttons in one activity. The first 2 buttons >> > work, but the problem is the 4 other ones that are located in a dialog >> > box. For the first two buttons I use >> > "button1.setOnClickListener(this);" which is placed in the oncreate >> > method. For the other 4 buttons I thought I could use the same line >> > but place it in the Dialog method. But I was wrong. I this it's the >> > (this) that is wrong. Bellow is my code and I have marked the line >> > where eclipse debug reacts. Or maybe you pro's see some thing else >> > that I did totally wrong? >> >> > regards >> > André >> >> > ... >> > public class ButtonTest1 extends Activity implements OnClickListener { >> > static final int DIALOG_NEW = 0; >> > private Button button1; >> > private Button button2; >> > private Button button3; >> > private Button button4; >> > private Button button5; >> > private Button button6; >> >> > /** Called when the activity is first created. */ >> > �...@override >> > public void onCreate(Bundle savedInstanceState) { >> > super.onCreate(savedInstanceState); >> > setContentView(R.layout.main); >> > button1 = (Button) findViewById(R.id.button1); >> > button2 = (Button) findViewById(R.id.button2); >> > button3 = (Button) findViewById(R.id.button3); >> > button4 = (Button) findViewById(R.id.button4); >> > button5 = (Button) findViewById(R.id.button5); >> > button6 = (Button) findViewById(R.id.button5); >> >> > button1.setOnClickListener(this); >> > button2.setOnClickListener(this); >> >> > } >> > public void onClick(View view) { >> > switch (view.getId()) { >> > case R.id.button1: >> > showDialog(DIALOG1); >> > break; >> > case R.id.button2: >> >> > break; >> > case R.id.button3: >> >> > break; >> > case R.id.button4: >> >> > break; >> > case R.id.button5: >> >> > break; >> > case R.id.button6: >> >> > break; >> > } >> > } >> > protected Dialog onCreateDialog(int id) { >> > Dialog dialog = new Dialog(this); >> > switch(id) { >> > case DIALOG_NEW: >> > dialog.setContentView(R.layout.popup_new); >> > dialog.setTitle("Choose button..."); >> >> > button3.setOnClickListener(this); >> > <--problem starts >> > here when dialog box opens >> > button4.setOnClickListener(this); >> > button5.setOnClickListener(this); >> > button6.setOnClickListener(this); >> >> > break; >> >> > default: >> > dialog = null; >> > } >> > return dialog; >> > } >> > ... >> >> > -- >> > 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 > > -- > You received this message because you are subscribed to the G