我在speed = (TextView) findViewById(R.id.speed);
中發現錯誤「速度無法解析或者它不是字段」。Android中的findViewById錯誤
我的佈局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SpeedometerActivity" >
<Button
android:id="@+id/download"
android:layout_width="150dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="13dp"
android:layout_marginLeft="300dp"
android:text="Begin Test" />
<TextView
android:id="@+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/meter"
android:layout_marginLeft="191dp"
android:layout_marginTop="55dp"
android:layout_toRightOf="@+id/meter"
android:text="TextView"
android:textSize="20dp"
android:textColor="#000000"/>
</RelativeLayout>
我MainActivity
:
public class MainActivity extends Activity {
TextView speed;
Button download;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.speedometer);
download = (Button)findViewById(R.id.download);
}
@Override
protected void onResume() {
super.onResume();
h = new Handler();
new speedTask().execute();
speed = (TextView) findViewById(R.id.speed);
}
}
請人幫我解決這個問題。
將類型添加到您的速度按鈕'(Button)speed =(Button)findViewById(R.id.speed);'順便說一句,您不能將Textview投射到按鈕。 – Arshak92
速度是textview如何更改爲按鈕 – appukrb
請粘貼您的完整MainActivity.Java文件。 –