-1

I am a novice. My intention is to bring about a dialogue box when the user clicks a button. The dialogue box is supposed to contain an editable text area where the user input some data, and a "Create", and "Cancel" button. I linked the button to my method via XML. However, everytime I run it the app crashes, just saying "(X App) has stopped".

TerritoryList.java:

    /*Called upon when user clicks "Create new territory" button*/

    private void creationDialog (View v) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Buisiness Call Creation");
    alert.setMessage("Create a new business call");

    //EditText view for user input
    final EditText input = new EditText(this);
    alert.setView(input);

    alert.setPositiveButton("Create", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface d, int whichButton) {
            String value = input.getText().toString();
            //Do something with the value
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface d, int whichButton) {
            //Cancelled. Do nothing
        }
    });
}
}

Here is my activity_territory_list.xml (just the Button):

  <Button
    android:id="@+id/create_new_call"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="67dp"
    android:text="@string/create_territory"
    android:onClick="creationDialog" />

I have taken the advice of @323go, and here is what I THINK is the correct LogCat:

12-22 19:02:11.582: E/AndroidRuntime(2138): FATAL EXCEPTION: main
12-22 19:02:11.582: E/AndroidRuntime(2138): Process: com.example.buninessterritory1, PID: 2138
12-22 19:02:11.582: E/AndroidRuntime(2138): java.lang.IllegalStateException: Could not find a method creationDialog(View) in the activity class com.example.buninessterritory1.TerritoryList for onClick handler on view class android.widget.Button with id 'create_new_call'
12-22 19:02:11.582: E/AndroidRuntime(2138):     at android.view.View$1.onClick(View.java:3978)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at android.view.View.performClick(View.java:4659)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at android.view.View$PerformClick.run(View.java:19462)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at android.os.Handler.handleCallback(Handler.java:733)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at android.os.Handler.dispatchMessage(Handler.java:95)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at android.os.Looper.loop(Looper.java:146)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at android.app.ActivityThread.main(ActivityThread.java:5692)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at java.lang.reflect.Method.invokeNative(Native Method)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at java.lang.reflect.Method.invoke(Method.java:515)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
12-22 19:02:11.582: E/AndroidRuntime(2138):     at dalvik.system.NativeStart.main(Native Method)
Mr Chasi
  • 437
  • 1
  • 6
  • 18

1 Answers1

2

java.lang.IllegalStateException: Could not find a method creationDialog(View) in the activity class com.example.buninessterritory1.TerritoryList for onClick handler on view class android.widget.Button with id 'create_new_call'

Methods invoked via the onClick XML attribute must be public, not private.

laalto
  • 150,114
  • 66
  • 286
  • 303
  • Okay, thanks great thanks, it no longer crashes. However, upon clicking, there is no activity... The dialogue box isn't brought up – Mr Chasi Dec 22 '14 at 19:19
  • You also need to add `alert.create();` and `alert.show()`. As it stands, the dialog will neither created nor shown when the "Create" button is pressed. – Willis Dec 22 '14 at 19:20
  • Ah that's great, thanks! However, the Title, message and TextView show, but as for my 2 buttons, there aren't there.... – Mr Chasi Dec 22 '14 at 19:32
  • Make sure that the calls to `alert.create();` and `alert.show()` are AFTER the calls to `alert.setNegativeButton` and `alert.setPositiveButton` otherwise they will not appear. – Willis Dec 22 '14 at 19:42