Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/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
Java 使用setText方法时获取错误_Java_Android_Macos_Macros_Android Logcat - Fatal编程技术网

Java 使用setText方法时获取错误

Java 使用setText方法时获取错误,java,android,macos,macros,android-logcat,Java,Android,Macos,Macros,Android Logcat,这是我的密码: public class NoteView extends FragmentActivity implements CustomDialogFragment.CustomDialogListener { private Uri mUri; private String[] projection = { NotepadContract.Notes.COLUMN_NAME_NOTE, NotepadContract.Notes.COLUMN_NAME_TITLE };

这是我的密码:

public class NoteView extends FragmentActivity implements CustomDialogFragment.CustomDialogListener {
private Uri mUri;
private String[] projection = { NotepadContract.Notes.COLUMN_NAME_NOTE,
        NotepadContract.Notes.COLUMN_NAME_TITLE };
private TextView mTextView;

private String content;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.note_view);
    mTextView = (TextView) findViewById(R.id.text_body);
    // Show the Up button in the action bar.
    getActionBar().setDisplayHomeAsUpEnabled(true);
    Intent intent = getIntent();
    mUri = intent.getData();
    // String action=intent.getAction();
    // if ("com.yuyizhao.NoteView".equals(action)) System.out.println(mUri);
    Cursor mCursor = getContentResolver().query(mUri, projection, null,
            null, null);
    int index_note = mCursor
            .getColumnIndexOrThrow(NotepadContract.Notes.COLUMN_NAME_NOTE);
    System.out.println(index_note);

    int index_title = mCursor
            .getColumnIndexOrThrow(NotepadContract.Notes.COLUMN_NAME_TITLE);
    System.out.println(index_title);
    if (mCursor != null) {
        while (mCursor.moveToNext()) {
            content = mCursor.getString(index_note);
            setTitle(mCursor.getString(index_title));
            System.out.println(mCursor.getString(index_title));
            System.out.println(mCursor.getString(index_note));

        }
    }
    mTextView.setText(content);

}
布局xml文件:(注意\u查看xml)


有人知道为什么我在使用
setText()
方法时出现这个错误吗?

没有足够的stacktrace或错误报告,所以只需要假设(完成stacktrace后)

许多程序失败的可能性,或者
mTextView
NULL

或者可能是您的
字符串内容
NULL

所以在执行
mTextView.setText(content)之前只需检查

if(content != null)
{
 mTextView.setText(content);
}
更新:您的
TextView mTextView
NULL
,因为在xml中id名称为view\u body而不是text\u body

mTextView = (TextView) findViewById(R.id.text_body);


可能是
TextView
null
。你的文本视图是否在
R.layout中。注意\u view

请显示完整的堆栈跟踪。你可以发布你的xml并完成你收到的logcat错误…兄弟请检查更新。谢谢兄弟。我检查了内容是否正确,因为我得到了打印件。还不明白为什么会发生这种事,他妈的对!非常感谢兄弟!这是我愚蠢的错误!再次感谢!我问你文本视图是否在那个布局中。
if(content != null)
{
 mTextView.setText(content);
}
mTextView = (TextView) findViewById(R.id.text_body);
mTextView = (TextView) findViewById(R.id.view_body);