List <textview>类型中的方法add(TextView)不适用于参数(String)</textview>

时间:2014-04-20 17:10:20

标签: android dialog onitemlongclicklistener

我在更新代码后得到此错误,以获取在Dialog文件中更新列表行的功能:

package com.example.classorganizer;

import java.util.List;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

class EditListItemDialog extends Dialog implements View.OnClickListener {

private View editText;

public EditListItemDialog(Context context) {
    super(context);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edit_text_dialog);//here is your xml with EditText and 'Ok' and 'Cancel' buttons
    View btnOk = findViewById(R.id.button_ok);
    editText = findViewById(R.id.edit_text);
    btnOk.setOnClickListener(this);
}

private List<TextView> fragment_monday;

public EditListItemDialog(Context context, List<TextView> fragment_monday) {
    super(context);
    this.fragment_monday = fragment_monday;
}

@Override
public void onClick(View v) {
    fragment_monday.add(((TextView) editText).getText().toString());//here is your updated(or not updated) text
    dismiss();
}
}

在fragment_monday之后的最后一个方法onClick中发生错误。 这是什么意思?

编辑。应用程序崩溃后的Logcat:

04-20 19:18:06.049: E/AndroidRuntime(1468): FATAL EXCEPTION: main
04-20 19:18:06.049: E/AndroidRuntime(1468): java.lang.NullPointerException
04-20 19:18:06.049: E/AndroidRuntime(1468):     at com.example.classorganizer.EditListItemDialog.onClick(EditListItemDialog.java:37)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at android.view.View.performClick(View.java:2485)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at android.view.View$PerformClick.run(View.java:9080)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at android.os.Handler.handleCallback(Handler.java:587)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at android.os.Looper.loop(Looper.java:130)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at android.app.ActivityThread.main(ActivityThread.java:3687)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at java.lang.reflect.Method.invokeNative(Native Method)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at java.lang.reflect.Method.invoke(Method.java:507)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-20 19:18:06.049: E/AndroidRuntime(1468):     at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案