简体   繁体   English

来自android的java.lang.classcastexception android.widget.textview错误,但我看不到

[英]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. 第一次发布,自以为是的程序员,并且在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. 来自try catch语句(密码)中第二个EditText的错误是java.lang.classcastexception android.widget.textview之一。 I have dozens of editviews like this and this one causes the program to crash. 我有数十个这样的editview,这会导致程序崩溃。 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. 感谢您的时间,并为xml文件格式不正确而感到抱歉,我不知道该如何调整它。

You've got two elements with the same ID: 您有两个具有相同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 . 给他们提供不同的ID-我假设它选择的是第一个(显然是TextView ),它显然不能转换为EditText

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.ClassCastException:android.widget.TextView - java.lang.ClassCastException: android.widget.TextView 我不断收到错误 java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView cannot be cast to android.widget.TextView - i keep getting the error java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView cannot be cast to android.widget.TextView java.lang.ClassCastException:android.widget.TextView无法转换为android.widget.EditText - java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText java.lang.ClassCastException:android.widget.ScrollView无法强制转换为android.widget.TextView - java.lang.ClassCastException: android.widget.ScrollView cannot be cast to android.widget.TextView java.lang.ClassCastException:android.widget.ImageButton无法转换为android.widget.TextView - java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.TextView java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView 不能转换为 android.widget.TextView - java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView cannot be cast to android.widget.TextView java.lang.ClassCastException:android.support.constraint.ConstraintLayout无法转换为android.widget.TextView - java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.TextView java.lang.ClassCastException:android.widget.TextView。我为什么要这个? - java.lang.ClassCastException: android.widget.TextView. Why am I getting this? 我如何覆盖android.widget.TextView的Accessibility className - How i can override Accessibility className for android.widget.TextView android中的java.lang.ClassCastException - java.lang.ClassCastException in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM