我在使用 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;
}
}