我在尝试从Parse.com(后端数据库)提取数据时遇到此错误。
错误是说Businesses类中的put函数不为null。我不确定这意味着什么,因为它不是假设不是空的?我想显示企业的名称,所以名称必须在那里才能做到这一点吗?
或者是说其他词中的值不能为空?
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
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();
}
}
答案 0 :(得分:0)
在旁边方法的类别类中更改此代码。
@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);
}
}
});
}
}