android - App crash using intent to switch activity -
it's simple login activity when must switch activity, app crash. tried use normal form pubic void onclick() {...} doesn't work.
login.java
package com.example.corrado_mattia_danny.face_offbrains; import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.checkedtextview; import android.widget.edittext; import android.widget.toast; public class login extends activity { private player player; private button login; private edittext username; private edittext password; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_login); login=(button)findviewbyid(r.id.button_sign_in); username=(edittext)findviewbyid(r.id.nickname); password=(edittext)findviewbyid(r.id.password); string = username.gettext().tostring(); string b = password.gettext().tostring(); player.inseriscicredenziali(a,b); //insert player class //username , password signin(); } public void signin() { intent intent = new intent(this, home.class); startactivity(intent); } }
activity_login.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.example.corrado_mattia_danny.face_offbrains.login" android:background="@drawable/sfondo_custom" > <edittext android:layout_width="wrap_content" android:layout_height="35dp" android:inputtype="textpersonname" android:hint="nickname" android:ems="10" android:id="@+id/nickname" android:linksclickable="false" android:textcolor="#ff000000" android:background="#ffd4d4d4" android:textstyle="normal|bold|italic" android:layout_margintop="100dp" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /> <edittext android:layout_width="wrap_content" android:layout_height="35dp" android:inputtype="textpassword" android:ems="10" android:id="@+id/password" android:layout_below="@+id/nickname" android:layout_alignstart="@+id/nickname" android:layout_margintop="30dp" android:hint="password" android:textcolor="#ff000000" android:background="#ffd4d4d4" android:textstyle="normal|bold|italic" /> <button style="?android:attr/buttonstylesmall" android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/button_sign_in" android:background="#ffffeb00" android:layout_centervertical="true" android:layout_toendof="@+id/nickname" android:layout_marginleft="10dp" android:onclick="signin"/> </relativelayout>
home.java
the buttons in home doesn't work yet.
package com.example.corrado_mattia_danny.face_offbrains; import android.app.activity; import android.content.intent; 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.button; public class home extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_home); intent intent = getintent(); button bottone_sfida_amico = (button)findviewbyid(r.id.button_sfida_amico); button bottone_avversario_casuale = (button)findviewbyid(r.id.button_avversario_casuale); } }
}
when set method through android:onclick
attribute, method signin()
must have parameter view
, source of event. so, declare method follows:
public void signin(view view) { ... }
Comments
Post a Comment