不能从parse.com检索阵列 [英] Not able to retrieve array from parse.com

查看:147
本文介绍了不能从parse.com检索阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在parse.com dashboard.i使这个阵列列是能从我的应用程序在数组中添加值,但中号无法获取数组或列表,并使用它的所有功能(即使大小())给该行零点例外。

我已经使用了许多解决方案,但没有奏效。

我的code,其中它给错误。

  =实(的TextView)v.findViewById(R.id.realtext);
        假=(TextView中)v.findViewById(R.id.faketext);
        realbutton =(的ImageButton)v.findViewById(R.id.realbutton);
        fakebutton =(的ImageButton)v.findViewById(R.id.fakebutton);
        real.setText(将String.valueOf(news.getRealvote()));
        fake.setText(将String.valueOf(news.getFake()));
fakebutton.setOnClickListener(新View.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根                news.setuserArray(news.getAuthor()getUsername());
                清单<&的parseObject GT;一个= news.getUserArray();
                Toast.makeText(C,a.toString(),Toast.LENGTH_SHORT).show(); //用a.size()等任何东西给任何错误                news.setFake();
                news.saveInBackground();
                fake.setText(将String.valueOf(news.getFake()));                realbutton.setVisibility(View.GONE);
                fakebutton.setVisibility(View.GONE);            }
        });

这是我的getUserArray()方法

 公开名单<&的parseObject GT; getUserArray(){    返回的GetList(users_rated);
}

存储数据的方法的工作

 公共无效setuserArray(字符串文件){
    addUnique(users_rated文件);
}

我已经尝试了很多,但没有success.plss帮我取回数组。

你要求列表适配器?

 公共类Customnewslistview扩展ParseQueryAdapter<新闻> {上下文℃;公共Customnewslistview(上下文的背景下){
    超(背景下,新闻报);
    C =背景;
}@覆盖
公共查看getItemView(最终新闻新闻,视图V的ViewGroup以及母公司){    如果(V == NULL){
        最终的TextView真实;
        最终的TextView假的;
        最终的ImageButton realbutton;
        最终的ImageButton fakebutton;
        最终进度装载机;
        V = View.inflate(的getContext(),R.layout.item_list_news_public,NULL);        装载机=(进度)v.findViewById(R.id.eachnewsloder);        ParseImageView newsImage =(ParseImageView)V
                .findViewById(R.id.icon);
        ParseFile photoFile = news.getParseFile(照片);
        如果(photoFile!= NULL){
            newsImage.setParseFile(photoFile);
            newsImage.loadInBackground(新GetDataCallback(){
                @覆盖
                公共无效完成(字节[]数据,ParseException的E){
                    Log.d(做事先知情同意,data.toString());
                    loader.setVisibility(View.GONE);
                }
            });
        }其他{
            loader.setVisibility(View.GONE);
            newsImage.setBackgroundResource(R.drawable.image40);
        }        TextView的titleTextView =(TextView中)v.findViewById(R.id.text1);
        titleTextView.setText(news.getTitle());
        //试图真假按钮
        真正=(TextView中)v.findViewById(R.id.realtext);
        假=(TextView中)v.findViewById(R.id.faketext);
        realbutton =(的ImageButton)v.findViewById(R.id.realbutton);
        fakebutton =(的ImageButton)v.findViewById(R.id.fakebutton);
        real.setText(将String.valueOf(news.getRealvote()));
        fake.setText(将String.valueOf(news.getFake()));
        realbutton.setOnClickListener(新View.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根
                news.setuserArray(news.getAuthor()的toString());
                news.setRealvote();
                news.saveInBackground();
                real.setText(将String.valueOf(news.getRealvote()));                Toast.makeText(的getContext(),不作弊,
                        Toast.LENGTH_SHORT).show();                realbutton.setVisibility(View.GONE);
                fakebutton.setVisibility(View.GONE);            }
        });
        fakebutton.setOnClickListener(新View.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根                news.setuserArray(news.getAuthor()getUsername());
                清单<&的parseObject GT;一个=无效;
                尝试{
                    。一个= news.fetchIfNeeded()的GetList(users_rated);
                }赶上(ParseException的E){
                    // TODO自动生成catch块
                    e.printStackTrace();
                }
                Toast.makeText(C,a.toString(),Toast.LENGTH_SHORT).show();                news.setFake();
                news.saveInBackground();
                fake.setText(将String.valueOf(news.getFake()));                realbutton.setVisibility(View.GONE);
                fakebutton.setVisibility(View.GONE);            }
        });
        titleTextView.setOnClickListener(新View.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根
                对话D =新的对话框(C);
                d.setContentView(R.layout.publicnewsdialog);
                d.setTitle(新闻);
                TextView的文本=(TextView的)d.findViewById(R.id.dialogtext);
                text.setText(news.getTitle());
                //图像解析
                ParseImageView newsImage =(ParseImageView)D
                        .findViewById(R.id.dialogimage);
                ParseFile photoFile = news.getParseFile(照片);
                如果(photoFile!= NULL){
                    newsImage.setParseFile(photoFile);
                    newsImage.loadInBackground(新GetDataCallback(){
                        @覆盖
                        公共无效完成(字节[]数据,ParseException的E){
                            Log.d(做事先知情同意,data.toString());                        }
                    });
                }其他{
                    loader.setVisibility(View.GONE);
                    newsImage.setBackgroundResource(R.drawable.image40);
                }
                d.show();            }
        });
    }    返回伏;
}}


解决方案

这是我用得到的DB的列表的方法TrackedLocation 对象:

  ParseQuery<&的parseObject GT;查询= ParseQuery.getQuery(TrackedLocation);
