我正嘗試將Azure連接到Android Studios。我遵循了關於Azure的教程並創建了移動服務。然後它給了我一些代碼添加到我的應用程序,以便他們連接。但是,代碼拋出了一個我無法弄清楚的異常。我從頭到腳搜索了互聯網,找不到答案。我認爲它與依賴或導入庫的方式有關(通過將jar文件粘貼到libs文件夾並添加依賴關係)。將Azure連接到Android Studios
代碼拋出導致異常(由天青提供):
try {
mClient = new MobileServiceClient(
"https://atm.azure-mobile.net/",
"JWjetFMUVaAXzHmqDVqhkkRhTGGjeW70",
this
);
Item item = new Item();
item.Text = "Awesome item";
mClient.getTable(Item.class).insert(item, new TableOperationCallback<Item>() {
public void onCompleted(Item entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
// Insert succeeded
Toast.makeText(context, "WOOHOO", Toast.LENGTH_LONG).show();
} else {
// Insert failed
Toast.makeText(context, "FAILED", Toast.LENGTH_LONG).show();
}
}
});
}
catch(MalformedURLException d) {
}
例外:
java.lang.NoClassDefFoundError: com.google.gson.GsonBuilder
at com.microsoft.windowsazure.mobileservices.MobileServiceClient.createMobileServiceGsonBuilder(MobileServiceClient.java:192)
at com.microsoft.windowsazure.mobileservices.MobileServiceClient.<init>(MobileServiceClient.java:179)
at com.microsoft.windowsazure.mobileservices.MobileServiceClient.<init>(MobileServiceClient.java:158)
at com.atmlocator.hooper.kenneth.atmlocator.HomeActivity.onCreate(HomeActivity.java:218)
at android.app.Activity.performCreate(Activity.java:5047)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2051)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2112)
at android.app.ActivityThread.access$700(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4917)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
at dalvik.system.NativeStart.main(Native Method)
謝謝您的回答@Peter,但我已經完成了這些步驟。 「gson-2.2.2.jar」文件已經包含在內,但在編譯時似乎沒有被識別。有任何想法嗎? 這是.jar我已經包含compile'com.google.code.gson:gson:2.2.2' – semiColon
@semiColon IDEA官方幫助手冊可以幫助您解決它https://www.jetbrains.com/idea /help/configuring-module-dependencies-and-libraries.html#d1552849e216 –