andru183
andru183

Reputation: 5

java.lang.classcastexception android.widget.textview error from android yet I can't see how

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.

Upvotes: 0

Views: 6292

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500525

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.

Upvotes: 5

Related Questions