EditText的setText时为空指针

red*_*dan 0 android

Thsi是我的代码:

EditText editCategoryName, editBrandName;
    private ArrayAdapter<String> myAdapter1, myAdapter2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//      mylist = new ArrayList<HashMap<String, String>>();
//      mylist2 = new ArrayList<HashMap<String, String>>();
        myList1 = new ArrayList<String>();
        myList2 = new ArrayList<String>();
        editCategoryName = (EditText)findViewById(R.id.editCategoryName);
        editBrandName = (EditText)findViewById(R.id.editBrandName);
        editCategoryName.setText("Google is your friend.", TextView.BufferType.EDITABLE);

<EditText
        android:id="@+id/editCategoryName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="???????"
        android:singleLine="true" >
    </EditText>

    <TextView
        android:id="@+id/textSpinnerBrand"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="hint" />

    <Spinner
        android:id="@+id/spinnerBrand"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/editBrandName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="hint"
        android:singleLine="true" >
    </EditText>
Run Code Online (Sandbox Code Playgroud)

空指针错误显示在行中:

editCategoryName.setText("Google is your friend.", TextView.BufferType.EDITABLE);
Run Code Online (Sandbox Code Playgroud)

我不知道为什么.请帮忙..

Nix*_*tel 5

你还没有setContetnView(R.layout.xyz); 在oncreate方法中定义.