package com.example.lew02;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class Lew_xianshi extends Activity {
private TextView mTextView01;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTextView01 = (TextView) findViewById(R.id.myTextView01);
String str_2 = "欢迎来到我的安卓世界";
mTextView01.setText(str_2);
setContentView(R.layout.activity_main);
}
<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="com.example.lew02.Lew_xianshi" >
<TextView
android:id="@+id/myTextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
------解决思路----------------------
setContentView(R.layout.activity_main); 放到 mTextView01 = (TextView) findViewById(R.id.myTextView01); 上面
------解决思路----------------------
------解决思路----------------------
setContentView(R.layout.activity_main); 放到mTextView01 = (TextView) findViewById(R.id.myTextView01);以上,要不然会报nullpointexception
------解决思路----------------------
刚开始 代码少 先弄懂每一行的作用, 这叫打基础