There is a strange bug in my code that wasted my whole night and I
still couldn't find where the real problem is.
Basically, I have a tabhost and many tabviews in it, each is a
separate activity.
When I launch a dialog from the first tabview activity, everything was
fine, a dialog pop up and when I click OK, it functions to switch me
into another tabview (activity 2).
But the problem is: when I try to launch another dialog within the
second tabview (activity 2), simulator crashed and throwed an
IllegalStateException.
The second used exactly the same way to show dialog as the first
activity:
public void OKClicked(View v) {
showDialog(2);}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 2:
return new AlertDialog.Builder(this)
.setTitle("Gift Card Value: $" +
getCardValue())
.setMessage(
"Send Message: "
+
aq.id(R.id.send_gift_message).getText()
+
"\n\nto: "
+
aq.id(R.id.send_email).getText())
.setPositiveButton("Confirm",
new
DialogInterface.OnClickListener() {
public void
onClick(DialogInterface dialog,
int which) {
postToServer();
}
})
.setNegativeButton("Cancel",
new
DialogInterface.OnClickListener() {
public void
onClick(DialogInterface dialog,
int which) {
// No
need to write anything here.
}
}).create();
}
return null;
}
(I used Android Query for "aq" but I believe it is not the problem
because I tried not to use but stall got the same exception)
I also tried a slightly different code:
public void OKClicked(View v) {
new AlertDialog.Builder(getParent())
.setTitle("Gift Card Value: $" + getCardValue())
.setMessage(
"Send Message: "
+
aq.id(R.id.send_gift_message).getText()
+ "\n\nto: "
+
aq.id(R.id.send_email).getText())
.setPositiveButton("Confirm",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface
dialog,
int which) {
postToServer();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface
dialog,
int which) {
// No need to write anything
here.
}
}).create().show();
}
but still got the same problem.
[Debug]
Thread [<1> main] (Suspended (exception IllegalStateException))
View$1.onClick(View) line: 3031
Button(View).performClick() line: 3511
View$PerformClick.run() line: 14105
ViewRootImpl(Handler).handleCallback(Message) line: 605
ViewRootImpl(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 137
ActivityThread.main(String[]) line: 4424
Method.invokeNative(Object, Object[], Class, Class[], Class, int,
boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 784
ZygoteInit.main(String[]) line: 551
NativeStart.main(String[]) line: not available [native method]
I also posted the question on stackoverflow.
If you prefer to answer there:
http://stackoverflow.com/questions/9215367/showdialog-throws-illegalstateexception-in-android
Please help me... Thanks!!!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en