我需要帮助,似乎是一个简单的问题,但我坚持了几天。我正尝试使用Azure Mobile服务来保存来自我的Android应用程序的数据。我现在遇到的问题是我有一个数据传输对象,其中有几个字段与Azure数据库表中的列对应。这是一个简单的表格,遵循所有步骤......我做错了什么?从我的Android应用程序持久数据Azure移动服务,不起作用
package com.bn7.rotabn7;
import java.net.MalformedURLException;
import com.microsoft.windowsazure.mobileservices.*;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
private MobileServiceClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
mClient = new MobileServiceClient(
"https://ocamorana.azure-mobile.net/",
"hCzcrsFYhkGmxPvQDNxyqBXjZwjXlK99",
this
);
Item item = new Item();
item.IdPhone = "Awesome item";
item.DateTimePhone = "Awesome item";
item.LatitudePhone = -43;
item.LongetudePhone = -23;
item.ActivePhone = false;
mClient.getTable(Item.class).insert(item, new TableOperationCallback<Item>() {
public void onCompleted(Item entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
// Insert succeeded
} else {
// Insert failed
Log.d("Insert failed", "*---------------------------------------------------------------*");
Log.d("Insert failed", "Error in activity", exception); // log the error
Log.d("Insert failed", "*---------------------------------------------------------------*");
}
}
});
} catch (MalformedURLException e) {
Log.d("MalformedURLException", e.toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
package com.bn7.rotabn7;
public class Item {
public int Id;
public String IdPhone;
public String DateTimePhone;
public double LatitudePhone;
public double LongetudePhone;
public boolean ActivePhone;
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bn7.rotabn7"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.bn7.rotabn7.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
错误活动 om.microsoft.windowsazure.mobileservices.MobileServiceException:错误在处理请求。 com.microsoft.windowsazure.mobileservices.MobileServiceConnection $ 1.onNext(MobileServiceConnection.java:121) com.microsoft.windowsazure.mobileservices.MobileServiceClient $ 4.handleRequest(MobileServiceClient.java:429) com.microsoft.windowsazure.mobileservices.MobileServiceConnection 。开始(MobileServiceConnection.java:92) com.microsoft.windowsazure.mobileservices.RequestAsyncTask.doInBackground(RequestAsyncTask.java:77) com.microsoft.windowsazure.mobileservices.RequestAsyncTask.doInBackground(RequestAsyncTask.java:1) 机器人。 os.AsyncTask $ 2.call(AsyncTask.java:185) java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:306) java.util.concurrent.FutureTask.run(FutureTask.java:138) java.util中。 (ThreadPoolExecutor.java:1088) java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:581) java.lang.Thread.run(Thread.java:1019) 引起: java.net.UnknownHostException:ocamorana.azure-mobile.net java.net.InetAddress.lookupHostByName(InetAddress.java:506) java.net.InetAddress.getAllByNameImpl(InetAddress.java:294) java.net.InetAddress。 getAllByName(InetAddress.java:256) org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136) org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAd apter.java:119) org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359) org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 组织.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) com.microsoft.windowsazure.mobileservices.ServiceFilterRequestImpl .execute(ServiceFilterRequestImpl.java:73) com.microsoft.windowsazure.mobileservices.MobileServiceConnection $ 1.onNext(MobileServiceConnection.java:101) ------------------- --------------------------------------------
感谢您的快速反馈,对不起,我没有放在一起明显的代码,但已经允许上网,在我看来是正确的。不起作用... :-( – user2233296
该错误表明它无法实际连接到服务。如果您在模拟器上打开浏览器并尝试连接到https://ocamorana.azure-mobile.net,会发生什么情况/。尝试创建一个新的模拟器,看看你是否得到相同的UnknownHostException。 – Chris
再次感谢您的反馈。正如你所说我创建了另一个移动服务,mClient = new MobileServiceClient(“https://bn7.azure-mobile.net/”...产生了完全相同的效果。以Azure ToDo和两种服务为例进行测试( ocamorana和BN7)功能,使用我的代码更简单,不起作用 – user2233296