Java 无法通过android应用程序插入azure
我正在为我的应用程序进行登录注册,我必须将它们与microsoft azure集成在一起。然而,尽管在遵循microsoft azure提供的教程之后,我仍然无法将我的“字符串”插入到他们的数据库中。代码中也没有错误,因此我不太确定哪里错了。下面是我的代码Java 无法通过android应用程序插入azure,java,android,azure,login,Java,Android,Azure,Login,我正在为我的应用程序进行登录注册,我必须将它们与microsoft azure集成在一起。然而,尽管在遵循microsoft azure提供的教程之后,我仍然无法将我的“字符串”插入到他们的数据库中。代码中也没有错误,因此我不太确定哪里错了。下面是我的代码 package mp.memberuse; import java.net.MalformedURLException; import android.app.Activity; import android.content.Contex
package mp.memberuse;
import java.net.MalformedURLException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import com.microsoft.windowsazure.mobileservices.*;
public class LoginRegister extends Activity {
Button btn1, btn2, btn3;
EditText tf1, tf2, tf3, tf4, tf5, tf6, tf7, tf8, tf9, tf10, tf11;
TextView tv1, tv2;
private MobileServiceClient mClient;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabs = (TabHost) this.findViewById(R.id.lt2tabhost);
tabs.setup();
TabSpec ts1 = tabs.newTabSpec("Login");
ts1.setIndicator("Login");
ts1.setContent(R.id.c1);
tabs.addTab(ts1);
TabSpec ts2 = tabs.newTabSpec("Register");
ts2.setIndicator("Register");
ts2.setContent(R.id.c2);
tabs.addTab(ts2);
btn1 = (Button)findViewById(R.id.button1);
btn2 = (Button)findViewById(R.id.button2);
btn3 = (Button)findViewById(R.id.button3);
tf1=(EditText) findViewById(R.id.editText1);
tf2=(EditText) findViewById(R.id.editText2);
tf3=(EditText) findViewById(R.id.editText3);
tf4=(EditText) findViewById(R.id.editText4);
tf5=(EditText) findViewById(R.id.editText5);
tf6=(EditText) findViewById(R.id.editText6);
tf7=(EditText) findViewById(R.id.editText7);
tf8=(EditText) findViewById(R.id.editText8);
tf9=(EditText) findViewById(R.id.editText9);
tf10=(EditText) findViewById(R.id.editText10);
tv1=(TextView) findViewById(R.id.login);
tv2=(TextView) findViewById(R.id.register);
try {
MobileServiceClient mClient = new MobileServiceClient("https://testrun.azure-mobile.net/","FOJanABDYiJEVMHkCECAylrXJCnVwF77",this);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
btn1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
String username, password;
username = tf1.getText().toString();
password = tf2.getText().toString();
/**if(username.equals(sqlusername) && password.equals(sqlpassword))
{
SharedPreferences prefs = getSharedPreferences("myPreferences",Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("fullname", fullname);
editor.commit();
Intent intent = new Intent(LoginRegister.this, SendMessage.class);
startActivity(intent);
}
else
{
tv1.setText("Invalid user");
} **/
}
}
);
btn2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
String username, password, cpassword, fullname, nric, address, phone, email;
username = tf3.getText().toString();
password = tf4.getText().toString();
cpassword = tf5.getText().toString();
fullname = tf6.getText().toString();
nric = tf7.getText().toString();
address = tf8.getText().toString();
phone = tf9.getText().toString();
email = tf10.getText().toString();
Members members = new Members();
members.username = username;
members.password = password;
members.fullname = fullname;
members.nric = nric;
members.address = address;
members.phone = phone;
members.email = email;
if(!password.equals(cpassword))
{
tv2.setText("Password & Confirm Password does not match.");
}
else if(username.equals("") || password.equals("") || cpassword.equals("") || fullname.equals("") || nric.equals("") || address.equals("") || phone.equals("") || email.equals(""))
{
tv2.setText("Do not leave any field empty.");
}
else
{
mClient.getTable(Members.class).insert(members, new TableOperationCallback<Members>()
{
public void onCompleted(Members entity, Exception exception, ServiceFilterResponse response)
{
if (exception == null)
{
tv2.setText("Register Complete.");
tf3.setText("");
tf4.setText("");
tf5.setText("");
tf6.setText("");
tf7.setText("");
tf8.setText("");
tf9.setText("");
tf10.setText("");
}
else
{
tv2.setText("Fail to register!");
}
}
});
tv2.setText("Register Complete.");
tf3.setText("");
tf4.setText("");
tf5.setText("");
tf6.setText("");
tf7.setText("");
tf8.setText("");
tf9.setText("");
tf10.setText("");
}
}
});
btn3.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
tf3.setText("");
tf4.setText("");
tf5.setText("");
tf6.setText("");
tf7.setText("");
tf8.setText("");
tf9.setText("");
tf10.setText("");
}
});
}
}
package mp.memberuse;
导入java.net.MalformedURLException;
导入android.app.Activity;
导入android.content.Context;
导入android.content.Intent;
导入android.content.SharedReferences;
导入android.content.SharedReferences.Editor;
导入android.database.Cursor;
导入android.database.sqlite.SQLiteDatabase;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.TabHost;
导入android.widget.TabHost.TabSpec;
导入android.widget.TextView;
导入com.microsoft.windowsazure.mobileservices.*;
公共类登录注册表扩展活动{
按钮btn1、btn2、btn3;
编辑文本tf1、tf2、tf3、tf4、tf5、tf6、tf7、tf8、tf9、tf10、tf11;
文本视图tv1、tv2;
私人移动服务客户机mClient;
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabs=(TabHost)this.findviewbyd(R.id.lt2tabhost);
tabs.setup();
TabSpec ts1=tabs.newTabSpec(“登录”);
ts1.setIndicator(“登录”);
ts1.设置内容(R.id.c1);
tabs.addTab(ts1);
TabSpec ts2=tabs.newTabSpec(“寄存器”);
ts2.设置指示器(“寄存器”);
ts2.设置内容(R.id.c2);
tabs.addTab(ts2);
btn1=(按钮)findViewById(R.id.button1);
btn2=(按钮)findViewById(R.id.button2);
btn3=(按钮)findViewById(R.id.button3);
tf1=(EditText)findViewById(R.id.editText1);
tf2=(EditText)findViewById(R.id.editText2);
tf3=(EditText)findViewById(R.id.editText3);
tf4=(EditText)findViewById(R.id.editText4);
tf5=(EditText)findViewById(R.id.editText5);
tf6=(EditText)findViewById(R.id.editText6);
tf7=(EditText)findViewById(R.id.editText7);
tf8=(EditText)findViewById(R.id.editText8);
tf9=(EditText)findViewById(R.id.editText9);
tf10=(EditText)findViewById(R.id.editText10);
tv1=(TextView)findViewById(R.id.login);
tv2=(TextView)findViewById(R.id.register);
试一试{
MobileServiceClient mClient=新的MobileServiceClient(“https://testrun.azure-mobile.net/“,“Fojanabdyijevmhkcecaylrxjcnwf77”,本);
}捕获(格式错误){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
btn1.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v)
{
字符串用户名、密码;
username=tf1.getText().toString();
密码=tf2.getText().toString();
/**if(username.equals(sqlusername)&&password.equals(sqlpassword))
{
SharedReferences prefs=GetSharedReferences(“myPreferences”,Context.MODE\u PRIVATE);
SharedReferences.Editor=prefs.edit();
编辑器.putString(“全名”,全名);
commit();
意向意向=新意向(LoginRegister.this,SendMessage.class);
星触觉(意向);
}
其他的
{
tv1.setText(“无效用户”);
} **/
}
}
);
btn2.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v)
{
字符串用户名、密码、cpassword、全名、nric、地址、电话、电子邮件;
username=tf3.getText().toString();
password=tf4.getText().toString();
cpassword=tf5.getText().toString();
fullname=tf6.getText().toString();
nric=tf7.getText().toString();
address=tf8.getText().toString();
phone=tf9.getText().toString();
email=tf10.getText().toString();
成员=新成员();
members.username=用户名;
members.password=密码;
members.fullname=全名;
members.nric=nric;
members.address=地址;
members.phone=电话;
members.email=电子邮件;
如果(!password.equals(cpassword))
{
tv2.setText(“密码和确认密码不匹配”);
}
else if(username.equals(“”)| | password.equals(“”)| | cpassword.equals(“”)| |全名.equals(“”)| | nric.equals(“”)| |地址.equals(“”)| |电话.equals(“”)| |电子邮件.equals(“”)
{
tv2.setText(“不要将任何字段留空”);
}
其他的
{
mClient.getTable(Members.class).insert(Members,new TableOperationCallback())
{
未完成公共无效(成员实体、异常、ServiceFilterResponse响应)
{
if(异常==null)
{
tv2.setText(“注册完成”);
tf3.setText(“”);
tf4.setText(“”);
tf5.setText(“”);
tf6.setText(“”);
tf7.setText(“”);
tf8.setText(“”);
tf9.setText(“”);
tf10.setText(“”);
}
其他的
{
tv2.setText(“注册失败!”);
}
}
});
tv2.setText(“注册完成”);
tf3.setText(“”);
private String SendDataFromAndroidDevice() {
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet getMethod = new HttpGet("your url + data appended");
BufferedReader in = null;
BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
.execute(getMethod);
in = new BufferedReader(new InputStreamReader(httpResponse
.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
while ((line = in.readLine()) != null) {
sb.append(line);
}
in.close();
result = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
private class HTTPdemo extends
AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {}
@Override
protected String doInBackground(String... params) {
String result = SendDataFromAndroidDevice();
return result;
}
@Override
protected void onProgressUpdate(Void... values) {}
@Override
protected void onPostExecute(String result) {
if (result != null && !result.equals("")) {
try {
JSONObject resObject = new JSONObject(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView("your layout");
if ("check here where network/internet is avaliable") {
new HTTPdemo().execute("");
}
}