I have followed ViewPager FragmentPagerAdapter Nullpointer but no help. Any solution to it would be appreciated. Please note that i have imported classes from Support library only.
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
Here is the crash log I received in Splunk Mint
java.lang.NullPointerException at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:416) at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:411) at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:99) at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:837) at android.support.v4.view.ViewPager.populate(ViewPager.java:987) at android.support.v4.view.ViewPager.populate(ViewPager.java:919) at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441) at android.view.View.measure(View.java:15575) at android.widget.LinearLayout.measureVertical(LinearLayout.java:833) at android.widget.LinearLayout.onMeasure(LinearLayout.java:574) at android.view.View.measure(View.java:15575) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399) at android.view.View.measure(View.java:15575) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.view.View.measure(View.java:15575) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396) at android.widget.LinearLayout.measureVertical(LinearLayout.java:681) at android.widget.LinearLayout.onMeasure(LinearLayout.java:574) at android.view.View.measure(View.java:15575) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2423) at android.view.View.measure(View.java:15575) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2031) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1249) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1425) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1142) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4724) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) at android.view.Choreographer.doCallbacks(Choreographer.java:555) at android.view.Choreographer.doFrame(Choreographer.java:525) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4947) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) at dalvik.system.NativeStart.main(Native Method)
Here is the code for my FragmentPagerAdapter.
private class MyPageAdapter extends FragmentPagerAdapter {
/**
* Instantiates a new my page adapter.
*
* @param fm the fm
*/
public MyPageAdapter(FragmentManager fm) {
super(fm);
}
/* (non-Javadoc)
* @see android.support.v4.app.FragmentPagerAdapter#getItem(int)
*/
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
try {
TypedArray a = null, b = null;
int attributeResourceId = 0, attributeStepsId = 0;
switch (currentLocale.toString().trim()) {
// if (currentLocale.toString().trim().equals("ar")) {
case "ar":
if (position == 0) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard2 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step1 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard2 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step1 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step1_title, R.string.activity_wizard_help_step2_line2, attributeStepsId);
} else if (position == 1) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step2 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step2 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step2_title, R.string.activity_wizard_help_step1_line2, attributeStepsId);
}
else if (position == 2) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard3_ar });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step3 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard3_ar });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step3 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step3_title, R.string.activity_wizard_help_step3_line2, attributeStepsId);
}
else if (position == 3) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard4_ar });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step4 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard4_ar });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step4 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step4_title, R.string.activity_wizard_help_step4_line2, attributeStepsId);
}
else {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step1 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step1 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step1_title, R.string.activity_wizard_help_step1_line2, attributeStepsId);
}
// } else {
break;
case "en":
if (position == 0) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard2 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step1 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard2 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step1 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step1_title, R.string.activity_wizard_help_step2_line2, attributeStepsId);
} else if (position == 1) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step2 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step2 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step2_title, R.string.activity_wizard_help_step1_line2, attributeStepsId);
}
else if (position == 2) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard3 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step3 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard3 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step3 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step3_title, R.string.activity_wizard_help_step3_line2, attributeStepsId);
}
else if (position == 3) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard4 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step4 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light,
new int[] { R.attr.wizard4 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step4 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step4_title, R.string.activity_wizard_help_step4_line2, attributeStepsId);
}
else {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step1 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step1 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step1_title, R.string.activity_wizard_help_step1_line2, attributeStepsId);
}
break;
case "hi":
if (position == 0) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard2 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step1 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard2 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step1 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step1_title, R.string.activity_wizard_help_step2_line2, attributeStepsId);
} else if (position == 1) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step2 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step2 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step2_title, R.string.activity_wizard_help_step1_line2, attributeStepsId);
}
else if (position == 2) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard3_hi });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step3 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard3_hi });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step3 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step3_title, R.string.activity_wizard_help_step3_line2, attributeStepsId);
}
else if (position == 3) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard4_hi });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step4 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard4_hi });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step4 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step4_title, R.string.activity_wizard_help_step4_line2, attributeStepsId);
}
else {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step1 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step1 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step1_title, R.string.activity_wizard_help_step1_line2, attributeStepsId);
}
break;
case "ur":
if (position == 0) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard2 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step1 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard2 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step1 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step1_title, R.string.activity_wizard_help_step2_line2, attributeStepsId);
} else if (position == 1) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step2 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step2 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step2_title, R.string.activity_wizard_help_step1_line2, attributeStepsId);
}
else if (position == 2) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard3_ur });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step3 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard3_ur });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step3 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step3_title, R.string.activity_wizard_help_step3_line2, attributeStepsId);
}
else if (position == 3) {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard4_ur });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step4 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard4_ur });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step4 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step4_title, R.string.activity_wizard_help_step4_line2, attributeStepsId);
}
else {
if (Util.getSharedPref(WizardHelpActivity.this).getInt("Theme", ConstantData.AppTheme.Dark.getValue()) == ConstantData.AppTheme.Dark.getValue()) {
a = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Dark, new int[] { R.attr.step1 });
} else {
a = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.wizard1 });
b = getTheme().obtainStyledAttributes(R.style.Light, new int[] { R.attr.step1 });
}
attributeResourceId = a.getResourceId(0, 0);
attributeStepsId = b.getResourceId(0, 0);
a.recycle();
fragment = WizardHelpPageFragment.getInstance(attributeResourceId, R.string.wizard_help_step1_title, R.string.activity_wizard_help_step1_line2, attributeStepsId);
}
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
new SendEmailAsyncTask(getApplicationContext(), getClass().getName(),"getItem(int position)", e).execute();
}
return fragment;
}
/* (non-Javadoc)
* @see android.support.v4.view.PagerAdapter#getCount()
*/
@Override
public int getCount() {
return 4;
}
}