我有两个活动MainActivity和SecondActivity
活动主要活动.java
中的代码public class MainActivity extends FragmentActivity implements OnMarkerClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main_screen);
databaseobj = new AppDatabase(MainActivity.this, null);
listview = (ListView) findViewById(R.id.store_listview);
noSavedMsg = (TextView) findViewById(R.id.no_msg);
..
..
..//Other code logic
..
}
@Override
protected void onResume() {
if (databaseobj.GetAll() != -1) { //NULL POINTER EXCEPTION
listview.setVisibility(View.GONE); //NULL POINTER EXCEPTION
noSavedMsg.setVisibility(View.VISIBLE); //NULL POINTER EXCEPTION
}
super.onResume();
}
}
从其他活动返回后,我收到空指针异常;
MainActivity - >对SecondActivity的新意图
SecondActivity-> finish()然后是MainActivity-> onResume()NULL POINTER EXCEPTION
请帮忙!
答案 0 :(得分:0)
您的TextView
名称为noSavedMsg
,但您正在尝试设置名为NoSavedMsg
的视图的可见性......这两个名称不相同。
更改此行...
NoSavedMsg.setVisibility(View.VISIBLE);
为...
noSavedMsg.setVisibility(View.VISIBLE);
答案 1 :(得分:0)
您确定需要那里的资金N
吗?
NoSavedMsg.setVisibility(View.VISIBLE);
而不是:
noSavedMsg.setVisibility(View.VISIBLE);
答案 2 :(得分:0)
databaseobj = new AppDatabase(MainActivity.this, null);
listview = (ListView) findViewById(R.id.store_listview);
noSavedMsg = (TextView) findViewById(R.id.no_msg);
将此代码添加到onResume方法中,看看它是否有效。