本人小白啊,C++转来的,什么都不懂,求通俗易懂答案
搭好了android开发平台,想运行下hello world ,从网上抄了点代码,结果有错误package android.hello;import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;public class HelloWorldActivity extends Activity {
private TextView txtView;
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.txtView = (TextView) findViewById(R.id.txtView);
        if(this.txtView!=null){
            this.txtView.setText("Hello World");
        }    
    }
}this.txtView = (TextView) findViewById(R.id.txtView);这句的id那报错

解决方案 »

  1.   

    确认main.xml里是否有txtView这个id的布局
      

  2.   

    有啊<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" /></LinearLayout>
      

  3.   


    把TextView加一个id: <TextView
            android:id="@+id/txtView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />