android - DialogActivity: java.lang.illegalStateException -


while creating dialogactivity getting error @ runtime.it shows java.lang.illegalstateexcepion.

stacktrace:

 e/androidruntime(1685): fatal exception: main  e/androidruntime(1685): process: com.steve.dialogactivity, pid: 1685 e/androidruntime(1685): java.lang.illegalstateexception: not find method onclick(view) in activity class com.steve.dialogactivity.mainactivity onclick handler on view class android.widget.button id 'btn_dislog'  e/androidruntime(1685):    @ android.view.view$1.onclick(view.java:3810)  e/androidruntime(1685):    @ android.view.view.performclick(view.java:4438)  e/androidruntime(1685):    @ android.view.view$performclick.run(view.java:18422)  e/androidruntime(1685):    @ android.os.handler.handlecallback(handler.java:733) e/androidruntime(1685):  @ android.os.handler.dispatchmessage(handler.java:95)  e/androidruntime(1685):    @ android.os.looper.loop(looper.java:136)  e/androidruntime(1685):    @ android.app.activitythread.main(activitythread.java:5017)  e/androidruntime(1685):    @ java.lang.reflect.method.invokenative(native method)  e/androidruntime(1685):    @ java.lang.reflect.method.invoke(method.java:515)  e/androidruntime(1685):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779)  e/androidruntime(1685):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595)  e/androidruntime(1685):    @ dalvik.system.nativestart.main(native method)  e/androidruntime(1685): caused by: java.lang.nosuchmethodexception: onclick [class android.view.view]  e/androidruntime(1685):    @ java.lang.class.getconstructorormethod(class.java:472)  e/androidruntime(1685):    @ java.lang.class.getmethod(class.java:857)  e/androidruntime(1685):    @ android.view.view$1.onclick(view.java:3803)  e/androidruntime(1685):    ... 11 more 

mainactivity.java:

import android.app.activity; import android.app.alertdialog; import android.app.dialog; import android.content.dialoginterface; import android.os.bundle; import android.util.log; import android.view.window; import android.widget.toast;  public class mainactivity extends activity{      charsequence[] items={"google","apple","windows"};     boolean[] itemschecked=new boolean[items.length];      protected void oncreate(bundle savedinstancestate){         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);      }      public void onclick(){         showdialog(0);     }      @override     protected dialog oncreatedialog(int id){         switch(id){         case  0:             return new alertdialog.builder(this).seticon(r.drawable.ic_launcher)                     .settitle("this dialog").setpositivebutton("ok", new dialoginterface.onclicklistener() {                                 @override                                 public void onclick(dialoginterface dialog, int whichbutton) {                                     toast.maketext(getbasecontext(), "ok clicked", toast.length_short).show();                                 }                              }).setnegativebutton("cancel", new dialoginterface.onclicklistener() {                                  @override                                 public void onclick(dialoginterface dialog, int whichbutton) {                                     toast.maketext(getbasecontext(), "cancel clicked", toast.length_short).show();                                 }                             }).setmultichoiceitems(items, itemschecked, new dialoginterface.onmultichoiceclicklistener() {                                   @override                                 public void onclick(dialoginterface dialog, int whichbutton, boolean ischecked) {                                     toast.maketext(getbasecontext(), items[whichbutton]+(ischecked?"checked!":"unchecked!"), toast.length_short).show();                                 }                             }).create();           }         return null;     }   } 

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >     <button        android:id="@+id/btn_dialog"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="click display dislog"        android:onclick="onclick"/>  </linearlayout> 

manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.steve.dialogactivity"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="19" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.steve.dialogactivity.mainactivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </application>  </manifest> 

anybody can me these.thank you.

try way: should pass view argument in method onclick()

public void onclick(view v){     showdialog(0); } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -