第一次发布,自我思考的程序员,并在android中有一个类强制转换异常.我明白错误是什么,我知道是什么导致了它,但我不知道它为什么会发生.
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());
}
Run Code Online (Sandbox Code Playgroud)
public class ChangeTwitter extends Activity
{
<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>
Run Code Online (Sandbox Code Playgroud)
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());
}
Run Code Online (Sandbox Code Playgroud)
来自try catch语句(password)中第二个EditText的错误是java.lang.classcastexception android.widget.textview之一.我有几十个这样的编辑视图,这个导致程序崩溃.我实际上不明白为什么.
谢谢你的时间和抱歉xml文件格式不佳,我无法弄清楚如何修改它.
你有两个具有相同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>
Run Code Online (Sandbox Code Playgroud)
给他们不同的ID - 我假设它正在挑选第一个(TextView显然不能被强制转换为)EditText.
| 归档时间: |
|
| 查看次数: |
6282 次 |
| 最近记录: |