android - java.lang.IllegalStateException: Could not find a method ExitApp(View) in the activity class com.test.apps.test.MainActivity for onClick -


so i'm using android studio first time. i'm got 2 activities, when main activity loads checks login flag set, if not loads login activity.

however, when i'm in login activity , use button onclick call method in activity , reason, java not looking in activity looking in main , throwing following error:

java.lang.illegalstateexception: not find method exitapp(view) in activity class com.test.apps.test.mainactivity onclick 

i'm sure i'm missing setting missing, understanding java searches current class first parent class, why button in second activity looking in main activity?

androidmanifest.xml

<activity android:name=".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>     <activity         android:name=".loginactivity"         android:label="@string/title_activity_login"         android:windowsoftinputmode="adjustresize|statevisible" >         <intent-filter>             <action android:name="android.intent.action.view" />         </intent-filter>     </activity> 

mainactivity.java

protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); string loggedin = preferences.getstring("logged_in", "");     if (loggedin.equals("")) {        intent intent = new intent(this, loginactivity.class);        startactivity(intent);     }     else {         setcontentview(r.layout.activity_main);     } } 

loginactivity.java

import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.edittext; import android.widget.toast; import android.view.view.onclicklistener; import android.app.activity;  public class loginactivity extends actionbaractivity { private edittext username; private edittext password;  public void exitapp(view view){     finish(); } 

activity_login.xml

<button android:layout_width="250dp" android:layout_height="50dp" android:text="login" android:id="@+id/btnlogin" android:layout_below="@+id/txtpassword" android:layout_centerhorizontal="true" android:layout_margintop="48dp" android:nestedscrollingenabled="false" android:onclick="exitapp" android:clickable="true"/> 

any great...

your method exitapp() doesn´t exist in activity mainactivity:

could not find method exitapp(view) in activity class com.test.apps.test.mainactivity onclick   

if want execute method exitapp() loginactivity load correct layout activity_login.xml

public class loginactivity extends actionbaractivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_login.xml);     } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -