Here is my onCreate() method. I am trying to pass a variable from one intent to this intent. That works fine. When I press back button and go back to previous intent to change the value, then the application crashes. And also when I change the orientation, the application crashes. I am getting “Nullpointer exception” at the pp.getData() method. It passes null argument into the function. How can I overcome this? do I need to add any other details?
public void onCreate(Bundle savedInstanceState) {
// get intent data
Intent i = getIntent();
setQuery(i.getExtras().getString("query"));
Log.v("query:", getQuery());
userquery = getQuery();
super.onCreate(savedInstanceState);
setContentView(R.layout.product_view_layout);
try {
pp = new Parser(userquery);
productData = pp.getData(asynctask, userquery);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mProductViewPagerAdapter = new ProductViewPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mProductViewPagerAdapter);
}
If the “query” extra doesn’t exist in the
Intentthen it will returnnull. You should perform a null check to make sure you don’t getnullPointerExceptions.