0

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....

14
  • 2
    where is btn_txt_login ? Please post the XMl having btn_txt_login. Commented May 11, 2012 at 12:21
  • @SamirMangroliya hello, i edited my question it is btn_txt_login in my xml code by mistake it was written like that.... Commented May 11, 2012 at 12:32
  • post your logcat i'm sure you have some issue in lmiyc_login.class activity Commented May 11, 2012 at 12:38
  • you have try if(v.getId()==(R.id.btn_txt_login)) instead of v.getId() == img_login.getId() Commented May 11, 2012 at 12:40
  • @SamirMangroliya logcat is pastebin.com/WyLtTxCP Commented May 11, 2012 at 12:44

8 Answers 8

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

btn_txt_login should be button on UI and txt_login is textview as we can see. I think due to same almost same name you would have done this.
iff query has been resolved please vote/accept any answer found close to your answer to finish this story and make stack Clear for all....
1

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);

3 Comments

this lines of code are of my another page when i click on login btn on home page then this screen(lmiyc_login) should be open and it also has one login btn same as it is in home screen.
if you give a pastbin link for lmyic_login_page xml then your problem will solve in sort time
@all The problem is solved. The problem was in another page. redeclared all imageview as textview in lmiyc_login page.
0
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

Comments

0

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..

Comments

0

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);
            }                   
        }
    });

1 Comment

hahahaha u wrote btn_txt_login n i wrote this R.id.txt_login and u wrote this v.getId() == img_login.getId() nd i wrote this v.getId().equals(img_login.getId()) nd u say its already therr great :)
0

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.

Comments

0

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

Comments

0

if you have duplicate resource Id, that will throw ClasscastException. So make sure you don't have duplicate element id throughout the whole project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.