Reputation: 8646
On clicking of textview of Loginform i was redering the page towards my Registration form.
It was working fine before writting code in registration form. But suddenly (After writting code in Registration form) , it started giving me above error after clicking on textview ("Please register yourself") in loginform.
After viewing logcat, i came to know that error is on Registration page.
Here is code on my registration page:
public class Register extends Activity implements OnClickListener,OnCheckedChangeListener {
String gender=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
//Toast.makeText(getApplicationContext(),"Load" , Toast.LENGTH_LONG).show();
Button btnRegister =(Button)findViewById(R.id.link_to_login);
final EditText edFullName=(EditText)findViewById(R.id.txtfname);
final EditText edUserName=(EditText)findViewById(R.id.txtusername);
final EditText edEmail=(EditText)findViewById(R.id.txtemail);
final RadioButton rbMale=(RadioButton)findViewById(R.id.rd_male);
final RadioButton rbFeMale=(RadioButton)findViewById(R.id.rd_female);
final EditText edDateOfBirth=(EditText)findViewById(R.id.txtdob);
final EditText edPassward=(EditText)findViewById(R.id.txtpassword);
rbFeMale.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if(arg1==true)
{
gender="Female";
}
}
});
rbMale.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if(arg1==true)
{
gender="Male";
}
}
});
final AlertDialog ad=new AlertDialog.Builder(this).create();
btnRegister.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
CallSoap cs=new CallSoap();
try
{
Boolean result=cs.Register(edFullName.getText().toString(), edUserName.getText().toString(), edEmail.getText().toString(), gender, edDateOfBirth.getText().toString(), edPassward.getText().toString());
if (result==true)
{
Toast.makeText(getApplicationContext(),"Registered Sucessfully!!!" , Toast.LENGTH_LONG).show();
}
}
catch(Exception ex)
{
ad.setMessage(ex.getMessage());
}
}
});
TextView tvBackLogin=(TextView)findViewById(R.id.link_to_login);
tvBackLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Register.this,MainActivity.class);
//intent.putExtra(EXTRA_MESSAGE, etLoginID.getText().toString());
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.register, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
}
}
This is my registration.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Full Name" />
<EditText
android:id="@+id/txtfname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/tvRegister"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Username" />
<EditText
android:id="@+id/txtusername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Email ID" />
<EditText
android:id="@+id/txtemail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Gender" />
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rd_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />
<RadioButton
android:id="@+id/rd_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<TextView
android:id="@+id/textView4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Date of Birth" />
<EditText
android:id="@+id/txtdob"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="date" />
<TextView
android:id="@+id/textView5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Password" />
<EditText
android:id="@+id/txtpassword"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/btnRegister"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Register" />
<TextView
android:id="@+id/link_to_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="Already have account! Login here" />
</LinearLayout>
</ScrollView>
Stacktrace:
08-23 13:12:11.154: E/AndroidRuntime(9864): FATAL EXCEPTION: main
08-23 13:12:11.154: E/AndroidRuntime(9864): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androsqlapp/com.example.androsqlapp.Register}: java.lang.ClassCastException: android.widget.TextView
08-23 13:12:11.154: E/AndroidRuntime(9864): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-23 13:12:11.154: E/AndroidRuntime(9864): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-23 13:12:11.154: E/AndroidRuntime(9864): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-23 13:12:11.154: E/AndroidRuntime(9864): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-23 13:12:11.154: E/AndroidRuntime(9864): at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 13:12:11.154: E/AndroidRuntime(9864): at android.os.Looper.loop(Looper.java:123)
08-23 13:12:11.154: E/AndroidRuntime(9864): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-23 13:12:11.154: E/AndroidRuntime(9864): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 13:12:11.154: E/AndroidRuntime(9864): at java.lang.reflect.Method.invoke(Method.java:507)
08-23 13:12:11.154: E/AndroidRuntime(9864): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-23 13:12:11.154: E/AndroidRuntime(9864): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-23 13:12:11.154: E/AndroidRuntime(9864): at dalvik.system.NativeStart.main(Native Method)
08-23 13:12:11.154: E/AndroidRuntime(9864): Caused by: java.lang.ClassCastException: android.widget.TextView
08-23 13:12:11.154: E/AndroidRuntime(9864): at com.example.androsqlapp.Register.onCreate(Register.java:28)
08-23 13:12:11.154: E/AndroidRuntime(9864): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-23 13:12:11.154: E/AndroidRuntime(9864): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-23 13:12:11.154: E/AndroidRuntime(9864): ... 11 more
Please help me.
Upvotes: 1
Views: 984
Reputation: 133560
You have this
<TextView // text view with id link_to_login
android:id="@+id/link_to_login"
While initializing you have this
Button btnRegister =(Button)findViewById(R.id.link_to_login);
Hence you get class cast exception
Either change your textview to button
<Button
android:id="@+id/link_to_login"
or
TextView btnRegister =(TextView)findViewById(R.id.link_to_login);
Upvotes: 1
Reputation: 2104
THis is because
android:id="@+id/link_to_login" is for TextView and in your code you have declared it for Button... So change it..
Hope you understand...And this will help you....
Upvotes: 2
Reputation: 8488
In xml you have defined it as TextView and in onCreate you are assigning it as button which is causing classCastexception. Change it in xml/code and it should work
Upvotes: 1