Tuesday 15 July 2014

java - App chrashes when I click button and select item on spinner -


According to what object is selected on the spinner, I want to take a certain action on the button press. This is what I have so far received:

  public void submitButton (see V) {button b1 = (button) findViewById (R.id.submitButton); Final Spinner S1 = (Spinner) Find VVBIID (RID Spinner 1); Final Reference Reference = This; b1.setOnClickListener (New View.OnClickListener () {@Override public void onClick (View v) {final int status = s1.getSelectedItemPosition (); switch (status) {case 0: AlertDialog.Builder spinnerErrorBuilder = new AlertDialogkBuilder (reference ) (( "OK", the new DialogInterface.OnClickListener (spinnerErrorBuilder.setPositiveButton "warning"), SpinnerErrorBuilderksetMessage () "Please select an item from the list") {@Override public void onClick (DialogInterface communicate, spinnerErrorBuilder.setTitle Int id) {dialog.cancel ();}}); Alert Dealog Spinner Ehrtar = Spinner IrrBilder.Create (); Spinner Err. Show (); B Rake; case 1: break;}}}); }   

When I compile my app and click on the button, the app crashes and returns to main activity, it does not matter what item The selected (0 or 1) app is still crashing.

  & lt; Button Android: id = "@ + id / submitButton" Android: Layout_width = Can anyone tell me where I went wrong?  

"wrap_content" Android: layout_height = "wrap_content" Android: layout_alignBaseline = "@ + id / editText1" Android: layout_alignBottom = "@ + id / editText1" Android: layout_alignLeft = "@ + id / checkBox25" Android: Text = "Add to String / Content" Android: onClick = "onClick" />

File Logcat:

  06-22 15: 00: 13.455: E / AndroidRuntime (23,409): java.lang.IllegalStateException: Could not get a Law com.example.gw2legendary.Bifrost 'submitButton' visual class android.widget.Button onClick handler with onClick activity class ID (see)    

Your method is named submitButton but your onClick method has xml onClick

Change it is submitButton and your problem is resolved

should be XML

      

No comments:

Post a Comment