0

我的代码有问题,有时我得到一个空对象引用,有时没有(在同一件事上),我无法理解问题所在,因为正如我所说,一次它工作正常,但第二次它显示我空对象引用消息。我想要做的是从我的 Azure 表中获取登录教练的俱乐部。

private MobileServiceTable<trainer> TrainerTable=null;
private MobileServiceClient mService=null;
private users cl=null;
private ProgressDialog prg;



private void Trainer_Club_String(final String username)
{
    AsyncTask<Void,Void,Void> task = new AsyncTask<Void, Void, Void>()
    {

        @Override
        protected Void doInBackground(Void... voids)
        {
            try
            {
                List<trainer> chosen_manager= TrainerTable.where().field("username").eq(username).execute().get(); \\the problem is in this line. Sometimes it tells me that the user is null and sometimes its working well

                if(chosen_manager.size()>0)
                {
                    trainer_club=chosen_manager.get(0).getClub().toString();
                }

            }

            catch (Exception e)
            {
                final String message=e.getMessage().toString();

                runOnUiThread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        Toast.makeText(trainer_home_page.this, message, Toast.LENGTH_LONG).show();
                    }
                });
            }
            return null;
        }
    }.execute();
} 

ONCREATE:


cl=StaticObjects.GetClient();

trainer_username=cl.getUsername().toString();

Trainer_Club_String(trainer_username);
4

0 回答 0