我正在开发一款使用解析云的Android应用。我试图通过ParseObjects列表在我的数据库中存储一些值。这是我的按钮点击操作的代码。
Button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText Edit1 = (EditText) findViewById(R.id.editText1);
input_email=Edit1.getText().toString();
if(isNetworkAvailable()) {
if (checkEmail(input_email)) {
ParseObject User = new ParseObject("User");
User.put("Email_Id", input_email);
User.put("Quote_Value", final_quote);
User.saveInBackground();
List<ParseObject> Product= new List<ParseObject>() {
@Override
public void add(int i, ParseObject parseObject) {
}
@Override
public boolean add(ParseObject parseObject) {
return false;
}
@Override
public boolean addAll(int i, Collection<? extends ParseObject> parseObjects) {
return false;
}
@Override
public boolean addAll(Collection<? extends ParseObject> parseObjects) {
return false;
}
@Override
public void clear() {
}
@Override
public boolean contains(Object o) {
return false;
}
@Override
public boolean containsAll(Collection<?> objects) {
return false;
}
@Override
public boolean equals(Object o) {
return false;
}
@Override
public ParseObject get(int i) {
return null;
}
@Override
public int hashCode() {
return 0;
}
@Override
public int indexOf(Object o) {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@NonNull
@Override
public Iterator<ParseObject> iterator() {
return null;
}
@Override
public int lastIndexOf(Object o) {
return 0;
}
@NonNull
@Override
public ListIterator<ParseObject> listIterator() {
return null;
}
@NonNull
@Override
public ListIterator<ParseObject> listIterator(int i) {
return null;
}
@Override
public ParseObject remove(int i) {
return null;
}
@Override
public boolean remove(Object o) {
return false;
}
@Override
public boolean removeAll(Collection<?> objects) {
return false;
}
@Override
public boolean retainAll(Collection<?> objects) {
return false;
}
@Override
public ParseObject set(int i, ParseObject parseObject) {
return null;
}
@Override
public int size() {
return 0;
}
@NonNull
@Override
public List<ParseObject> subList(int i, int i2) {
return null;
}
@NonNull
@Override
public Object[] toArray() {
return new Object[0];
}
@NonNull
@Override
public <T> T[] toArray(T[] ts) {
return null;
}
};
List<Product_database> checked_product_Description = db.getSelectProducts();
for (Product_database pd : checked_product_Description) {
ParseObject product_data = new ParseObject("products");
product_data.put("Product_Description", pd.getProduct_name());
product_data.put("Product_Price", pd.getProduct_prices());
product_data.put("Product_Quantity", pd.getProduct_quantity());
Product.add(product_data);
}
saveAllInBackground(Product);
List<ParseObject> Add_ons= new List<ParseObject>() {
@Override
public void add(int i, ParseObject parseObject) {
}
@Override
public boolean add(ParseObject parseObject) {
return false;
}
@Override
public boolean addAll(int i, Collection<? extends ParseObject> parseObjects) {
return false;
}
@Override
public boolean addAll(Collection<? extends ParseObject> parseObjects) {
return false;
}
@Override
public void clear() {
}
@Override
public boolean contains(Object o) {
return false;
}
@Override
public boolean containsAll(Collection<?> objects) {
return false;
}
@Override
public boolean equals(Object o) {
return false;
}
@Override
public ParseObject get(int i) {
return null;
}
@Override
public int hashCode() {
return 0;
}
@Override
public int indexOf(Object o) {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@NonNull
@Override
public Iterator<ParseObject> iterator() {
return null;
}
@Override
public int lastIndexOf(Object o) {
return 0;
}
@NonNull
@Override
public ListIterator<ParseObject> listIterator() {
return null;
}
@NonNull
@Override
public ListIterator<ParseObject> listIterator(int i) {
return null;
}
@Override
public ParseObject remove(int i) {
return null;
}
@Override
public boolean remove(Object o) {
return false;
}
@Override
public boolean removeAll(Collection<?> objects) {
return false;
}
@Override
public boolean retainAll(Collection<?> objects) {
return false;
}
@Override
public ParseObject set(int i, ParseObject parseObject) {
return null;
}
@Override
public int size() {
return 0;
}
@NonNull
@Override
public List<ParseObject> subList(int i, int i2) {
return null;
}
@NonNull
@Override
public Object[] toArray() {
return new Object[0];
}
@NonNull
@Override
public <T> T[] toArray(T[] ts) {
return null;
}
};
List<Add_on_database> checked_Add_ons_Description = add_db.getSelectAdd_ons();
for (Add_on_database ad : checked_Add_ons_Description) {
ParseObject add_on_data = new ParseObject("add_ons");
add_on_data.put("Add_on_Description", ad.getAdd_on_name());
add_on_data.put("Add_on_Price", ad.getAdd_on_prices());
add_on_data.put("Add_on_Quantity", ad.getAdd_on_quantity());
Add_ons.add(add_on_data);
}
saveAllInBackground(Add_ons);
}
else {
Toast.makeText(getApplicationContext(), "Enter a valid Email Id!!", Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(getApplicationContext(), "Check Your Network Connection. Application needs active network to send mails!!", Toast.LENGTH_SHORT).show();
}
}});
以下是Android Studio中的Logcat:
09-10 04:17:07.462 1266-1266/com.example.chmp.client04 I/Choreographer﹕ Skipped 38 frames! The application may be doing too much work on its main thread.
09-10 04:17:16.650 1266-1266/com.example.chmp.client04 D/AndroidRuntime﹕ Shutting down VM
09-10 04:17:16.650 1266-1266/com.example.chmp.client04 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4db0b20)
09-10 04:17:16.662 1266-1266/com.example.chmp.client04 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.chmp.client04, PID: 1266
java.lang.NullPointerException
at com.parse.ParseTraverser.traverseInternal(ParseTraverser.java:85)
at com.parse.ParseTraverser.traverse(ParseTraverser.java:128)
at com.parse.ParseObject.collectDirtyChildren(ParseObject.java:2188)
at com.parse.ParseObject.collectDirtyChildren(ParseObject.java:2251)
at com.parse.ParseObject.deepSaveAsync(ParseObject.java:2294)
at com.parse.ParseObject.saveAllAsync(ParseObject.java:2447)
at com.parse.ParseObject.saveAllInBackground(ParseObject.java:2646)
at com.parse.ParseObject.saveAllInBackground(ParseObject.java:2657)
at com.example.chmp.client04.UI.email_sender$1.onClick(email_sender.java:216)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
09-10 04:17:19.482 1266-1266/com.example.chmp.client04 I/Process﹕ Sending signal. PID: 1266 SIG: 9
答案 0 :(得分:1)
您正在使用空存根覆盖List方法,这没有意义。而是使用一些非抽象的List实现,ArrayList将是一个很好的候选者。