String 如何将TextView转换为int?

String 如何将TextView转换为int?,string,textview,int,ivalueconverter,parseint,String,Textview,Int,Ivalueconverter,Parseint,我知道有很多这样的帖子,但我读过了,我的应用程序还不能运行。 我正在尝试将TextView参数转换为int。 我用这个: int MyScore; TextView score = (TextView) findViewById(R.id.highscore); MyScore = Integer.parseInt(score.toString()); 当我启动程序并将其加载到某个位置时,由于最后一行的原因,我的程序应该可以运行:MyScore=Integer.parseInt(score.t

我知道有很多这样的帖子,但我读过了,我的应用程序还不能运行。 我正在尝试将TextView参数转换为int。 我用这个:

int MyScore;
TextView score = (TextView) findViewById(R.id.highscore);
MyScore = Integer.parseInt(score.toString());
当我启动程序并将其加载到某个位置时,由于最后一行的原因,我的程序应该可以运行:
MyScore=Integer.parseInt(score.toString())


我如何解决这个问题?

因为你没有指定使用的语言,我无法完全回答,但我可以猜出问题所在。大多数输入字段都有值或文本属性,请尝试对其进行分析。

最后一行应为

    MyScore = Integer.parseInt(score.getText().toString());
score
对象调用的
toString()
方法描述
score
对象,它不返回输入
score
对象的字符串。请参阅Oracle Java教程。阅读其中大部分内容是个好主意。

使用TextView.getText().toString()(如@Floris建议的)将返回TextView的文本。如果您需要,EditText也适用。