首页 文章

尝试实施Azure移动服务的Android格式错误的网址错误

提问于
浏览
0

我正在尝试使用Azure门户内部的文档(门户>移动服务> Android>连接现有Android应用程序)在Android应用程序中实施Azure移动服务,并在尝试实例化时遇到java格式错误的URL错误a MobileServiceClient .

抛出错误的代码:

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

编译器抛出此错误:

未处理的异常:java.net.MalformedURLException

我在project / app Gradle文件中添加了buildscript和compile声明 . 使用SDK的2.0.3版本(也尝试使用2.0.2) .

我也为清单文件添加了权限:

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

我正在使用它的活动是导入移动服务库:

import com.microsoft.windowsazure.mobileservices.*;

我在同一个活动中声明一个私有成员来保存MobileServiceClient,如下所示:

private MobileServiceClient mClient;

使用Android Studio 1.3.2 .

1 回答

  • 3

    网址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);
    }
    

相关问题