Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Android将数据插入Windows Azure表?_Java_C#_Android_Azure_Cloud - Fatal编程技术网

Java 使用Android将数据插入Windows Azure表?

Java 使用Android将数据插入Windows Azure表?,java,c#,android,azure,cloud,Java,C#,Android,Azure,Cloud,我正在尝试将数据插入到一个表中,我已在sql Management studio中为该表创建了数据库并将其上载到Windows azure 但我无法从android应用程序中插入数据 /////////main activity///// private MobileServiceClient MSC; private MobileServiceTable MST; User usertable=new User(); Spinner spinner; @Override protect

我正在尝试将数据插入到一个表中,我已在sql Management studio中为该表创建了数据库并将其上载到Windows azure

但我无法从android应用程序中插入数据

/////////main activity/////


private MobileServiceClient MSC;
private MobileServiceTable MST;
User usertable=new User();

Spinner spinner;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up);

    //for connectivity

    try {
        MSC=new MobileServiceClient(
               "app url",

                "app key",
                this
        );
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }


    spinner=(Spinner)findViewById(R.id.spinner);
    ArrayAdapter adapter=ArrayAdapter.createFromResource(this,R.array.Profession,android.R.layout.simple_dropdown_item_1line);
    spinner.setAdapter(adapter);

    //from here new code for spinner validation

    //till hare code for spinner validation

    Button signUpBotton=(Button)findViewById(R.id.signUpButton);

    signUpBotton.setOnClickListener(new View.OnClickListener(){

                                       public void onClick(View view){
                                          // signUpvalidation();
                                         EditText fname= (EditText) findViewById(R.id.etfirstname);
                                           usertable.first_name=fname.getText().toString();

                                           MSC.getTable(User.class).insert(usertable, new TableOperationCallback<User>() {
                                               public void onCompleted(User entity, Exception exception, ServiceFilterResponse response) {
                                                   if (exception == null) {
                                                       // Insert succeeded
                                                   } else {
                                                       // Insert failed
                                                   }

                                               }
                                           });

根据我的经验,从android应用程序中插入日期失败的原因是POJO类“User”不正确

我引用Azure移动服务示例中的POJO类“ToDoItem”来重写用户POJO类,如下所示:

package com.example.engiam.anybodyhere;

public class User {

    @com.google.gson.annotations.SerializedName("id")
    private String id;

    @com.google.gson.annotations.SerializedName("first_name")
    private String firstName;

    public User() {}

    public User(String id, String firstName) {
         this.setId(id);
         this.setFirstName(firstName);
    }

    public String getId() {
         return id;
    }

    public String setId(String id) {
         this.id = id;
    }

    public String getFirstName() {
         return firstName;
    }

    public String setId(String firstName) {
         this.firstName = firstName;
    }

     // If you need to override function toString & equals, please follow the sample to write them. 

 }
如果类属性名称与表列名不同,则上述POJO类中的Java注释与数据库中的表列相关。如果代码未注释表列名,则程序不知道如何将数据项插入正确的表列

并且您的类代码缺少setting&get方法,这将导致动态模式不会注入用户对象并获取其属性以将其插入表或创建新表。关于动态模式,请参阅

您需要按照POJO类规范使用set&get函数修改主活动代码

如有任何问题,请评论我。
致以最诚挚的问候。

根据我的经验,从您的android应用程序中插入日期失败的原因是POJO类“User”不正确

我引用Azure移动服务示例中的POJO类“ToDoItem”来重写用户POJO类,如下所示:

package com.example.engiam.anybodyhere;

public class User {

    @com.google.gson.annotations.SerializedName("id")
    private String id;

    @com.google.gson.annotations.SerializedName("first_name")
    private String firstName;

    public User() {}

    public User(String id, String firstName) {
         this.setId(id);
         this.setFirstName(firstName);
    }

    public String getId() {
         return id;
    }

    public String setId(String id) {
         this.id = id;
    }

    public String getFirstName() {
         return firstName;
    }

    public String setId(String firstName) {
         this.firstName = firstName;
    }

     // If you need to override function toString & equals, please follow the sample to write them. 

 }
如果类属性名称与表列名不同,则上述POJO类中的Java注释与数据库中的表列相关。如果代码未注释表列名,则程序不知道如何将数据项插入正确的表列

并且您的类代码缺少setting&get方法,这将导致动态模式不会注入用户对象并获取其属性以将其插入表或创建新表。关于动态模式,请参阅

您需要按照POJO类规范使用set&get函数修改主活动代码

如有任何问题,请评论我。
致以最诚挚的问候。

如果插入失败,您不会使用异常信息检查代码中的错误,也许您应该从那里开始。如果您能解释,请不要理解!!在测试中
if(异常==null){…
如果插入失败,则不会对异常执行任何操作,也许可以使用
printStackTrace
然后阅读android错误日志可以帮助查找错误您没有使用异常信息检查代码中的错误如果插入失败,也许您应该从那里开始。如果您可以在tes中解释,请不要理解t
if(exception==null){…
如果插入失败,则不会对异常执行任何操作,可能使用
printStackTrace
然后读取android错误日志可以帮助查找错误