Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:42:29+00:00 2026-06-10T16:42:29+00:00

Here is the Java with the line that the log cat says I have

  • 0

Here is the Java with the line that the log cat says I have an error on… I will add a comment to that line… it says I have casted a textview to a button but I haven’t at all.

package k.t.m;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

    TextView errors;
    TextView tkm;
    TextView result;
    TextView main;
    Button mainButton1;
    Button mainButton2;
    Button back;
    Button go;
    EditText textbox;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        main = (TextView) findViewById(R.id.main);
        back = (Button) findViewById(R.id.secondaryButtonBack);
        mainButton1  = (Button) findViewById(R.id.mainButton1);
        mainButton2  = (Button) findViewById(R.id.mainButton2);
        go = (Button) findViewById(R.id.goButton); // error here in the logcat... below

        tkm = (TextView) findViewById(R.id.mkm);
        result = (TextView) findViewById(R.id.result);
        errors = (TextView) findViewById(R.id.errors);
        textbox = (EditText) findViewById(R.id.TextBox);

        textbox.setVisibility(View.INVISIBLE);
        back.setVisibility(View.INVISIBLE);
        go.setVisibility(View.INVISIBLE);

       mainButton1.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {

            milesToKilometers();
        }

       });


        mainButton2.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                kilometersToMiles();
            }

        });

        back.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                back();
                result.setText("");
                tkm.setText("");

            }

        });


    }


    protected void back() {

        main.setVisibility(View.VISIBLE);
        mainButton1.setVisibility(View.VISIBLE);
        mainButton2.setVisibility(View.VISIBLE);
        back.setVisibility(View.INVISIBLE);
        go.setVisibility(View.INVISIBLE);
        textbox.setVisibility(View.INVISIBLE);

    }


    protected void kilometersToMiles() {

        tkm.setText("Kilometers:");
        main.setVisibility(View.INVISIBLE);
        mainButton1.setVisibility(View.INVISIBLE);
        mainButton2.setVisibility(View.INVISIBLE);
        back.setVisibility(View.VISIBLE);
        go.setVisibility(View.VISIBLE);
        textbox.setVisibility(View.VISIBLE);
        go.setOnClickListener(new OnClickListener() {


            public void onClick(View v) {
                if(textbox.getText().toString().equals("")){

                    errors.setText("Error: Kilometers Missing");

                }
            }

        });
    }

    protected void milesToKilometers() {


        main.setVisibility(View.INVISIBLE);
        mainButton1.setVisibility(View.INVISIBLE);
        mainButton2.setVisibility(View.INVISIBLE);
        back.setVisibility(View.VISIBLE);
        go.setVisibility(View.VISIBLE);
        textbox.setVisibility(View.VISIBLE);

         go.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {

                }

            });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }


}

now here is the logcat error I don’t know whats wrong…it makes no senese to me.

08-18 15:54:14.687: E/AndroidRuntime(15778): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Button
08-18 15:54:14.687: E/AndroidRuntime(15778):    at k.t.m.MainActivity.onCreate(MainActivity.java:32)

thanks to all in advance… and here is the xml file I don’t think that there is anything wrong but here you go…

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

    <TextView
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="                    What do you wish to convert?" />

    <Button
        android:id="@+id/mainButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="122dp"
        android:text="Kilometers to Miles" />

    <Button
        android:id="@+id/mainButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/mainButton2"
        android:layout_below="@+id/mainButton2"
        android:layout_marginTop="126dp"
        android:text="Miles to Kilometers" />

    <Button
        android:id="@+id/secondaryButtonBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mainButton1"
        android:layout_marginTop="57dp"
        android:layout_toRightOf="@+id/mainButton1"
        android:text="Back" />

    <Button
        android:id="@+id/goButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mainButton1"
        android:layout_centerHorizontal="true"
        android:text="Go" />

    <TextView
        android:id="@+id/result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="" />

    <TextView
        android:id="@+id/errors"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/main"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="46dp"
        android:text="" />

    <EditText
        android:id="@+id/TextBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/result"
        android:layout_centerHorizontal="true"
        android:ems="10"
        android:inputType="number" />

    <TextView
        android:id="@+id/mkm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/TextBox"
        android:layout_toLeftOf="@+id/result" />

</RelativeLayout>

here is the r.java I don’t know what to look for so here

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package k.t.m;

public final class R {
    public static final class attr {
    }
    public static final class dimen {
        public static final int padding_large=0x7f040002;
        public static final int padding_medium=0x7f040001;
        public static final int padding_small=0x7f040000;
    }
    public static final class drawable {
        public static final int ic_action_search=0x7f020000;
        public static final int ic_launcher=0x7f020001;
    }
    public static final class id {
        public static final int TextBox=0x7f080008;
        public static final int errors=0x7f080007;
        public static final int goButton=0x7f080005;
        public static final int main=0x7f080000;
        public static final int mainButton1=0x7f080002;
        public static final int mainButton2=0x7f080001;
        public static final int menu_settings=0x7f080009;
        public static final int mkm=0x7f080004;
        public static final int result=0x7f080006;
        public static final int secondaryButtonBack=0x7f080003;
    }
    public static final class layout {
        public static final int activity_main=0x7f030000;
    }
    public static final class menu {
        public static final int activity_main=0x7f070000;
    }
    public static final class string {
        public static final int app_name=0x7f050000;
        public static final int hello_world=0x7f050001;
        public static final int menu_settings=0x7f050002;
        public static final int title_activity_main=0x7f050003;
    }
    public static final class style {
        public static final int AppTheme=0x7f060000;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:42:31+00:00Added an answer on June 10, 2026 at 4:42 pm

    This means you have to revise the findViewById. I think there is a textview declared in the java code you are referencing it to a button id. Please check that

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this chess engine Rybka.exe, that i have to execute in java Here
We have system here that uses Java JNI to call a function in a
The Java tutorials here mention that &= is an assignment operator but doesn't seem
I have a fairly straightforward Java class here which creates 2 thread pools.... Connects
I have some question over here regarding the java garbage collector. First let me
I have try this code on DatabaseHelper.java Line Number 34 public DatabaseHelper(Context context) throws
I have the following Hibernate code that is returning an error. The results of
So here is the problem I'm having currently...I have a ASPX script that runs
I have developed a servlet that outputs the server.log file of my JBoss 7.1
I log quite a bit of stuff, and have noticed that Eclipse Console makes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.