vendredi 17 juin 2016

Getting an error after trying to open TimePickerDialog

//When user clicks "choose time"
    public void setTime(View view)    {
        DateTime dateTime = new DateTime().now();
        Context context = getApplicationContext();
        new TimePickerDialog(context,  onTimeSetListener, dateTime.getHourOfDay(), dateTime.getMinuteOfDay(), true).show();
    }

    TimePickerDialog.OnTimeSetListener onTimeSetListener=new TimePickerDialog.OnTimeSetListener() {

        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {


        }
    };

I get an error after the user clicks on the "choose time" button, which should use this method. I know that the onTimeSetListener method is empty, but I don't think it's related to the crash..

This is the error I get after trying to open it up:

> 01:24:51.700 6479-6479/? E/AndroidRuntime: FATAL EXCEPTION: main
> Process: meet.projectoklahoma, PID: 6479
> java.lang.IllegalStateException: Could not execute method for
> android:onClick at
> android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275)
> at android.view.View.performClick(View.java:5609) at
> android.view.View$PerformClick.run(View.java:22238) at
> android.os.Handler.handleCallback(Handler.java:751) at
> android.os.Handler.dispatchMessage(Handler.java:95) at
> android.os.Looper.loop(Looper.java:154) at
> android.app.ActivityThread.main(ActivityThread.java:6044) at
> java.lang.reflect.Method.invoke(Native Method) at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused
> by: java.lang.reflect.InvocationTargetException at
> java.lang.reflect.Method.invoke(Native Method) at
> android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270)
> at android.view.View.performClick(View.java:5609)  at
> android.view.View$PerformClick.run(View.java:22238)  at
> android.os.Handler.handleCallback(Handler.java:751)  at
> android.os.Handler.dispatchMessage(Handler.java:95)  at
> android.os.Looper.loop(Looper.java:154)  at
> android.app.ActivityThread.main(ActivityThread.java:6044)  at
> java.lang.reflect.Method.invoke(Native Method)  at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
> Caused by: android.view.WindowManager$BadTokenException: Unable to add
> window -- token null is not for an application at
> android.view.ViewRootImpl.setView(ViewRootImpl.java:685) at
> android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
> at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
> at android.app.Dialog.show(Dialog.java:316) at
> meet.projectoklahoma.Activities.CreateEventActivity.setTime(CreateEventActivity.java:213)
> at java.lang.reflect.Method.invoke(Native Method)  at
> android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270)
> at android.view.View.performClick(View.java:5609)  at
> android.view.View$PerformClick.run(View.java:22238)  at
> android.os.Handler.handleCallback(Handler.java:751)  at
> android.os.Handler.dispatchMessage(Handler.java:95)  at
> android.os.Looper.loop(Looper.java:154)  at
> android.app.ActivityThread.main(ActivityThread.java:6044)  at
> java.lang.reflect.Method.invoke(Native Method)  at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

EDIT:

The xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="meet.projectoklahoma.Activities.CreateEventActivity">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/eventNameTextBox"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:text="שם האירוע"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Other"
        android:id="@+id/otherButton"
        android:onClick="setDate"
        android:layout_alignTop="@+id/tomorrowButton"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/which_day"
        android:id="@+id/whichDayTxt"
        android:layout_below="@+id/eventNameTextBox"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Tomorrow"
        android:id="@+id/tomorrowButton"
        android:onClick="tomorrow"
        android:layout_alignTop="@+id/todayButton"
        android:layout_toRightOf="@+id/otherButton"
        android:layout_toEndOf="@+id/otherButton" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Today"
        android:id="@+id/todayButton"
        android:onClick="today"
        android:layout_above="@+id/dayTxt"
        android:layout_toRightOf="@+id/tomorrowButton"
        android:layout_toEndOf="@+id/tomorrowButton" />

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/invitaionsList"
        android:choiceMode="multipleChoice"
        android:layout_above="@+id/SaveEventButton"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_below="@+id/whichTimeBtn" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="סבבה"
        android:id="@+id/SaveEventButton"
        android:onClick="createEvent"
        android:layout_alignParentBottom="true"
        android:layout_toLeftOf="@+id/tomorrowButton"
        android:layout_toStartOf="@+id/tomorrowButton" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/dateTxt"
        android:layout_below="@+id/whichDayTxt"
        android:layout_alignRight="@+id/whichDayTxt"
        android:layout_alignEnd="@+id/whichDayTxt" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/dayTxt"
        android:layout_below="@+id/dateTxt"
        android:layout_alignRight="@+id/dateTxt"
        android:layout_alignEnd="@+id/dateTxt" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/which_time"
        android:id="@+id/timeTxt"
        android:layout_below="@+id/dayTxt"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/choose_time"
        android:id="@+id/whichTimeBtn"
        android:layout_alignTop="@+id/timeTxt"
        android:layout_alignLeft="@+id/todayButton"
        android:layout_alignStart="@+id/todayButton"
        android:onClick="setTime"
        />


</RelativeLayout>

Aucun commentaire:

Enregistrer un commentaire