Reputation: 108
I have three textviews and applied clickevent on them, but when i click on any of them the they cause Forceclose error in application. i have also tried changing ids textviews and then clean project and ran the project still that error is not removed.
My XML code is
for one textview
<LinearLayout
android:id="@+id/LL_fb"
android:layout_width="180px"
android:layout_height="27px"
android:layout_above="@+id/txt_msg_regs"
android:layout_alignLeft="@+id/LL_signup"
android:layout_marginBottom="25dp"
android:background="@drawable/facebook" >
<TextView
android:id="@+id/btn_txt_fb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Connect with facebook"
android:layout_gravity="center_vertical"
android:layout_marginLeft="23dp"
android:layout_marginTop="1dp"
android:clickable="true"
android:textColor="#FFFFFF" />
</LinearLayout>
for second textview
<LinearLayout
android:id="@+id/LL_signup"
android:layout_width="180px"
android:layout_height="29px"
android:layout_above="@+id/textView1"
android:layout_alignLeft="@+id/LL_login"
android:background="@drawable/lmyic_signup">
<TextView
android:id="@+id/btn_txt_sinup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="signup with email"
android:layout_gravity="center_vertical"
android:layout_marginLeft="25dp"
android:layout_marginTop="1dp"
android:clickable="true"
android:textColor="#FFFFFF" />
</LinearLayout>
for third one
<LinearLayout
android:id="@+id/LL_login"
android:layout_width="180px"
android:layout_height="29px"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="69dp"
android:background="@drawable/lmyic_login">
<TextView
android:id="@+id/btn_txt_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log in"
android:layout_gravity="center_vertical"
android:layout_marginLeft="70dp"
android:layout_marginTop="1dp"
android:textColor="#FFFFFF"
android:clickable="true"/>
</LinearLayout>
this is my android code. This class name in intent are also correct and i verified them.
TextView img_login;
img_login = (TextView)findViewById(R.id.btn_txt_login);
img_login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == img_login.getId())
{
Intent i_lin = new Intent(LockmeifyoucanActivity.this,lmiyc_login.class);
startActivity(i_lin);
}
}
});
Please Tell me what is wrong with this. If logcat is needed then ask me for it....
Upvotes: 0
Views: 1485
Reputation: 1
if you have duplicate resource Id, that will throw ClasscastException. So make sure you don't have duplicate element id throughout the whole project.
Upvotes: 0
Reputation: 15701
these are lines from 42-48
setContentView(R.layout.lmyic_login_page);
txtBack = (TextView)findViewById(R.id.ImgViewTxtBack); txtBack.setTypeface(null,Typeface.BOLD);
iv_login = (ImageView)findViewById(R.id.Txtlogin);
iv_login.setOnClickListener(this);
iv_sign_up = (ImageView)findViewById(R.id.TxtSignup);
I think problem is with iv_login = (ImageView)findViewById(R.id.Txtlogin); – Dheeresh Singh 1 min ago edit because this is 46 line and it should be textview and you are castin it in Imageview – Dheeresh Singh just now edit
Upvotes: 0
Reputation: 132972
you have some problem with textview in lmiyc_login activity.in lmiyc_login corrent line number 46 which maybe:
TextView txtview;
txtview = (TextView)yourlayout.findViewById(R.id.txtviewid);
Upvotes: 1
Reputation: 4802
To resolve this error quickly, set one break point at line:
View view = findViewById(R.id.btn_txt_login);
Then, see on locals tab which component is, looking at gen/R.java.
Upvotes: 0
Reputation: 603
change ur code with this
TextView img_login;
img_login = (TextView)findViewById(R.id.txt_login);
img_login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId().equals(img_login.getId()))
{
Intent i_lin = new Intent(LockmeifyoucanActivity.this,lmiyc_login.class);
startActivity(i_lin);
}
}
});
Upvotes: 0
Reputation: 15701
Please post the complete XMl so that we can view the btn_txt_login in that.
It looks it is button because "findViewById(R.id.btn_txt_login);" would return null if this "btn_txt_login" id is not in xml.
Upvotes: 1
Reputation: 1628
Wrong resource ID...
img_login = (TextView)findViewById(R.id.btn_txt_login);
according to your XML should be
img_login = (TextView)findViewById(R.id.txt_login);
etc..
Upvotes: 0
Reputation: 22552
findViewById(R.id.btn_txt_login);
Is this really a TextView or do you have a Button in your layout as well? I think you're trying to cast a Button to a TextView
Upvotes: 0