Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to bind onClick xml onto a method in my activity
    text
    copied!<p>I've got the following Button declared in my main.xml</p> <pre><code>&lt;Button android:name="@+id/clickedStartService" android:layout_height="wrap_content" android:layout_width="wrap_content" android:onClick="clickedStartService" android:text="Start" /&gt; &lt;Button android:name="@+id/clickedStopService" android:layout_height="wrap_content" android:layout_width="wrap_content" android:onClick="clickedStopService" android:text="Stop" /&gt; </code></pre> <p>And I have the following methods in the activity..</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void clickedStartService(View v) { startService(new Intent(this, LocalService.class)); } public void clickedStopService(View v) { stopService(new Intent(this, LocalService.class)); } </code></pre> <p>I'm getting the following error when I click the button. I have tried rebuilding the project in my IDE and have also restarted the emulator, but same error re-appears. I've followed the documentation on the <a href="http://developer.android.com/reference/android/widget/Button.html" rel="nofollow">Android developers</a> site, and I've had this working in a separate project, I just can't get it to work here..</p> <pre><code>ERROR/AndroidRuntime(335): FATAL EXCEPTION: main java.lang.IllegalStateException: Could not find a method clickedStartService(View) in the activity class com.jameselsey.observerpattern.MyApp for onClick handler on view class android.widget.Button at android.view.View$1.onClick(View.java:2059) at android.view.View.performClick(View.java:2408) at android.view.View$PerformClick.run(View.java:8816) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4627) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NoSuchMethodException at java.lang.Class.getDeclaredMethods(Native Method) at java.lang.ClassCache.getDeclaredPublicMethods(ClassCache.java:166) at java.lang.ClassCache.getDeclaredMethods(ClassCache.java:179) at java.lang.ClassCache.findAllMethods(ClassCache.java:249) at java.lang.ClassCache.getFullListOfMethods(ClassCache.java:223) at java.lang.ClassCache.getAllPublicMethods(ClassCache.java:204) at java.lang.Class.getMethod(Class.java:984) at android.view.View$1.onClick(View.java:2052) ... 11 more </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload