I cannot seem to find out what this error means. Can you all help me out?
Here is my source code in the MainView.java. After logging into the app, this is the first screen you see, it should show the header, then a google maps api, then the menu at the bottom.
public class MainView extends FragmentActivity implements OnClickListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.main_view, container, false);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Fragment fragment;
Button openDrawer = (Button) findViewById(R.id.openDrawer);
openDrawer.setOnClickListener(this);
Button openUploader = (Button) findViewById(R.id.menuButtonAdd);
openUploader.setOnClickListener(this);
Button openEditor = (Button) findViewById(R.id.menuButtonEdit);
openEditor.setOnClickListener(this);
Button openMap = (Button) findViewById(R.id.menuButtonMap);
openMap.setOnClickListener(this);
Button openPeople = (Button) findViewById(R.id.menuButtonPeople);
openPeople.setOnClickListener(this);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Map myFragment = new Map();
ft.add(R.id.mainFragment, myFragment);
ft.commit();
}
public void onClick(View arg0) {
Fragment newFragment = new Map();
switch (arg0.getId()) {
case(R.id.openDrawer):
SlidingDrawer menuDrawer = (SlidingDrawer) findViewById(R.id.menuDrawer);
//SlidingDrawer textDrawer = (SlidingDrawer) findViewById(R.id.textDrawer);
if (menuDrawer.isOpened() == true) {
menuDrawer.animateClose();
//textDrawer.animateClose();
} else if (menuDrawer.isOpened() == false) {
menuDrawer.animateOpen();
//textDrawer.animateOpen();
}
break;
case(R.id.menuButtonAdd):
newFragment = new UploadFragment();
break;
case(R.id.menuButtonEdit):
newFragment = new EditGallery();
break;
case(R.id.menuButtonMap):
newFragment = new Map();
break;
case(R.id.menuButtonPeople):
// TODO present an error
break;
default:
newFragment = new Map();
break;
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.mainFragment, newFragment);
transaction.commit();
}
}
Code at line 37:
openDrawer.setOnClickListener(this);
It means you’ve got a
NullPointerExceptionon this line:com.fotolife.app.MainView.onStart(MainView.java:37)This is because
openDrawerisnull, because it cannot be found in the view.You need to add this:
and remove the
onCreateViewmethod.