Note that there are some explanatory texts on larger screens.

plurals
  1. POjava null pointer exception setting my action bar and fragment in my page viewer via button click
    text
    copied!<p>I have a page viewer as my main display page and i have used codes from the java class itself to create my tabs and action bar like this:</p> <pre><code>protected ViewPager viewPager; private pageAdapter mAdapter; private ActionBar actionBar; // Tab titles private String[] tabs = { "Home", "BroadCast", "Friends" }; viewPager = (ViewPager) findViewById(R.id.pager); mAdapter = new pageAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); actionBar = getActionBar(); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); for (String tab_name : tabs) { actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this)); } </code></pre> <p>i have three fragments for each tab that is loaded to the page viewer but on a particular fragment i want to set orload a another fragment into the page viewer when a button is clicked like so:</p> <pre><code>main mainly = new main(); public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.blastbut: mactv = (MultiAutoCompleteTextView) this.getActivity().findViewById(R.id.blastarea); new postotimeline().execute(); ViewPager viewPager = (ViewPager) this.getView().findViewById(R.id.pager); pageAdapter mAdapter = new pageAdapter(mainly.getSupportFragmentManager()); viewPager.setAdapter(mAdapter); viewPager.setCurrentItem(0); Log.i("Blast", "Blasting"); //send getText to database and update list view break; case R.id.sf: break; case R.id.blastarea: break; } } </code></pre> <p>but it keeps giving me a null pointer exception on the <code>viewPager.setAdapter(mAdapter);</code> i have tried various ways but it keeps giving me the java null pointer exception. Please I am not so much of a professional in android. so kindly excuse me if i missed the obvious. </p> <p>Log cat:</p> <pre><code>12-20 05:15:35.785: E/AndroidRuntime(1119): FATAL EXCEPTION: main 12-20 05:15:35.785: E/AndroidRuntime(1119): Process: example.gbaalert, PID: 1119 12-20 05:15:35.785: E/AndroidRuntime(1119): java.lang.NullPointerException 12-20 05:15:35.785: E/AndroidRuntime(1119): at example.gbaalert.broadcastfragment.onClick(broadcastfragment.java:75) 12-20 05:15:35.785: E/AndroidRuntime(1119): at android.view.View.performClick(View.java:4424) 12-20 05:15:35.785: E/AndroidRuntime(1119): at android.view.View$PerformClick.run(View.java:18383) 12-20 05:15:35.785: E/AndroidRuntime(1119): at android.os.Handler.handleCallback(Handler.java:733) 12-20 05:15:35.785: E/AndroidRuntime(1119): at android.os.Handler.dispatchMessage(Handler.java:95) 12-20 05:15:35.785: E/AndroidRuntime(1119): at android.os.Looper.loop(Looper.java:137) 12-20 05:15:35.785: E/AndroidRuntime(1119): at android.app.ActivityThread.main(ActivityThread.java:4998) 12-20 05:15:35.785: E/AndroidRuntime(1119): at java.lang.reflect.Method.invokeNative(Native Method) 12-20 05:15:35.785: E/AndroidRuntime(1119): at java.lang.reflect.Method.invoke(Method.java:515) 12-20 05:15:35.785: E/AndroidRuntime(1119): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 12-20 05:15:35.785: E/AndroidRuntime(1119): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 12-20 05:15:35.785: E/AndroidRuntime(1119): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>NOTE: main is a Fragment Activity that implements tab listener that is bind to a page viewer(XML) and the class in which the button is clicked extends a Fragment</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload