1

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;
 }
}
4

1 に答える 1

2

Even though this question is 7 months old this might still help other with the same bug.

Some HTC phones have an outdated version of Gson in their system classpath. The (newer) version of the Gson JAR that is included in your app is therefore ignored.

I know of two possible solutions, neither of which is particularly convenient:
1) Work with the old version of Gson. This is probably a bad idea, since you might need some of the new features and bugfixes from later versions. Also, future HTC phones might ship with a different Gson version, so this approach is not very robust.
2) Repackage the version of Gson included in your application, as described in https://sites.google.com/site/gson/gson-on-android

于 2013-10-07T12:09:53.000 に答える