2
我一直试图在日食工作台上构建我的应用程序,但是我偶然发现了一条错误消息:“无法从视图转换到复选框”。我曾尝试不同的东西来解决问题无济于事,想知道,如果有人可以请帮我不能从视图投到复选框
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.widget.Checkbox;
import android.widget.TextView;
@SuppressLint("ParserError")
public class MainActivity extends Activity {
TextView textView;
CheckBox pepBox, cheeseBox;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pepBox =
(CheckBox) findViewById(R.id.checkBox1);
cheeseBox =
(CheckBox) findViewById(R.id.checkBox2);
textView =
(TextView) findViewById(R.id.textView2);
}
这是我用过
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="57dp"
android:text="@string/pepperoni" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/checkBox1"
android:layout_marginTop="33dp"
android:text="@string/extra_cheese" />
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/checkBox1"
android:layout_below="@+id/textView1"
android:onClick="onButton1Click"
android:text="@string/show" />
编码这是我的xml文件 感谢
非常感谢你,这解决了我的问题。有趣的是,这样一个小小的错误会让你想知道这么久。不,这没什么,你听起来没有什么光顾,实际上非常有帮助。是的,你是正确的日食通常给你提示如何解决这个问题,我通过日食提示帮助修复了我的其他问题,但是这个特殊的错误并没有提供任何提示。再次感谢 – user1505722 2012-07-14 04:32:23
对于未来,这个错误将帮助我们找出问题所在。我经常不得不谷歌错误信息找到可能导致它的一个线索。不要忘记,你创造一个以前从未见过的错误的机会很渺茫。祝你好运。 – cstrutton 2012-07-14 04:46:19