query.whereEqualTo(IMEI,helpUtils.getDeviceIDEqualsIMEI());
query.setLimit(1000);
query.findInBackground(新FindCallback<&的parseObject GT;()
{
    @覆盖
     公共无效完成(列表<&的parseObject GT; DataList控件,ParseException的E){}
});

你想用的DataList 的parseObject 的是你将收到一份关于什么完成回调。

i have made this array column in parse.com dashboard.i am able to add values in the array from my app but m not able to get the array or list and using any function on it(even size() ) give null point exception on that line.

i have used many solutions but none worked.

my code where it is giving error.

real = (TextView) v.findViewById(R.id.realtext);
        fake = (TextView) v.findViewById(R.id.faketext);
        realbutton = (ImageButton) v.findViewById(R.id.realbutton);
        fakebutton = (ImageButton) v.findViewById(R.id.fakebutton);
        real.setText(String.valueOf(news.getRealvote()));
        fake.setText(String.valueOf(news.getFake()));
fakebutton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                news.setuserArray(news.getAuthor().getUsername());
                List<ParseObject> a = news.getUserArray();


                Toast.makeText(c, a.toString(), Toast.LENGTH_SHORT).show();//any thing with a.size() etc anything gives error

                news.setFake();
                news.saveInBackground();
                fake.setText(String.valueOf(news.getFake()));

                realbutton.setVisibility(View.GONE);
                fakebutton.setVisibility(View.GONE);

            }
        });

here is my getUserArray() method

public List<ParseObject> getUserArray() {

    return getList("users_rated");
}

the method to store data is working

public void setuserArray(String file) {
    addUnique("users_rated", file);
}

i have tried a lot but no success.plss help me retrieving the array.

are you asking for list adapter??

public class Customnewslistview extends ParseQueryAdapter<News> {

Context c;

public Customnewslistview(Context context) {
    super(context, "News");
    c = context;
}

@Override
public View getItemView(final News news, View v, ViewGroup parent) {

    if (v == null) {
        final TextView real;
        final TextView fake;
        final ImageButton realbutton;
        final ImageButton fakebutton;
        final ProgressBar loader;
        v = View.inflate(getContext(), R.layout.item_list_news_public, null);

        loader = (ProgressBar) v.findViewById(R.id.eachnewsloder);

        ParseImageView newsImage = (ParseImageView) v
                .findViewById(R.id.icon);
        ParseFile photoFile = news.getParseFile("photo");
        if (photoFile != null) {
            newsImage.setParseFile(photoFile);
            newsImage.loadInBackground(new GetDataCallback() {
                @Override
                public void done(byte[] data, ParseException e) {
                    Log.d("done pic", data.toString());
                    loader.setVisibility(View.GONE);
                }
            });
        } else {
            loader.setVisibility(View.GONE);
            newsImage.setBackgroundResource(R.drawable.image40);
        }

        TextView titleTextView = (TextView) v.findViewById(R.id.text1);
        titleTextView.setText(news.getTitle());
        // trying real fake buttons
        real = (TextView) v.findViewById(R.id.realtext);
        fake = (TextView) v.findViewById(R.id.faketext);
        realbutton = (ImageButton) v.findViewById(R.id.realbutton);
        fakebutton = (ImageButton) v.findViewById(R.id.fakebutton);
        real.setText(String.valueOf(news.getRealvote()));
        fake.setText(String.valueOf(news.getFake()));
        realbutton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                news.setuserArray(news.getAuthor().toString());
                news.setRealvote();
                news.saveInBackground();
                real.setText(String.valueOf(news.getRealvote()));

                Toast.makeText(getContext(), "No Cheating",
                        Toast.LENGTH_SHORT).show();

                realbutton.setVisibility(View.GONE);
                fakebutton.setVisibility(View.GONE);

            }
        });
        fakebutton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                news.setuserArray(news.getAuthor().getUsername());
                List<ParseObject> a=null;
                try {
                    a = news.fetchIfNeeded().getList("users_rated");
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


                Toast.makeText(c, a.toString(), Toast.LENGTH_SHORT).show();

                news.setFake();
                news.saveInBackground();
                fake.setText(String.valueOf(news.getFake()));

                realbutton.setVisibility(View.GONE);
                fakebutton.setVisibility(View.GONE);

            }
        });
        titleTextView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Dialog d = new Dialog(c);
                d.setContentView(R.layout.publicnewsdialog);
                d.setTitle("News");
                TextView text = (TextView) d.findViewById(R.id.dialogtext);
                text.setText(news.getTitle());
                // parsing image
                ParseImageView newsImage = (ParseImageView) d
                        .findViewById(R.id.dialogimage);
                ParseFile photoFile = news.getParseFile("photo");
                if (photoFile != null) {
                    newsImage.setParseFile(photoFile);
                    newsImage.loadInBackground(new GetDataCallback() {
                        @Override
                        public void done(byte[] data, ParseException e) {
                            Log.d("done pic", data.toString());

                        }
                    });
                } else {
                    loader.setVisibility(View.GONE);
                    newsImage.setBackgroundResource(R.drawable.image40);
                }
                d.show();

            }
        });
    }

    return v;
}

}

解决方案

This is the method I use to get a List of a DB of TrackedLocation objects:

ParseQuery<ParseObject> query = ParseQuery.getQuery("TrackedLocation"); 
query.whereEqualTo("imei", helpUtils.getDeviceIDEqualsIMEI());
query.setLimit(1000);
query.findInBackground(new FindCallback<ParseObject>() 
{
    @Override
     public void done(List<ParseObject> dataList, ParseException e) {}
});

Do what you want with the dataList of ParseObjects you will receive on the done callback.

这篇关于不能从parse.com检索阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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