在进行Azure SQL查询时,Android应用程序崩溃

时间:2016-07-05 19:03:13

标签: java android sql-server azure azure-sql-database

非常感谢任何帮助。我使用适用于Android Studio的Microsoft Azure Mobile SDK为我的Android应用程序创建了一个后端。但是当我尝试使用查询从服务器获取数据时,应用程序会挂起并崩溃。我的代码如下:

//The variables
private MobileServiceClient mClient;
private MobileServiceTable<Item> table;

//In onCreate method
try {
    mClient = new MobileServiceClient("https://myapp.azurewebsites.net", this);
} catch (MalformedURLException e) {
    e.printStackTrace();
}
table = mClient.getTable("MyTable",Item.class);
try {
    final List<Item> result =  table.execute().get();//----App crashes here
} catch (MobileServiceException e) {
    e.printStackTrace();
}

1 个答案:

答案 0 :(得分:1)

@AnshaySaboo有两个名为Azure Mobile Services的服务(Azure经典门户网站上的旧服务)&amp; Azure上的Azure Mobile Apps(Azure新门户上的新服务)。根据您的描述,我无法识别您使用的是哪种服务。但是,根据构造函数MobileServiceClient(String appUrl, Context context),我认为您使用的是Azure Mobile Apps SDK for Android,而不是Azure Mobile Services SDK for Android

我认为当您在Azure新门户上创建移动应用服务时,可能会因使用适用于Android的移动服务SDK而导致此问题。因此,请检查您用作后端的服务以及您用于Android客户端的sdk,并确保后端和客户端的服务一致性。

作为参考,有一些资源可用于不同的服务。

  1. 开始使用Mobile Services vs Mobile Apps
  2. 如何使用Mobile Services vs Mobile Apps的Android客户端库。
  3. GitHub上的示例:Mobile Services vs Mobile Apps