02-20 10:37:18.255 13029-13029/avappmobile.mytasks E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: avappmobile.mytasks, PID: 13029
java.util.IllegalFormatConversionException: %d can't format java.lang.String arguments
at java.util.Formatter.badArgumentType(Formatter.java:1489)
at java.util.Formatter.transformFromInteger(Formatter.java:1689)
at java.util.Formatter.transform(Formatter.java:1461)
at java.util.Formatter.doFormat(Formatter.java:1081)
at java.util.Formatter.format(Formatter.java:1042)
at java.util.Formatter.format(Formatter.java:1011)
at java.lang.String.format(String.java:1803)
at android.content.res.Resources.getString(Resources.java:1453)
at android.content.Context.getString(Context.java:397)
at android.widget.SimpleMonthView$MonthViewTouchHelper.getItemDescription(SimpleMonthView.java:684)
at android.widget.SimpleMonthView$MonthViewTouchHelper.onPopulateNodeForVirtualView(SimpleMonthView.java:628)
at com.android.internal.widget.ExploreByTouchHelper.createNodeForChild(ExploreByTouchHelper.java:377)
at com.android.internal.widget.ExploreByTouchHelper.createNode(ExploreByTouchHelper.java:316)
at com.android.internal.widget.ExploreByTouchHelper.access$100(ExploreByTouchHelper.java:50)
at com.android.internal.widget.ExploreByTouchHelper$ExploreByTouchNodeProvider.createAccessibilityNodeInfo(ExploreByTouchHelper.java:711)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfVirtualNode(AccessibilityInteractionController.java:1179)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1091)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1087)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1087)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1087)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1087)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1087)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1087)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1087)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1087)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1087)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:888)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:155)
at android.view.AccessibilityInteractionController.access$400(AccessibilityInteractionController.java:53)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1236)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5834)
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:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
下面是我的DialogFragment代码:
public class DatePFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
DatePicker dp;
OnDatePickedListener mCallback;
Integer mLayoutId = null;
// Interface definition
public interface OnDatePickedListener {
public void onDatePicked(int textId, int year, int month, int day);
}
// make sure the Activity implement the OnDatePickedListener
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mCallback = (OnDatePickedListener)activity;
}
catch (final ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnDatePickedListener");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
mCallback = (OnDatePickedListener)getActivity();
Calendar cal = Calendar.getInstance();
Bundle bundle = this.getArguments();
mLayoutId = bundle.getInt("layoutId");
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
View view = getActivity().getLayoutInflater().inflate(R.layout.datepfragment, null);
dp = (DatePicker) view.findViewById(R.id.datePicker);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(),this,year, month, day);
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
if (mCallback != null) {
// Use the date chosen by the user.
mCallback.onDatePicked(mLayoutId, year, monthOfYear+1, dayOfMonth);
}
}
}
下面是相关的xml布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/txtDPTitle"
android:id="@+id/txtDPTitle"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btnDPValidate"
android:id="@+id/btnDPValidate"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp" />
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/datePicker"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="0dp"
android:datePickerMode="spinner"
android:calendarViewShown="false"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
事实上,我有两种问题(导致应用程序崩溃):
这是三星在LollipopUI实现中的一个错误。它影响了Galaxy S4、S5、Note 3以及可能更多的设备。对我们来说,它发生在de_DE和de_AT语言上,但它似乎是一个影响多种语言的问题。
我通过强制三星设备为日期选择器使用全息主题来修复它。在我们的DatePickerFragment中:
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
/* calendar code here */
Context context = getActivity();
if (isBrokenSamsungDevice()) {
context = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Light_Dialog);
}
return new DatePickerDialog(context, this, year, month, day);
}
private static boolean isBrokenSamsungDevice() {
return (Build.MANUFACTURER.equalsIgnoreCase("samsung")
&& isBetweenAndroidVersions(
Build.VERSION_CODES.LOLLIPOP,
Build.VERSION_CODES.LOLLIPOP_MR1));
}
private static boolean isBetweenAndroidVersions(int min, int max) {
return Build.VERSION.SDK_INT >= min && Build.VERSION.SDK_INT <= max;
}
多亏了三星,他们的用户将不会得到漂亮的材料设计的日期选择器。
自定义datePicker代码: 这就是我如何在我的主要活动中使用这个类: Logcat:
当我在设备上运行应用程序时单击增量按钮时,我的应用程序意外地强制执行这是我的activity_main.xml代码 这是我的mainactivity.java文件 这是调试报告05-23 22:14:45.695 297 36-29736/com.orton.birthdayCard E/AndroidRuntime:致命异常:主进程:com.orton.birthdayCard,PID:2973
我想显示datepicker弹出窗口。我找到了一些例子,但我没有得到正确的理解。我有一个edittext,我希望当我单击edittext时,datepicker对话框应该弹出,在设置日期后,日期应该以DD/MM/YYYY格式显示在edittext中。请提供给我样本代码或良好的链接。
每当我单击登录页面中的“注册”按钮时,应用程序就会崩溃,无法移动到下一个活动。我已经在这个问题上纠缠了一天,似乎在任何地方都找不到解决办法。 下面是我为注册按钮方法编写的代码。(和是文本输入布局) Logcat在第7行显示错误,即ref.child(…行)。我尝试了第7行的替代方法,如:
代码如下: 这是我面临的错误:
问题内容: 我一直试图在Eclipse中制作我的第一个android应用程序(一个简单的温度转换器),但是当我单击手机上的按钮时,该应用程序崩溃了。这是完整的Java代码 单击按钮时的LogCat 最后是按钮的xml 我不确定如何解决此问题,因此希望有人可以提供帮助。谢谢。 问题答案: 首先初始化您的按钮,然后将onclicklistener设置为它们 同样设置另一个按钮