0

first time posting, self thought programmer and having a class cast exception in android. I understand what the error is and I know what's causing it, yet I've no idea why it is happening.

public class ChangeTwitter extends Activity {

EditText newtwitter;
EditText password;
Button submitbutton;

InputStream is = null;
String result = "";
private static String passwordchecker;

FUNCTIONS callfunction = new FUNCTIONS();
ERRORS callerrors = new ERRORS();

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.twitterchanger);



    try
    {
        newtwitter = (EditText) findViewById(R.id.twitterchangertwitter);
            password = (EditText) findViewById(R.id.twitterchangerpassword);
            submitbutton = (Button) findViewById(R.id.twitterchangersubmitbutton);
    }

    catch (Exception e)
    {
        Log.e("log_tag", "Error is:"+e.toString());
    }

<TextView 
        android:text="" 
        android:id="@+id/twitterchangerspacer1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
    <TextView 
        android:text="Please enter the twitter name you wish to update to:"
        android:id="@+id/twitterchangertext1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
    <TextView 
        android:text="" 
        android:id="@+id/twitterchangerspacer2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
    <EditText 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:id="@+id/twitterchangertwitter" 
        android:text="">
    </EditText>
    <TextView 
        android:text="" 
        android:id="@+id/twitterchangerspacer3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
    <TextView 
        android:text="Please confirm with your password:" 
        android:id="@+id/twitterchangerpassword" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
    <TextView 
        android:text="" 
        android:id="@+id/twitterchangerspacer4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
    <EditText 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:id="@+id/twitterchangerpassword" 
        android:text="">
    </EditText>
    <TextView android:text="" 
        android:id="@+id/twitterchangerspacer5" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="TextView" 
        android:id="@+id/twitterchangerspacer6" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
    <Button android:text="Submit" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:id="@+id/twitterchangersubmitbutton">
    </Button>

The error that come from the second EditText in the try catch statement (password) is one of java.lang.classcastexception android.widget.textview. I have dozens of editviews like this and this one causes the program to crash. I actually don't see why.

Thanks for you time and sorry about the poor formatting on the xml file, I couldn't figure out how to spruce it up.

1 Answer 1

5

You've got two elements with the same ID:

<TextView android:text="Please confirm with your password:" 
    android:id="@+id/twitterchangerpassword" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
</TextView>

<EditText android:layout_height="wrap_content"
    android:layout_width="fill_parent" 
    android:id="@+id/twitterchangerpassword" 
    android:text="">
</EditText>

Give them different IDs - I assume it's picking the first one (the TextView) which obviously can't be cast to an EditText.

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

2 Comments

Skeeted for the 3rd time today... (+1 oc)
oh well spotted!! thanks so much! If I had a hat I would tip it to you

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.