如何从在线数据库kinvey获取数据

时间:2015-04-01 22:15:45

标签: android mysql eclipse kinvey

我正在尝试从在线数据库中获取数据,并使用Textview在一个简单的表单上显示根据今天日期的结果。

请参阅以下代码:

myJavaClient.appData("tdSensorData", Sensor.class).get(new KinveyListCallback<Sensor>() {

                        @Override
                        public void onSuccess(Sensor[] result) {

                        Toast.makeText(MainActivity.this,"Get All Worked!\n Got: " + result.length,Toast.LENGTH_LONG).show();


                        }

                        @Override
                        public void onFailure(Throwable error) {
                            Toast.makeText(MainActivity.this,
                                    "Get All error: " + error.getMessage(),
                                    Toast.LENGTH_LONG).show();
                        }

                    });

问题是当我试图从名为Sensor的实体类中获取数据时,当我从success方法键入result.getSensorr1()时出现错误。任何人都可以请求帮助和来自吐司的result.length我得到4000这是我从数据库中的正确行数

这是我的实体类:

package com.accenture.googleglassaccenture;

import com.google.api.client.json.GenericJson;
import com.google.api.client.util.Key;

public class Sensor extends GenericJson{

    @Key("_id")
    private String id;

    @Key("DATETIME")
    private String datetime;

    @Key("MAC")
    private String mac;

    @Key("SENSOR_1")
    private String sensorr1;

    @Key("SENSOR_2")
    private String sensorr2;

    @Key("SENSOR_3")
    private String sensorr3;

    @Key("SENSOR_4")
    private String sensorr4;

    @Key("TEMP")
    private String temp;

    @Key("BAT")
    private String bat;


    public String getId() {
        return id;
    }



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



    public String getDatetime() {
        return datetime;
    }



    public void setDatetime(String datetime) {
        this.datetime = datetime;
    }



    public String getMac() {
        return mac;
    }



    public void setMac(String mac) {
        this.mac = mac;
    }



    public String getSensorr1() {
        return sensorr1;
    }



    public void setSensorr1(String sensorr1) {
        this.sensorr1 = sensorr1;
    }



    public String getSensorr2() {
        return sensorr2;
    }



    public void setSensorr2(String sensorr2) {
        this.sensorr2 = sensorr2;
    }



    public String getSensorr3() {
        return sensorr3;
    }



    public void setSensorr3(String sensorr3) {
        this.sensorr3 = sensorr3;
    }



    public String getSensorr4() {
        return sensorr4;
    }



    public void setSensorr4(String sensorr4) {
        this.sensorr4 = sensorr4;
    }



    public String getTemp() {
        return temp;
    }



    public void setTemp(String temp) {
        this.temp = temp;
    }



    public String getBat() {
        return bat;
    }



    public void setBat(String bat) {
        this.bat = bat;
    }


    public Sensor() {
        // TODO Auto-generated constructor stub
    }
}

,这是表格中的结果

{"_id":"51a71254d06fdbee04000653","DATETIME":"2013-05-23T11:16:34Z","MAC":"0013a200407e0086","SENSOR_1":"91.19","SENSOR_2":"19.093333333333334","SENSOR_3":"439.3097042968143","SENSOR_4":"0.0","TEMP":"-17","BAT":"47","_acl":{"creator":"kid_VPuam4pfqf"},"_kmd":{"lmt":"2013-05-30T08:48:20.335Z","ect":"2013-05-30T08:48:20.335Z"}},{"_id":"51a71255d06fdbee04000654","DATETIME":"2013-05-23T11:17:33Z","MAC":"0013a200407e0086","SENSOR_1":"91.19","SENSOR_2":"19.093333333333334","SENSOR_3":"494.4776331634671","SENSOR_4":"0.0","TEMP":"-17","BAT":"47","_acl":

1 个答案:

答案 0 :(得分:0)

您获得的结果是数组的形式。您必须遍历数组并获取实体对象。 这是一个例子:

public void onSuccess(Sensor[] result) {
if (result.length != 0) {
    for (Sensor sensor:result){
        sensor.getSensorr1();
        //what-ever-else-you-need
    }
}