我叫马雷克。我来自波兰。
我的项目有问题。
java.lang.ClassCastException: android.widget.TextView cannot be cast andoid.widget.EditView
它不适用于虚拟设备和我的设备
这对我的学习发展来说是一个简单的项目。
对不起我的英语。
java:
cylindr = (TextView)findViewById(R.id.cylindr);
na = (TextView)findViewById(R.id.na);
litry = (TextView)findViewById(R.id.litry);
spalanie = (TextView)findViewById(R.id.spalanie);
obrot = (TextView)findViewById(R.id.obrot);
ok = (Button)findViewById(R.id.ok);
cylindr = (EditText)findViewById(R.id.cylindr);
obroty = (EditText)findViewById(R.id.obroty);
paliwo = (EditText)findViewById(R.id.paliwo);
xml:
<TextView
android:id="@+id/spalanie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/paliwo"
android:layout_alignParentTop="true"
android:layout_marginTop="24dp"
android:text="@string/Spalanie" />
<EditText
android:id="@+id/paliwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/spalanie"
android:layout_marginLeft="18dp"
android:layout_marginTop="22dp"
android:ems="10"
android:inputType="number"
android:labelFor="@+id/paliwo"
android:singleLine="true" />
<TextView
android:id="@+id/litry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/paliwo"
android:layout_alignBottom="@+id/paliwo"
android:layout_toRightOf="@+id/paliwo"
android:text="@string/litrow" />
<TextView
android:id="@+id/obrot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/paliwo"
android:layout_below="@+id/paliwo"
android:layout_marginTop="28dp"
android:text="@string/obroty" />
<EditText
android:id="@+id/obroty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/obrot"
android:layout_marginTop="24dp"
android:layout_toLeftOf="@+id/litry"
android:ems="10"
android:inputType="number"
android:labelFor="@id/obroty" />
<TextView
android:id="@+id/na"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/obroty"
android:layout_alignBottom="@+id/obroty"
android:layout_toRightOf="@+id/obroty"
android:text="@string/na" />
<TextView
android:id="@+id/cylindr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/obrot"
android:layout_below="@+id/obroty"
android:layout_marginTop="36dp"
android:text="@string/cylindry" />
<EditText
android:id="@+id/cylindry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/cylindr"
android:layout_below="@+id/obroty"
android:layout_marginTop="65dp"
android:ems="10"
android:inputType="number"
android:labelFor="@id/cylindry" />
<Button
android:id="@+id/dalej"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cylindry"
android:layout_marginTop="31dp"
android:layout_toRightOf="@+id/spalanie"
android:text="@string/ok" />
</RelativeLayout>
请帮帮我!
cylindr = (EditText)findViewById(R.id.cylindr);
应为:
cylindr = (EditText)findViewById(R.id.cylindry);
您当前正在使用R.id.cylindr
两次,还有一个重复的变量。您应该使用:
cylindr = (TextView)findViewById(R.id.cylindr);
na = (TextView)findViewById(R.id.na);
litry = (TextView)findViewById(R.id.litry);
spalanie = (TextView)findViewById(R.id.spalanie);
obrot = (TextView)findViewById(R.id.obrot);
ok = (Button)findViewById(R.id.ok);
cylindry = (EditText)findViewById(R.id.cylindry); //this is the line that was wrong
obroty = (EditText)findViewById(R.id.obroty);
paliwo = (EditText)findViewById(R.id.paliwo);