0
我的問題是,TextView給java.lang.NullPointerException如果我做方向更改頻繁。我在下面粘貼了我的代碼。我錯過了什麼嗎?頻繁的方向更改爲Textview提供空指針例外
@Override
public void onSaveInstanceState(Bundle outState) {
if (title.getText().toString() != null) { //Getting Null Exception here
Log.i("onSaveInstanceState", " "+title.getText().toString());
outState.putString("title", title.getText().toString());
}
}
-
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
view=inflater.inflate(R.layout.add, null);
title =(TextView) view.findViewById(R.id.title);
if (savedInstanceState.getString("title") != null) {
Log.i("on create", " "+savedInstanceState.getString("title"));
title.setText(savedInstanceState.getString("title"));
}
}
感謝烏拉圭回合的答覆, 「title.getText()」 本身給空指針異常,任何想法? – kavie
你有沒有在你的onCreate()方法之外聲明'標題'? – axierjhtjz
是啊............ – kavie