EditText上不能被解析为一个类型 [英] EditText cannot be resolved to a type
问题描述
我在Android项目的资源文件夹中定义XML文件的布局。该的EditText'元素如下:
I have defined a layout in an xml file in the 'res' folder of my android project. The 'EditText' element looks like:
<EditText android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numeric="integer|decimal"></EditText>
在我的Android项目我的类文件,我有以下几点:
In my class file in my android project, I have the following:
public void doCalculation(View view) {
String firstNo = ((EditText) findViewById(R.id.editText1)).getText().toString();
String secondNo = ((EditText) findViewById(R.id.editText2)).getText().toString();
String operator = ((Spinner) findViewById(R.id.spinner1)).getSelectedItem().toString();
callWebService(firstNo, secondNo, operator );
}
不幸的是,第2分配在我的方法上面显示错误在eclipse说明
Unfortunately, the first 2 assignments in my method above are showing an error in eclipse stating
EditText cannot be resolved to a type
我不知道如何解决这一问题。我使用的是安卓2.3.3 API 10。 任何帮助将是AP preciated。谢谢
I've no idea how to fix this. I'm using android 2.3.3 API 10. Any help would be appreciated. Thanks
推荐答案
您需要导入的EditText
类,所以它的知的,使用下面一行在你的的.java
文件的开头:
You need to import the EditText
class, so it's known, using the following line at the beginning of your .java
file :
import android.widget.EditText;
需要注意的是,在大多数情况下,Eclipse可以帮助你很多:它有一个整理进口的功能,这将添加所需的进口
行:
Note that, in most cases, Eclipse can help you a lot : it has an Organize Imports feature, that will add the required import
lines :
- 菜单>
来源
>组织导入
- 或者使用<大骨节病>控制骨节病> + <大骨节病>移骨节病> + <大骨节病> 0
- Menu >
Source
>Organize Imports
- Or use Ctrl + Shift + O
这篇关于EditText上不能被解析为一个类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!