无法解决以下问题:Ljavax / xml / bind / DatatypeConverter;

时间:2019-01-26 13:42:08

标签: android api android-studio woocommerce-rest-api

我正在尝试将Woocommerce API连接到android项目中。

我在AsyncTask中尝试了以下代码:

 OAuthService service = new ServiceBuilder().provider(RequestToken.class)
                    .apiKey(getResources().getString(R.string.ck))
                    .apiSecret(getResources().getString(R.string.cs))
                    .signatureType(SignatureType.QueryString)
                    .debug()
                    .build();

            OAuthRequest request = new OAuthRequest(Verb.GET, restURL);
            Token accessToken = new Token("", ""); //not required for context.io
            service.signRequest(accessToken, request);
            Response response = request.send();

            String jsonStr = response.getBody();
            Log.e(TAG, "Response from url id first : " + jsonStr);

此代码已在我安装了NOXPlayer的系统中成功运行。但是此代码未在我的手机上运行。 我试图通过PdaNet +在手机上查看输出。

输出设备规格:

  • 在NOXPlayer设备中:SAMSUNG NEXUS:Android 4.4.2,API 19
  • 我的移动设备:小米MI A1 Android 9,API 28

我发现我从这一行得到了错误:

service.signRequest(accessToken, request);

我的错误日志:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
    Process: com.example.kishan.grocerr, PID: 13279
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:354)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/bind/DatatypeConverter;
        at org.scribe.services.DatatypeConverterEncoder.encode(DatatypeConverterEncoder.java:10)
        at org.scribe.services.HMACSha1SignatureService.bytesToBase64String(HMACSha1SignatureService.java:51)
        at org.scribe.services.HMACSha1SignatureService.doSign(HMACSha1SignatureService.java:46)
        at org.scribe.services.HMACSha1SignatureService.getSignature(HMACSha1SignatureService.java:32)
        at org.scribe.oauth.OAuth10aServiceImpl.getSignature(OAuth10aServiceImpl.java:145)
        at org.scribe.oauth.OAuth10aServiceImpl.addOAuthParams(OAuth10aServiceImpl.java:75)
        at org.scribe.oauth.OAuth10aServiceImpl.signRequest(OAuth10aServiceImpl.java:120)
        at com.example.kishan.grocerr.MainActivity$GetContacts.doInBackground(MainActivity.java:154)
        at com.example.kishan.grocerr.MainActivity$GetContacts.doInBackground(MainActivity.java:125)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.xml.bind.DatatypeConverter" on path: DexPathList[[zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/base.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_resources_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/lib/arm64, /system/lib64, /system/vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at org.scribe.services.DatatypeConverterEncoder.encode(DatatypeConverterEncoder.java:10) 
        at org.scribe.services.HMACSha1SignatureService.bytesToBase64String(HMACSha1SignatureService.java:51) 
        at org.scribe.services.HMACSha1SignatureService.doSign(HMACSha1SignatureService.java:46) 
        at org.scribe.services.HMACSha1SignatureService.getSignature(HMACSha1SignatureService.java:32) 
        at org.scribe.oauth.OAuth10aServiceImpl.getSignature(OAuth10aServiceImpl.java:145) 
        at org.scribe.oauth.OAuth10aServiceImpl.addOAuthParams(OAuth10aServiceImpl.java:75) 
        at org.scribe.oauth.OAuth10aServiceImpl.signRequest(OAuth10aServiceImpl.java:120) 
        at com.example.kishan.grocerr.MainActivity$GetContacts.doInBackground(MainActivity.java:154) 
        at com.example.kishan.grocerr.MainActivity$GetContacts.doInBackground(MainActivity.java:125) 
        at android.os.AsyncTask$2.call(AsyncTask.java:333) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
        Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.kishan.grocerr-aOveHYnFM3y_edrWtj0ViA==/split_lib_resources_apk.apk
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:354)
        at dalvik.system.DexFile.<init>(DexFile.java:101)
        at dalvik.system.DexFile.<init>(DexFile.java:75)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
01-26 18:59:01.742 13279-13450/com.example.kishan.grocerr E/AndroidRuntime:     at dalvik.system.DexPathList.<init>(DexPathList.java:164)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:718)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:801)
        at android.app.LoadedApk.getResources(LoadedApk.java:1023)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5780)
        at android.app.ActivityThread.access$1100(ActivityThread.java:200)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1660)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6762)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

我的图书馆

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.squareup.picasso:picasso:2.3.2'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.daimajia.slider:library:1.1.5@aar'
    implementation 'org.scribe:scribe:1.3.5'
}

2 个答案:

答案 0 :(得分:1)

最简单的解决方案是将其添加到AndroidMainifest.xml中的“应用程序标签选择”中:

<uses-library android:name="org.apache.http.legacy" android:required="false" />

一定可以使用!

答案 1 :(得分:0)

您使用的库(org.scribe:scribe:1.3.5)与Android不兼容。它设计用于Java SE或Java EE,而不是Android SDK(不具有javax.xml.bind.DatatypeConverter)。

找到另一个已知可用于Android的库。