我正在使用parse.com,我创建了一个广告系列创建者。 但是,在提交时,它会崩溃。 我有:
CreateNewCampaign java file:
package com.alibdeir.signupactivity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.parse.Parse;
import com.parse.ParseObject;
import java.util.Calendar;
public class CreateNewCampaign extends AppCompatActivity {
Spinner typeSpinner;
Button datePicker;
EditText titleEditText,descriptionEditText,countEditText,actionEditText;
TextView dateTextView;
int day_x;
int month_x;
int year_x;
static final int DIALOG_ID=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_new_campaign);
Parse.initialize(this, "g***************8kJy8piZZD4JRab", "BzguaPll0zUC8lU5******************zFV");
//region set spinner array+
typeSpinner = (Spinner) findViewById(R.id.typeDropDown);
ArrayAdapter<CharSequence> dropDownTypeAdapter = ArrayAdapter.createFromResource(this,
R.array.typeDropDown, android.R.layout.simple_spinner_item);
dropDownTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
typeSpinner.setAdapter(dropDownTypeAdapter);
//endregion
titleEditText = (EditText) findViewById(R.id.titleEditText);
descriptionEditText = (EditText) findViewById(R.id.descriptionEditText);
countEditText = (EditText) findViewById(R.id.CountEditText);
actionEditText = (EditText)findViewById(R.id.actionEditText);
datePicker = (Button) findViewById(R.id.expirationDateButton);
dateTextView = (TextView) findViewById(R.id.dateTextView);
Calendar cal = Calendar.getInstance();
day_x = cal.get(Calendar.DAY_OF_MONTH);
month_x = cal.get(Calendar.MONTH);
year_x = cal.get(Calendar.YEAR);
}
public void datePickerOnCLick(View v){
showDialog(DIALOG_ID);
}
@Override
protected Dialog onCreateDialog(int id){
if(id==DIALOG_ID)
return new DatePickerDialog(this,dpickerListener,year_x,month_x,day_x);
return null;
}
private DatePickerDialog.OnDateSetListener dpickerListener
= new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
year_x = year;
month_x = monthOfYear;
day_x = dayOfMonth;
String dateString = day_x + "/" + month_x + "/" + year_x;
dateTextView.setText(dateString);
}
};
public void createNewCampaign(View v){
//region editTextStrings
String typeSpinnerResultString = typeSpinner.getSelectedItem().toString();
String titleResultString = titleEditText.getText().toString();
String descriptionResultString = descriptionEditText.getText().toString();
int countResultInt = Integer.parseInt(countEditText.getText().toString());
String actionResultString = actionEditText.getText().toString();
//endregion
if(titleResultString.length()<6){
Context titleLengthErrorContext = getApplicationContext();
CharSequence titleLengthErrorText = "Your title must be at least 6 characters";
int titleLengthErrorDuration = Toast.LENGTH_LONG;
Toast titleLengthError = Toast.makeText(titleLengthErrorContext,titleLengthErrorText,titleLengthErrorDuration);
titleLengthError.show();
}
if(titleResultString.isEmpty()){
Context titleLengthErrorContext = getApplicationContext();
CharSequence titleLengthErrorText = "Your title must be at least 6 characters";
int titleLengthErrorDuration = Toast.LENGTH_LONG;
Toast titleLengthError = Toast.makeText(titleLengthErrorContext,titleLengthErrorText,titleLengthErrorDuration);
titleLengthError.show();
}
if(descriptionResultString.length()<15){
Context descriptionLengthErrorContext = getApplicationContext();
CharSequence descriptionLengthErrorText = "Your description must be at least 15 characters";
int descriptionLengthErrorDuration = Toast.LENGTH_LONG;
Toast descriptionLengthError = Toast.makeText(descriptionLengthErrorContext,descriptionLengthErrorText,descriptionLengthErrorDuration);
descriptionLengthError.show();
}
if(descriptionResultString.isEmpty()){
Context descriptionLengthErrorContext = getApplicationContext();
CharSequence descriptionLengthErrorText = "Your description must be at least 15 characters";
int descriptionLengthErrorDuration = Toast.LENGTH_LONG;
Toast descriptionLengthError = Toast.makeText(descriptionLengthErrorContext,descriptionLengthErrorText,descriptionLengthErrorDuration);
descriptionLengthError.show();
}
if(countResultInt==0){
Context countSizeErrorContext = getApplicationContext();
CharSequence countSizeErrorText = "Your count must be greater than 0";
int countSizeErrorDuration = Toast.LENGTH_LONG;
Toast countSizeError = Toast.makeText(countSizeErrorContext,countSizeErrorText,countSizeErrorDuration);
countSizeError.show();
}
if(actionResultString.length()<4){
Context actionLengthErrorContext = getApplicationContext();
CharSequence actionLengthErrorText = "Your action must contain 4 characters";
int actionLengthErrorDuration = Toast.LENGTH_LONG;
Toast actionLengthError = Toast.makeText(actionLengthErrorContext,actionLengthErrorText,actionLengthErrorDuration);
actionLengthError.show();
}
if(titleResultString.length()>15){
Context titleLengthErrorContext = getApplicationContext();
CharSequence titleLengthErrorText = "Your title must be less than 15 characters";
int titleLengthErrorDuration = Toast.LENGTH_LONG;
Toast titleLengthError = Toast.makeText(titleLengthErrorContext,titleLengthErrorText,titleLengthErrorDuration);
titleLengthError.show();
}
if(descriptionResultString.length()>512){
Context descriptionLengthErrorContext = getApplicationContext();
CharSequence descriptionLengthErrorText = "Your description must be less that 512 characters";
int descriptionLengthErrorDuration = Toast.LENGTH_LONG;
Toast descriptionLengthError = Toast.makeText(descriptionLengthErrorContext,descriptionLengthErrorText,descriptionLengthErrorDuration);
descriptionLengthError.show();
}
if(typeSpinnerResultString=="Select an Item"){
Context SpinnerErrorContext = getApplicationContext();
CharSequence SpinnerLengthErrorText = "Please select an item";
int SpinnerLengthErrorDuration = Toast.LENGTH_LONG;
Toast SpinnerLengthError = Toast.makeText(SpinnerErrorContext,SpinnerLengthErrorText,SpinnerLengthErrorDuration);
SpinnerLengthError.show();
}
if(dateTextView.getText()=="dd/mm/yy"){
Context DateErrorContext = getApplicationContext();
CharSequence DateErrorText = "Please select an item";
int DateErrorDuration = Toast.LENGTH_LONG;
Toast DateError = Toast.makeText(DateErrorContext,DateErrorText,DateErrorDuration);
DateError.show();
}
else {
ParseObject listViewCreation = new ParseObject("Campaign");
listViewCreation.put("Title",titleResultString);
listViewCreation.put("Description",descriptionResultString);
listViewCreation.put("Count",countResultInt);
listViewCreation.put("Action",actionResultString);
listViewCreation.put("Visibility",typeSpinnerResultString);
listViewCreation.put("Expiration_Date",dateTextView);
}
}
}
create_new_campaign
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/titleEditText"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:hint="@string/titleHint"
android:layout_toEndOf="@+id/titleTextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/PictureText"
android:id="@+id/pictureTextView"
android:layout_below="@+id/titleEditText"
android:layout_alignParentStart="true"
android:layout_marginTop="38dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/titleText"
android:id="@+id/titleTextView"
android:layout_alignBottom="@+id/titleEditText"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="93.333dp"
android:layout_height="93.333dp"
android:id="@+id/pictureImageView"
android:src="@drawable/abc_btn_check_to_on_mtrl_000"
android:layout_marginStart="25dp"
android:layout_below="@+id/titleEditText"
android:layout_toEndOf="@+id/pictureTextView"
android:contentDescription="picture for the occasion" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/descriptionText"
android:id="@+id/descriptionTextView"
android:layout_below="@+id/pictureImageView"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/descriptionEditText"
android:layout_below="@+id/descriptionTextView"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/titleEditText"
android:hint="@string/descriptionHint" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/ExpirationDateText"
android:id="@+id/expirationDateTextView"
android:layout_below="@+id/descriptionEditText"
android:layout_alignParentStart="true"
android:textSize="20dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose Date"
android:id="@+id/expirationDateButton"
android:layout_alignTop="@+id/expirationDateTextView"
android:layout_toEndOf="@+id/expirationDateTextView"
android:onClick="datePickerOnCLick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/visibilityText"
android:id="@+id/visibilityTextView"
android:layout_below="@+id/expirationDateButton"
android:layout_alignParentStart="true" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/typeDropDown"
android:layout_alignTop="@+id/visibilityTextView"
android:layout_toEndOf="@+id/visibilityTextView"
android:spinnerMode="dropdown" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/countText"
android:id="@+id/CountTextView"
android:layout_below="@+id/typeDropDown"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/CountEditText"
android:layout_below="@+id/typeDropDown"
android:layout_toEndOf="@+id/CountTextView"
android:hint="@string/countHint" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/Action"
android:id="@+id/actionTextView"
android:layout_below="@+id/typeDropDown"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/actionEditText"
android:layout_below="@+id/typeDropDown"
android:layout_alignParentEnd="true"
android:layout_toEndOf="@+id/actionTextView"
android:hint="@string/actionHint" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/submitButton"
android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:onClick="createNewCampaign" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="day/month/year"
android:id="@+id/dateTextView"
android:textColor="#000000"
android:layout_above="@+id/typeDropDown"
android:layout_toEndOf="@+id/expirationDateButton" />
</RelativeLayout>
logcat的:
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: FATAL EXCEPTION: main
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: Process: com.alibdeir.signupactivity, PID: 16161
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: java.lang.IllegalStateException: Could not execute method for android:onClick
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.support.v7.internal.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:278)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.view.View.performClick(View.java:4633)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19270)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.os.Looper.loop(Looper.java:146)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5602)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.support.v7.internal.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:273)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.view.View.performClick(View.java:4633)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19270)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.os.Looper.loop(Looper.java:146)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5602)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: Caused by: java.lang.NumberFormatException: Invalid int: ""
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.Integer.invalidInt(Integer.java:137)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.Integer.parseInt(Integer.java:358)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.Integer.parseInt(Integer.java:331)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at com.alibdeir.signupactivity.CreateNewCampaign.createNewCampaign(CreateNewCampaign.java:81)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.support.v7.internal.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:273)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.view.View.performClick(View.java:4633)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19270)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.os.Looper.loop(Looper.java:146)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5602)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
11-13 18:27:54.216 16161-16161/com.alibdeir.signupactivity E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
请原谅我,如果以前曾经问过这个问题,但是我已经在logct中找到了原因,但我一无所获。如果它是重复的,请告诉我而不是标记
答案 0 :(得分:0)
看起来我最终自己解决了这个问题。由于这已经老了,我忘记了问题是什么,但它已经解决了。 谢谢