多次按下按钮时,我会强制关闭。我有一个条件,比如如果连接了互联网,那么将显示谷歌地图。如果没有连接互联网,那么我会一直显示警报框以检查我们的互联网连接。所以问题就在这里。如果在按下按钮一次时未连接互联网,则会显示警报框。但是,如果多次单击它会显示强制关闭。我已将警报框显示放置在 catch 块中。
case R.id.geocode_button: // Place name as selected by the user.
placeName = placeText.getText().toString();
clik=1;
placenametemp = placeName;
System.out.println(""+placenametemp);
String [] optionArray = new String[numberOptions];
Geocoder gcoder = new Geocoder(this);
try
{
///// code to display google map
}
catch (IOException e)
{
if(!dialogShown)
{
dialogShown = true;
//Show your dialog
new
AlertDialog.Builder(this).setIcon(R.drawable.icon).setTitle(
" Check your Internet
Connection!").setPositiveButton("OK",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog,
int which)
{
dialogShown = false;
// TODO Auto-generated method stub
dialog.cancel();
}
}).show();
Log.e("Geocoder", "I/O Failure; is network
available?",e);
}
}
//The LOG cat details :
12-10 18:31:09.506: E/Geocoder(238): I/O Failure; is network available?
12-10 18:31:09.506: E/Geocoder(238): java.io.IOException: Unable to parse response from server
12-10 18:31:09.506: E/Geocoder(238): at android.location.Geocoder.getFromLocationName(Geocoder.java:166)
12-10 18:31:09.506: E/Geocoder(238): at com.journey.snoozer.Mapper.onClick(Mapper.java:93)
12-10 18:31:09.506: E/Geocoder(238): at android.view.View.performClick(View.java:2364)
12-10 18:31:09.506: E/Geocoder(238): at android.view.View.onTouchEvent(View.java:4179)
12-10 18:31:09.506: E/Geocoder(238): at android.widget.TextView.onTouchEvent(TextView.java:6540)
12-10 18:31:09.506: E/Geocoder(238): at android.view.View.dispatchTouchEvent(View.java:3709)
12-10 18:31:09.506: E/Geocoder(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:09.506: E/Geocoder(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:09.506: E/Geocoder(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:09.506: E/Geocoder(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:09.506: E/Geocoder(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:09.506: E/Geocoder(238): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
12-10 18:31:09.506: E/Geocoder(238): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
12-10 18:31:09.506: E/Geocoder(238): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
12-10 18:31:09.506: E/Geocoder(238): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
12-10 18:31:09.506: E/Geocoder(238): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
12-10 18:31:09.506: E/Geocoder(238): at android.os.Handler.dispatchMessage(Handler.java:99)
12-10 18:31:09.506: E/Geocoder(238): at android.os.Looper.loop(Looper.java:123)
12-10 18:31:09.506: E/Geocoder(238): at android.app.ActivityThread.main(ActivityThread.java:4363)
12-10 18:31:09.506: E/Geocoder(238): at java.lang.reflect.Method.invokeNative(Native Method)
12-10 18:31:09.506: E/Geocoder(238): at java.lang.reflect.Method.invoke(Method.java:521)
12-10 18:31:09.506: E/Geocoder(238): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-10 18:31:09.506: E/Geocoder(238): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-10 18:31:09.506: E/Geocoder(238): at dalvik.system.NativeStart.main(Native Method)
12-10 18:31:10.277: E/ActivityThread(238): Failed to find provider info for com.google.settings
12-10 18:31:10.296: E/ActivityThread(238): Failed to find provider info for com.google.settings
12-10 18:31:10.426: E/ActivityThread(238): Failed to find provider info for com.google.settings
12-10 18:31:11.626: I/MapActivity(238): Handling network change notification:CONNECTED
12-10 18:31:11.626: E/MapActivity(238): Couldn't get connection factory client
12-10 18:31:11.926: D/dalvikvm(238): GC freed 3247 objects / 233880 bytes in 241ms
12-10 18:31:11.936: E/DEBUGTAG(238): Remote Image Exception
12-10 18:31:11.936: E/DEBUGTAG(238): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
12-10 18:31:11.936: E/DEBUGTAG(238): at android.view.ViewRoot.checkThread(ViewRoot.java:2683)
12-10 18:31:11.936: E/DEBUGTAG(238): at android.view.ViewRoot.requestLayout(ViewRoot.java:557)
12-10 18:31:11.936: E/DEBUGTAG(238): at android.view.View.requestLayout(View.java:7918)
12-10 18:31:11.936: E/DEBUGTAG(238): at android.view.View.requestLayout(View.java:7918)
12-10 18:31:11.936: E/DEBUGTAG(238): at android.view.View.requestLayout(View.java:7918)
12-10 18:31:11.936: E/DEBUGTAG(238): at android.view.ViewGroup.removeAllViews(ViewGroup.java:2146)
12-10 18:31:11.936: E/DEBUGTAG(238): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:196)
12-10 18:31:11.936: E/DEBUGTAG(238): at android.app.Activity.setContentView(Activity.java:1622)
12-10 18:31:11.936: E/DEBUGTAG(238): at com.journey.snoozer.ShowTheMap.mapProgress(ShowTheMap.java:143)
12-10 18:31:11.936: E/DEBUGTAG(238): at com.journey.snoozer.ShowTheMap$loadImageTask.doInBackground(ShowTheMap.java:197)
12-10 18:31:11.936: E/DEBUGTAG(238): at com.journey.snoozer.ShowTheMap$loadImageTask.doInBackground(ShowTheMap.java:1)
12-10 18:31:11.936: E/DEBUGTAG(238): at android.os.AsyncTask$2.call(AsyncTask.java:185)
12-10 18:31:11.936: E/DEBUGTAG(238): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-10 18:31:11.936: E/DEBUGTAG(238): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-10 18:31:11.936: E/DEBUGTAG(238): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
12-10 18:31:11.936: E/DEBUGTAG(238): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
12-10 18:31:11.936: E/DEBUGTAG(238): at java.lang.Thread.run(Thread.java:1096)
12-10 18:31:12.756: D/dalvikvm(238): GC freed 7692 objects / 597720 bytes in 68ms
12-10 18:31:12.886: D/dalvikvm(238): GC freed 5342 objects / 404384 bytes in 62ms
12-10 18:31:13.296: E/WindowManager(238): Activity com.journey.snoozer.Mapper has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44ea2bc8 that was originally added here
12-10 18:31:13.296: E/WindowManager(238): android.view.WindowLeaked: Activity com.journey.snoozer.Mapper has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44ea2bc8 that was originally added here
12-10 18:31:13.296: E/WindowManager(238): at android.view.ViewRoot.<init>(ViewRoot.java:227)
12-10 18:31:13.296: E/WindowManager(238): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
12-10 18:31:13.296: E/WindowManager(238): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
12-10 18:31:13.296: E/WindowManager(238): at android.view.Window$LocalWindowManager.addView(Window.java:424)
12-10 18:31:13.296: E/WindowManager(238): at android.app.Dialog.show(Dialog.java:239)
12-10 18:31:13.296: E/WindowManager(238): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
12-10 18:31:13.296: E/WindowManager(238): at com.journey.snoozer.Mapper.onClick(Mapper.java:141)
12-10 18:31:13.296: E/WindowManager(238): at android.view.View.performClick(View.java:2364)
12-10 18:31:13.296: E/WindowManager(238): at android.view.View.onTouchEvent(View.java:4179)
12-10 18:31:13.296: E/WindowManager(238): at android.widget.TextView.onTouchEvent(TextView.java:6540)
12-10 18:31:13.296: E/WindowManager(238): at android.view.View.dispatchTouchEvent(View.java:3709)
12-10 18:31:13.296: E/WindowManager(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:13.296: E/WindowManager(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:13.296: E/WindowManager(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:13.296: E/WindowManager(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:13.296: E/WindowManager(238): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-10 18:31:13.296: E/WindowManager(238): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
12-10 18:31:13.296: E/WindowManager(238): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
12-10 18:31:13.296: E/WindowManager(238): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
12-10 18:31:13.296: E/WindowManager(238): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
12-10 18:31:13.296: E/WindowManager(238): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
12-10 18:31:13.296: E/WindowManager(238): at android.os.Handler.dispatchMessage(Handler.java:99)
12-10 18:31:13.296: E/WindowManager(238): at android.os.Looper.loop(Looper.java:123)
12-10 18:31:13.296: E/WindowManager(238): at android.app.ActivityThread.main(ActivityThread.java:4363)
12-10 18:31:13.296: E/WindowManager(238): at java.lang.reflect.Method.invokeNative(Native Method)
12-10 18:31:13.296: E/WindowManager(238): at java.lang.reflect.Method.invoke(Method.java:521)
12-10 18:31:13.296: E/WindowManager(238): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-10 18:31:13.296: E/WindowManager(238): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-10 18:31:13.296: E/WindowManager(238): at dalvik.system.NativeStart.main(Native Method)