2015-10-29 39 views
0

我試圖在Azure門戶(Portal>移動服務> Android> Connect Existing Android App)中使用文檔在Android應用中實現Azure移動服務,並且在嘗試實例化MobileServiceClient時遇到了java格式錯誤的URL錯誤。是拋出錯誤嘗試實施Azure移動服務的Android格式錯誤的URL錯誤

代碼:

mClient = new MobileServiceClient(
    "https://myurl.azure-mobile.net/", 
    "my_secret_squirrel_key", 
    this 
); 

編譯器引發此錯誤:

Unhandled exception:java.net.MalformedURLException

我已經添加了buildscript和編譯的項目/應用搖籃文件中的聲明。使用SDK 2.0.3版(也嘗試使用2.0.2)。

我已經添加權限清單文件,太:

<uses-permission android:name="android.permission.INTERNET" /> 

我用這中導入移動服務庫的活動:

import com.microsoft.windowsazure.mobileservices.*; 

而且我聲明一個私人會員在同一活動中持有MobileServiceClient,如下所示:

private MobileServiceClient mClient; 

使用Android工作室1.3.2。

+0

嘗試使用相同的實現在本教程應用程序(第60行)從這裏(不是我的代碼) - https://github.com/Azure/mobile-services-samples/blob/master/GettingStartedWithData/AndroidStudio/GetStartedWithData/app/src/main/java/com/例如/ GetStartedWithData/ToDoActivity.java –

回答

3

的URL constructor已選中的MalformedUrlException

你需要或者添加throws MalformedUrlException到您的調用方法,或者將它包裝在一個try/catch:

try 
{ 
    mClient = new MobileServiceClient(
     "https://myurl.azure-mobile.net/", 
     "my_secret_squirrel_key", 
        this); 
} 
catch(MalformedUrlException ex) 
{ 
    Log.e("Service URL was malformed!", ex); 
}