当多次按下按钮时,我会强制关闭。我有一个条件,如果互联网连接,然后谷歌地图将显示。如果互联网没有连接,那么我保持一个警报框显示检查我们的互联网连接。所以问题出在这里。如果按下按钮时未连接互联网,则会显示警告框。但如果不止一次点击它会显示FORCE CLOSE。我已将警报框显示放在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)
答案 0 :(得分:0)
您不能多次显示警告对话框,因此请执行此类检查
首先创建一个类级变量
public boolean dialogShown = false;
然后在这里case R.id.geocode_button
if(!dialogShown){
dialogShown = true;
//Show your dialog
}
然后在对话框ok
按钮中点击listener
dialogShown = false;
<强>更新强>
检查您的网络连接
void boolean checkInternet(){
NetworkInfo i = conMgr.getActiveNetworkInfo();
if (i == null)
return false;
if (!i.isConnected())
return false;
if (!i.isAvailable())
return false;
return true;
}
答案 1 :(得分:0)
右。首先,这不是检查互联网连接是否可用的方法。但这不是问题所在。 第一个问题是CalledFromTheWrongThread异常,这意味着你正试图从另一个线程访问UI元素。不要那样做。我猜你有一个AsyncTask试图以一种不允许的方式发布一些更新。 (在com.journey.snoozer.ShowTheMap.mapProgress(ShowTheMap.java:143))
这里的主要问题是WindowLeaked异常几行。例如,当您退出某个活动然后尝试访问Dialog时,就会发生这种情况。 (方向更改等)由于您遇到了涉及AsyncTask的另一个异常,我想知道是否在IO异常发生时取消了第一个AsycTask。
因此,请确保在onPause()上的AsyncTask中使用.cancel(),并在任务创建的对话框上使用dissmiss()。