应用程序未从Azure移动服务表中检索数据 [英] App not retrieving data from Azure mobile service table

查看:84
本文介绍了应用程序未从Azure移动服务表中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我的Android应用程序无法从移动服务中的表获取数据.

Well my android app has trouble getting data from a table in my mobile service.

它使用MobileserviceClient连接到azure移动服务服务器,没有任何错误.但是,当我尝试获取表并将数据从该表中取出时,应用程序会冻结在那一行上,并给我一个白屏.

It connects to the azure mobile service server using the MobileserviceClient with no errors what so ever. But when i try to get a table and take the data out of that table that app freezes on that 1 line and gives me a white screen.

所以有些帮助将是很大的原因,因为我不知道我在做什么错. restaurantdata表中已经有50行数据.

So some help would be great cause I have no clue what I am doing wrong. Also there is already 50 rows of data in the restaurantdata table.

private MobileServiceClient mClient;
private MobileServiceTable<RestaurantData> table;
private MobileServiceList<RestaurantData> list;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.activityMainToolbar);
    setSupportActionBar(toolbar);
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.activityMainCoordinatorLayout);
    viewGroup = (ViewGroup) ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
    layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = layoutInflater.inflate(R.layout.activity_new_restaurants, viewGroup, false);
    coordinatorLayout.addView(view);       

    try {
        Log.e("Log", "Log1");
        mClient = new MobileServiceClient("Service doamin", "application key here", getApplicationContext());
        Log.e("Log", "Log2");
        table = mClient.getTable(RestaurantData.class);
        Log.e("Log", "Log3");
        list = table.execute().get();//App freezes here with white screen
        Log.e("Log", "Log4");

    } catch (Exception e) {
        e.printStackTrace();
        Log.e("ERROR2", " " + e);
    }
    Log.e("Log", "Log6");
}

推荐答案

根据您提供的代码段,您似乎只是通过list = table.execute().get()获取数据,但没有将数据呈现给视图.

Per your code snippet you provided, it seems you just get the data via list = table.execute().get() but do not present your data to the view.

通常,我们可以利用列表视图适配器将我们的数据显示在列表中.

Usually, we can leverage list view and adapter to present our data in list.

以下是Azure移动服务Android客户端示例上的代码段:

Here are the code snippet on Azure Mobile Service Android Client sample:

public class ToDoItemAdapter extends ArrayAdapter<ToDoItem> {

/**
 * Adapter context
 */
Context mContext;

/**
 * Adapter View layout
 */
int mLayoutResourceId;

public ToDoItemAdapter(Context context, int layoutResourceId) {
    super(context, layoutResourceId);

    mContext = context;
    mLayoutResourceId = layoutResourceId;
}

/**
 * Returns the view for a specific item on the list
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;

    final ToDoItem currentItem = getItem(position);

    if (row == null) {
        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        row = inflater.inflate(mLayoutResourceId, parent, false);
    }

    row.setTag(currentItem);

    return row;
}

}

定义变量:

private ToDoItemAdapter mAdapter;


mAdapter = new ToDoItemAdapter(this, R.layout.row_list_to_do);
ListView listViewToDo = (ListView) findViewById(R.id.listViewToDo);
listViewToDo.setAdapter(mAdapter);

在列表视图中添加列表项:

for (ToDoItem item : list) {
    mAdapter.add(item);
}

这篇关于应用程序未从Azure移动服务表中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