当我在应用程序中使用我的按钮时,出现错误。错误NullpointerException按钮
09-23 18:29:01.242 9332-9332 /? E/AndroidRuntime:致命异常:主要 显示java.lang.NullPointerException 在foit.startingpoint.nl.androiddrawer.LocatiesFragment.onCreateView(LocatiesFragment.java:28)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Button button = (Button) getView().findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(LocatiesFragment.this.getActivity(), SecondActivity.class);
startActivity(myIntent); }
});
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_locaties, container, false);
}
在'Activity'或'fragment_locaties.xml'中xml中的'button'是否膨胀? – codeMagic 2014-09-23 16:50:05
fragment_locaties.xml – ImAtWar 2014-09-23 16:51:49