0

我已经构建了一个自定义 jar 来执行 JSON 事务。在自定义 jar 中,我有 gson-2.2.4.jar 文件。jar 位于 res 文件夹中。

当我在我的应用程序中包含我的自定义 jar 并尝试运行它时,我得到以下运行时异常

09-13 14:25:39.411: ERROR/AndroidRuntime(988): FATAL EXCEPTION: AsyncTask #1
        java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:299)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
        at java.util.concurrent.FutureTask.run(FutureTask.java:239)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
        Caused by: java.lang.NoClassDefFoundError: com.google.gson.GsonBuilder
        at com.company.mobile.rest.RestAccessObject.call(RestAccessObject.java:42)
        at com.company.mobile.rest.ContactsRAO.getContacts(ContactsRAO.java:25)
        at com.company.mobile.activity.ContactActivity$JSONOperation.executeRAO(ContactActivity.java:130)
        at com.company.mobile.activity.ContactActivity$JSONOperation.doInBackground(ContactActivity.java:89)
        at com.company.mobile.activity.ContactActivity$JSONOperation.doInBackground(ContactActivity.java:81)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        ... 4 more

就像临时步骤一样,我已将 gson-2.2.4.jar 添加到 android 应用程序的 lib 文件夹中。我仍然得到同样的错误。

我是否需要在我的自定义 jar 中的清单中添加一些内容以使其中的 gson-2.2.4.jar 可用于所有其他类?或者,这与我的 android 项目结构有关吗?

谢谢你的帮助。

4

1 回答 1

0

I have built a custom jar to execute JSON transactions. Inside of the custom jar I have gson-2.2.4.jar file.

That will not work, unless you really mean "Inside of the custom JAR [you] have the contents of the gson-2.2.4.jar file".

The jar is located in res folder.

That certainly will not work.

Just as temporary step I have added gson-2.2.4.jar to lib folder of the android app

Put your JAR in libs/. And, consider getting rid of your copy of the Gson classes from that custom JAR and use the separate Gson JAR also in libs/.

If you are using Eclipse, make sure that the "Order & Export" portion of your Build Path is set up properly.

于 2013-09-13T14:42:29.307 回答