如果由于某种原因没有互联网连接或请求失败,应用程序在呼叫时崩溃:
GSAPI.getInstance().initialize(this, GIGYA_API_KEY);
问题是:是否有某种方法可以捕获异常? (java.net.SocketTimeoutException和java.util.ConcurrentModificationException)
跟踪:
08-19 17:53:22.971 2062-2062/************ E/GSAPI﹕ Unable to load config from server:*********** GSResponse Log ***********
apiKey: ************
userKey: apiMethod: getSDKConfig
params: {"enabledProviders":"","ucid":"************","sdk":"android_3.1","format":"json","targetEnv":"mobile","apiKey":"************","include":"permissions"}
useHTTPS: false
sdk: android_3.1
post_data: apiKey=************&enabledProviders=&format=json&httpStatusCodes=false&include=permissions&sdk=android_3.1&targetEnv=mobile&ucid=************&
url: http://socialize.us1.gigya.com/socialize.getSDKConfig
java.net.SocketTimeoutException: failed to connect to socialize.us1.gigya.com/23.12.180.171 (port 80) after 5000ms
at libcore.io.IoBridge.connectErrno(IoBridge.java:159)
at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
at java.net.Socket.connect(Socket.java:843)
at com.android.okhttp.internal.Platform.connectSocket(Platform.java:131)
at com.android.okhttp.Connection.connect(Connection.java:101)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:179)
at com.gigya.socialize.GSRequest.sendRequest(Unknown Source)
at com.gigya.socialize.GSRequest.send(Unknown Source)
at ************.GSAsyncRequest$GSRequestTask.doInBackground(Unknown Source)
at ************.GSAsyncRequest$GSRequestTask.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
08-19 17:53:22.971 2062-2062/************ D/AndroidRuntime﹕ Shutting down VM
08-19 17:53:22.981 2062-2062/************ W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0d6db20)
08-19 17:53:26.011 2062-2062/************ E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: ************, PID: 2062
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
at java.util.HashMap$KeyIterator.next(HashMap.java:833)
at com.gigya.socialize.android.login.LoginProviderFactory.validatePermissions(Unknown Source)
at com.gigya.socialize.android.GSAPI$10.onGSResponse(Unknown Source)
at com.gigya.socialize.android.GSAsyncRequest$1.onGSResponse(Unknown Source)
at com.gigya.socialize.android.GSAsyncRequest$GSRequestTask.onPostExecute(Unknown Source)
at com.gigya.socialize.android.GSAsyncRequest$GSRequestTask.onPostExecute(Unknown Source)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
Gigya在即将发布的补丁中有针对此计划的错误修复。当您等待修补程序更正此错误时,您可以通过downloading it自行修补Gigya移动SDK,并在下面进行更改并重新编译:
<强> ./主/ JAVA / COM /的Gigya /社交/机器人/登录/ LoginProviderFactory.java 强>
后
import java.util.Hashmap;
添加的
import java.util.concurrent.ConcurrentHashMap;
替换的
private HashMap<String, LoginProvider> providers = new HashMap<String, LoginProvider>();
用的
private ConcurrentHashMap<String, LoginProvider> providers = new ConcurrentHashMap<String, LoginProvider>();
替换的
public HashMap<String, LoginProvider> getLoginProviders() {
return providers;
}
用的
public HashMap<String, LoginProvider> getLoginProviders() {
return new HashMap<String, LoginProvider>(providers);
}