[英]Date datatype in parse
I am trying to send date datatype in to Parse.com database. 我正在尝试将日期数据类型发送到Parse.com数据库。 I am neither able to send data or get any app crash message, not sure what is going on..
我既无法发送数据,也无法收到任何应用崩溃消息,不确定发生了什么。
This is the code. 这是代码。
buttonPlacebet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ParseUser currentUser = ParseUser.getCurrentUser();
/** if (currentUser != null)
{
}
else
{
// show the signup or login screen
} **/
final String Betname = etBetName.getText().toString().trim();
final String BetDescription = etDescription.getText().toString().trim();
final int Betvalue = seekBarValue.getProgress();
final String Cat1 = cat1.getSelectedItem().toString();
final String Cat2 = cat2.getSelectedItem().toString();
String endDate = textEndDate.getText().toString();
// = "03/26/2012 11:49:00 AM";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date convertedDate = new Date();
try {
convertedDate = dateFormat.parse(endDate);
actualendDate = convertedDate;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d(TAG, "onCreate() Restoring previous state");
ParseObject bets = new ParseObject("Bets");
bets.put("BetName", Betname);
bets.put("BetDescription", BetDescription);
bets.put("BetValue",Betvalue);
if(cbPvtbet.isChecked())
{
bets.put("PrivateBet","True");
}
else
{
bets.put("PrivateBet","False");
}
if(cbReal.isChecked())
{
bets.put("RealBet","True");
}
else
{
bets.put("RealBet","False");
}
bets.put("Cat1",Cat1);
bets.put("Cat2",Cat2);
endDate = actualendDate.toString();
bets.put("EndDate",actualendDate);
bets.saveInBackground();
}
});
}
I am guessing I am doing something wrong with the date datatype not converting/parsing properly. 我猜想我在日期数据类型上做错了什么,而不能正确地转换/解析。 Tks
ks
Adding Log cat (right when I press the button), but frankly there is literally nothing in the logcat that is showing up.. 添加Log cat(当我按下按钮时是正确的),但是坦率地说,logcat中实际上没有任何显示。
05-30 21:49:25.652: E/AndroidRuntime(27738): FATAL EXCEPTION: main
05-30 21:49:25.652: E/AndroidRuntime(27738): Process: com.techiequickie.bharath.betonanything, PID: 27738
05-30 21:49:25.652: E/AndroidRuntime(27738): java.lang.NullPointerException
05-30 21:49:25.652: E/AndroidRuntime(27738): at com.techiequickie.bharath.betonanything.NewBet$1.onClick(NewBet.java:136)
05-30 21:49:25.652: E/AndroidRuntime(27738): at android.view.View.performClick(View.java:4480)
05-30 21:49:25.652: E/AndroidRuntime(27738): at android.view.View$PerformClick.run(View.java:18686)
05-30 21:49:25.652: E/AndroidRuntime(27738): at android.os.Handler.handleCallback(Handler.java:733)
05-30 21:49:25.652: E/AndroidRuntime(27738): at android.os.Handler.dispatchMessage(Handler.java:95)
05-30 21:49:25.652: E/AndroidRuntime(27738): at android.os.Looper.loop(Looper.java:157)
05-30 21:49:25.652: E/AndroidRuntime(27738): at android.app.ActivityThread.main(ActivityThread.java:5872)
05-30 21:49:25.652: E/AndroidRuntime(27738): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 21:49:25.652: E/AndroidRuntime(27738): at java.lang.reflect.Method.invoke(Method.java:515)
05-30 21:49:25.652: E/AndroidRuntime(27738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-30 21:49:25.652: E/AndroidRuntime(27738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
05-30 21:49:25.652: E/AndroidRuntime(27738): at dalvik.system.NativeStart.main(Native Method)
As your log shows NullPointerException try to look at all your variables, especially on the actualendDate
cause you're trying to initialize it with date parsed from string input. 如您的日志所示, NullPointerException请尝试查看所有变量,尤其是在
actualendDate
上,因为您尝试使用从字符串输入中解析的日期来初始化它。 And this is the place where everything's gone wrong. 这是所有发生错误的地方。
Look at your sample date input: "03/26/2012 11:49:00 AM"
and compare it with pattern you provided for SimpleDateFormat: "yyyy-MM-dd"
. 查看您的示例日期输入:
"03/26/2012 11:49:00 AM"
,并将其与您为SimpleDateFormat提供的模式: "yyyy-MM-dd"
。 They're completely different. 他们是完全不同的。 That's why ParseException's risen and your
actualendDate
is not initialized and refers to Null 这就是为什么ParseException升高且您的
actualendDate
未初始化并引用Null的原因
So the solution is to look at SimpleDateFormat documentation and change 因此,解决方案是查看SimpleDateFormat文档并进行更改
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
to 至
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.