Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 设置EditText的文本时使用空指针_Android - Fatal编程技术网

Android 设置EditText的文本时使用空指针

Android 设置EditText的文本时使用空指针,android,Android,Thsi是我的代码: EditText editCategoryName, editBrandName; private ArrayAdapter<String> myAdapter1, myAdapter2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // mylist = new

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>

我不知道为什么。请在
super.onCreate(savedInstanceState)之后帮助..


这一行您忘记了
setContentView(R.layout.)

您没有定义
setContentView(R.layout.xyz)

在oncreate方法中。

您忘记定义setContentView(R.layout.you\u xml\u name);在onCreate方法中

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

@Override
public void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.you_xml_name);
    super.onCreate(savedInstanceState);
    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-editCategoryName,editBrandName;
专用阵列适配器myAdapter1、myAdapter2;
@凌驾
创建时的公共void(Bundle savedInstanceState){
setContentView(R.layout.you\u xml\u name);
super.onCreate(savedInstanceState);
myList1=新的ArrayList();
myList2=新的ArrayList();
editCategoryName=(EditText)findViewById(R.id.editCategoryName);
editBrandName=(EditText)findViewById(R.id.editBrandName);
editCategoryName.setText(“谷歌是你的朋友。”,TextView.BufferType.EDITABLE);

在使用xml文件中编辑文本和微调器的id之前,请提供setContentView(“布局文件的id”);否则,当您尝试使用未使用的xml布局的一部分id时,它将显示空指针

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

@Override
public void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.you_xml_name);
    super.onCreate(savedInstanceState);
    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);