LOGCAT Erorr私のEditTextでのsetTextカント
java.lang.NullPointerExceptionが:ヌル に ')java.lang.Stringでa.thebook.m_Model.new_book1.getnamebook(' 仮想メソッド を起動しようとしJavaクラスのオブジェクト参照
package a.thebook;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import a.thebook.m_Model.new_book1;
....
public class my_book extends AppCompatActivity {
private new_book1 model;
private EditText bookname1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_book_activity);
EditText bookname1 = (EditText) findViewById(R.id.editTextbookname2);
bookname1.setText(model.getbookname());
...
}
firebaseデータベースから値を取得します。 new_book1
package a.thebook.m_Model;
import java.util.Objects;
public class new_book1 {
public String author;
public String bookname;
public new_book1() {
}
public new_book1(String bookname ,String author) {
this.bookname = bookname;
this.author = author;
}
public String getauthor(int author) {
return this.author;
}
public String getbookname() {
return this.bookname;
}
}
あなたはログを投稿します。 – Piyush
ここで、 'model'の初期化は何ですか? –
モデルに空文字があり、booknameを設定せず、直接getbooknameを使用していませんでした – Redman