pre*_*pal 5 android android-intent android-bundle
我正在查看我的应用程序的Crashlytics日志,发现某些设备上存在NullPointerException,因为getIntent()。getExtras()返回null。
仅在少数设备上可以看到此行为,并且我无法重现此错误。我知道我可以检查活动是否Bundle为null并防止NullPointerException,但我对找出此行为的根本原因更感兴趣。
编辑:
资源 -
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor c = (Cursor) parent.getAdapter().getItem(position);
Intent intent = new Intent(getActivity(), SelectedTopicActivity.class);
intent.putExtra("topicId", c.getLong(c.getColumnIndex(AppContract.TopicsEntry._ID)));
startActivity(intent);
}
});
Run Code Online (Sandbox Code Playgroud)
目的地-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selected_topic);
Bundle bundle = getIntent().getExtras();
topicId = bundle.getLong("topicId");
...
}
Run Code Online (Sandbox Code Playgroud)
如果光标为空,则源本身中将出现错误。我不认为光标中的字段为null,否则该项目将不会首先出现在列表中。
| 归档时间: |
|
| 查看次数: |
413 次 |
| 最近记录: |