我有这项活动,
package org.dewsworld.ui;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Main extends Activity {
TextView textView ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.textView1) ;
textView.setText("hello ") ;
}
}
main.xml是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/textView1">
<TextView android:layout_height="wrap_content" android:id="@+id/textView1"
android:layout_width="wrap_content" android:text="TextView" />
</LinearLayout>
logcat是
我找不到错误...... :(
答案 0 :(得分:4)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:layout_height="wrap_content" android:id="@+id/textView1"
android:layout_width="wrap_content" android:text="TextView" />
</LinearLayout>
立即尝试
答案 1 :(得分:3)
你有2个视图使用相同的ID Linearlayout和TextView。删除LinearLayout的id并再次尝试。它会起作用。