本文介绍了java.lang.IllegalArgumentException:值不能为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从Parse.com(后端数据库)提取数据时出现此错误.

I'm getting this error when trying to pull data from Parse.com (backend database).

该错误表明Businesses类中的put函数不为null.我不确定这是什么意思,因为它不是应该为null吗?我想显示商户名称,所以必须要有商户名称才能做到这一点?

The error is saying that the put function in the Businesses class is not null. I'm not sure what that means, because isn't it suppose to not be null? I want to display the name of businesses so the name would have to be there in order to do this right?

还是说其他值不能为null?

Or is it saying that the value can't be null in others words?

FATAL EXCEPTION: main
    Process: zafir.com.app, PID: 13295
    java.lang.IllegalArgumentException: value may not be null.
        at com.parse.ParseObject.performPut(ParseObject.java:2918)
        at com.parse.ParseObject.put(ParseObject.java:2909)
        at zafir.com.app.Businesses.setName(Businesses.java:20)
        at zafir.com.app.Fragments.Categories$1.done(Categories.java:57)
        at zafir.com.app.Fragments.Categories$1.done(Categories.java:50)
        at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:115)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5283)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

企业

package zafir.com.app;

import com.parse.ParseClassName;
import com.parse.ParseObject;


@ParseClassName("Businesses")
public class Businesses extends ParseObject
{

    private String Name;

    public String getName()
    {
        return getString("Name");
    }

    public void setName(String name)
    {
        put("Name", name);
    }

    public String getCategory()
    {
        return getString("Category");
    }

    public void setCategory(String category)
    {
        put("Category", category);
    }

    public String getEmail()
    {
        return getString("Email");
    }

    public void setEmail(String email)
    {
        put("Email", email);
    }

    public String getLocation()
    {
        return getString("Location");
    }

    public void setLocation(String location)
    {
        put("Location", location);
    }

    public String getPhone()
    {
        return getString("Phone");
    }

    public void setPhone(String phone)
    {
        put("Phone", phone);
    }

    public String getWebsite()
    {
        return getString("Website");
    }

    public void setWebsite(String website)
    {
        put("Website", website);
    }
}

类别

    public class Categories extends Fragment
{

    List<Businesses> data = new ArrayList<>();
    private RecyclerView recView = null;
    private RecyclerAdapter zAdapter;

    public Categories()
    {
        // Required empty public constructor
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {

        ParseQuery<Businesses> query = new ParseQuery<>("Businesses");
        query.findInBackground(new FindCallback<Businesses>()
        {
            @Override
            public void done(List<Businesses> list, ParseException e)
            {
                if(e == null)
                {
                    for(Businesses businesses : list)
                    {
                        Businesses bizList = new Businesses();
                        bizList.setName(businesses.getName());
                        bizList.setPhone(businesses.getPhone());
                        bizList.setEmail(businesses.getEmail());
                        bizList.setWebsite(businesses.getWebsite());
                        bizList.setLocation(businesses.getLocation());
                        bizList.setCategory(businesses.getCategory());
                        data.add(bizList);
                    }
                }
            }
        });

        View rootView = inflater.inflate(R.layout.fragment_categories, container, false);

        recView = (RecyclerView) rootView.findViewById(R.id.recview_categories);
        recView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recView.setAdapter(zAdapter);

        return inflater.inflate(R.layout.fragment_categories, container, false);
    }

}

RecyclerAdapter

RecyclerAdapter

    public static class ViewHolder extends RecyclerView.ViewHolder
    {
        public TextView zName;
        public TextView zPhone;
        public TextView zEmail;
        public TextView zWebsite;
        public TextView zLocation;
        public TextView zCategory;

        public ViewHolder(View itemView)
        {
            super(itemView);

            zName = (TextView) itemView.findViewById(R.id.name);
            zPhone = (TextView) itemView.findViewById(R.id.phone);
            zEmail = (TextView) itemView.findViewById(R.id.email);
            zWebsite = (TextView) itemView.findViewById(R.id.website);
            zLocation = (TextView) itemView.findViewById(R.id.location);
            zCategory = (TextView) itemView.findViewById(R.id.category);
        }
    }

    public RecyclerAdapter(Context context,List<Businesses> data)
    {
        inflater=LayoutInflater.from(context);
        this.data= data;
    }

    @Override
    public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        Context context = parent.getContext();
        LayoutInflater inflater = LayoutInflater.from(context);

        View recView = inflater.inflate(R.layout.recycler_layout, parent, false);

        ViewHolder ViewHolder = new ViewHolder(recView);

        return ViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerAdapter.ViewHolder viewHolder, int position)
    {
        Businesses businesses = data.get(position);

        TextView name = viewHolder.zName;
        name.setText(businesses.getName());

        TextView phone = viewHolder.zPhone;
        phone.setText(businesses.getPhone());

        TextView email = viewHolder.zEmail;
        email.setText(businesses.getEmail());

        TextView website = viewHolder.zWebsite;
        website.setText(businesses.getWebsite());

        TextView location = viewHolder.zLocation;
        location.setText(businesses.getLocation());

        TextView category = viewHolder.zCategory;
        category.setText(businesses.getCategory());
    }

    @Override
    public int getItemCount()
    {
        return data.size();
    }
}

推荐答案

在side方法中的Categories类上更改此代码.

change this code at your Categories Class in side method.

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {

        ParseQuery<Businesses> query = new ParseQuery<>("Businesses");
        query.findInBackground(new FindCallback<Businesses>()
        {
            @Override
            public void done(List<Businesses> list, ParseException e)
            {
                if(e == null)
                {
                    for(Businesses businesses : list)
                    {
                        Businesses bizList = new Businesses();
                        bizList.setName(businesses.getName());
                        bizList.setPhone(businesses.getPhone());
                        bizList.setEmail(businesses.getEmail());
                        bizList.setWebsite(businesses.getWebsite());
                        bizList.setLocation(businesses.getLocation());
                        bizList.setCategory(businesses.getCategory());
                        data.add(bizList);
                    }
//find in background is one type of thered so when data is added into array list then u can bind your adapter
                    View rootView = inflater.inflate(R.layout.fragment_categories, container, false);

                    recView = (RecyclerView) rootView.findViewById(R.id.recview_categories);
                    recView.setLayoutManager(new LinearLayoutManager(getActivity()));
                    recView.setAdapter(zAdapter);

                    return inflater.inflate(R.layout.fragment_categories, container, false);
                }
            }
        });


    }

}

这篇关于java.lang.IllegalArgumentException:值不能为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 22:19