1
我使用HTC Explorer A310e出現此錯誤,但它與其他設備正常工作。什麼是真正的問題?當使用Gson時,應用程序崩潰HTC Explorer A310e
03-25 12:23:37.553: ERROR/EmbeddedLogger(178): App crashed! Process: com.consors.android.de
03-25 12:23:37.553: ERROR/EmbeddedLogger(178): App crashed! Package: com.consors.android.de v4 (1.0.3.9)
03-25 12:23:37.553: ERROR/EmbeddedLogger(178): Error getting package label: com.consors.android.de
java.lang.NullPointerException
at com.htc.server.embedded.EmbeddedLogger.onHandleApplicationCrash(EmbeddedLogger.java:59)
at com.android.server.am.ActivityManagerService.handleApplicationCrash(ActivityManagerService.java:7739)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:1033)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1657)
at android.os.Binder.execTransact(Binder.java:320)
at dalvik.system.NativeStart.run(Native Method)
03-25 12:23:37.553: ERROR/EmbeddedLogger(178): Application Label: <ERROR>
03-25 12:23:37.553: ERROR/AndroidRuntime(538): FATAL EXCEPTION: main
java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.registerTypeAdapterFactory
at com.consors.android.auxilary.GsonRequestResponseHandler.getInstance(GsonRequestResponseHandler.java:26)
at com.consors.android.ui.watchlist.WebWatchList.subscribeWatchListsUrlRequest(WebWatchList.java:293)
at com.consors.android.ui.AbsSnapShotActivity.sendWatchListRequest(AbsSnapShotActivity.java:2105)
at com.consors.android.ui.AbsSnapShotActivity.onActivityResult(AbsSnapShotActivity.java:422)
at com.consors.android.de.ui.SnapShotActivity.onActivityResult(SnapShotActivity.java:198)
at android.app.Activity.dispatchActivityResult(Activity.java:4108)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3016)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3072)
at android.app.ActivityThread.access$2000(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1084)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4389)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
這是導致異常的代碼:
public static GsonRequestResponseHandler getInstance() {
if (INSTANCE == null) {
INSTANCE = new GsonRequestResponseHandler();
gson = new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).create();
}
return INSTANCE;
}
定製TypeAdapter定義:
public class ArrayAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {
TypeAdapter<T> typeAdapter = null;
try {
if (type.getRawType() == ArrayList.class)
{
typeAdapter = new ArrayAdapter(
(Class) ((ParameterizedType) type.getType())
.getActualTypeArguments()[0]);
}
} catch (Exception e) {
e.printStackTrace();
}
return typeAdapter;
}
}
中所述您能發佈一些代碼嗎?也許相關的行: 在com.consors.android.auxilary.GsonRequestResponseHandler.getInstance(GsonRequestResponseHandler.java:26) – Kgrover 2013-03-25 07:20:01
請找到我已粘貼它的代碼的相關部分 – Rockin 2013-03-25 08:41:58
在我看來,你已經部署了一箇舊版本Gson在那部手機上(<2.1)。在2.1中,registerTypeAdapterFactory被添加到了構建器中。但只是一個猜測。 – giampaolo 2013-09-08 12:49:43