我有这个应用程序显示 com.cleveroad.slidingtutorial库的帮助
我遵循文档协议android.app.Fragment
但是当关闭或滑动屏幕到下一个页面碎片时,我总是坚持这个错误。我尝试了1页以上,并且总是得到相同的错误尝试获取空数组的长度
gradle com.cleveroad上的滑动教程版本:slidingtutorial:1.0.8
滑动教程指南Cleveroad/SlidingTutorial-Android
MainActivityTutorialCrearContacto类
public class MainActivityTutorialCrearContacto extends Activity {
public UsuarioDao usuario;
public Typeface typeface_bold, typeface_regular;
private int[] mPagesColors;
private static final int TOTAL_PAGES = 1;
private static final int ACTUAL_PAGES_COUNT = 3;
private final String TAG = MainActivityTutorialCrearContacto.class.getSimpleName();
public static void start(Context context) {
context.startActivity(new Intent(context, MainActivityTutorialCrearContacto.class));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_tutorial);
Context ctx = getApplicationContext();
try {
typeface_regular = Typeface.createFromAsset(ctx.getAssets(), Constantes.TYPEFACE_FONT_OPENSANS_REGULAR);
typeface_bold = Typeface.createFromAsset(ctx.getAssets(), Constantes.TYPEFACE_FONT_OPENSANS_SEMIBOLD);
} catch (Exception e) {
e.printStackTrace();
}
mPagesColors = new int[]{
getResources().getColor(R.color.color_fondo_green_dark)
// ,getResources().getColor(R.color.colorPrimaryDark)
// ,getResources().getColor(R.color.color_fondo_orange_pido )
};
if (savedInstanceState == null) {
replaceTutorialFragment();
}
}
final TutorialPageProvider<Fragment> tutorialPageProvider = new TutorialPageProvider<Fragment>() {
@NonNull
@Override
public Fragment providePage(int position) {
switch (position) {
case 0: {
return new ContactoFirstragment();
}
case 1: {
return new ContactoFirstragment();
}
case 2: {
return new ContactoThirdFragment();
}
default: {
throw new IllegalArgumentException("Unknown position: " + position);
}
}
}
};
public void replaceTutorialFragment() {
try {
final IndicatorOptions indicatorOptions = IndicatorOptions.newBuilder(this)
.build();
final TutorialOptions tutorialOptions = TutorialFragment.newTutorialOptionsBuilder(this)
.setUseAutoRemoveTutorialFragment(false)
.setUseInfiniteScroll(false)
.setPagesColors(mPagesColors)
.setPagesCount(TOTAL_PAGES)
.setIndicatorOptions(indicatorOptions)
.setTutorialPageProvider(tutorialPageProvider)
.setOnSkipClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Util.guardarPreferencia(Constantes.VERTUTORIAL_CONTACTO, "ENTENDIDO", getApplicationContext());
try {
//getFragmentManager().popBackStack(); // THIS DON'T CLOSE DE ACTIVITY
finish();
// cierraFragmentTransaction();
} catch (Exception e) {
e.printStackTrace();
}
}
})
.build();
final TutorialFragment tutorialFragment = TutorialFragment.newInstance(tutorialOptions);
getFragmentManager()
.beginTransaction()
.replace(R.id.container, tutorialFragment)
.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
PageFragment Class
class ContactoSecondFragment extends PageFragment {
TextView tv_hola, textView_solicitaremail, textView2, textView1;
public UsuarioDao usuario;
DatabaseManager manager;
public Typeface typeface_bold, typeface_regular;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx = getContext();
try {
typeface_regular = Typeface.createFromAsset(ctx.getAssets(), Constantes.TYPEFACE_FONT_OPENSANS_REGULAR);
typeface_bold = Typeface.createFromAsset(ctx.getAssets(), Constantes.TYPEFACE_FONT_OPENSANS_SEMIBOLD);
} catch (Exception e) {
e.printStackTrace();
}
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.contacto_fragment_page_second, container, false);
findViews(view);
try {
if(typeface_bold!=null && typeface_regular!=null) {
tv_hola.setTypeface(typeface_bold);
textView1.setTypeface(typeface_regular);
textView2.setTypeface(typeface_regular);
textView_solicitaremail.setTypeface(typeface_regular);
}
checkDatabaseManager();
UsuarioDao usuario = manager.obtenerUsuario();
String nombre = WordUtils.capitalize(usuario.getNombre().toLowerCase());
tv_hola.setText("Hola " + nombre + "\n ¡Vamos a ayudarte!");
} catch (Exception e) {
tv_hola.setText("Hola ¡Vamos a ayudarte!");
}
return view;
}
private void findViews(View view) {
tv_hola = (TextView) view.findViewById(R.id.textView0_hola);
textView1 = (TextView) view.findViewById(R.id.textView1);
textView2 = (TextView) view.findViewById(R.id.textView2);
textView_solicitaremail = (TextView) view.findViewById(R.id.textView_solicitaremail);
}
@Override
protected int getLayoutResId() {
return R.layout.contacto_fragment_page_second;
}
@NonNull
@Override
protected TransformItem[] getTransformItems() {
return new TransformItem[]{
TransformItem.create(R.id.textView0_hola, Direction.RIGHT_TO_LEFT, 0.2f),
TransformItem.create(R.id.img_hola, Direction.LEFT_TO_RIGHT, 0.6f),
TransformItem.create(R.id.textView1, Direction.RIGHT_TO_LEFT, 0.8f),
TransformItem.create(R.id.textView2, Direction.LEFT_TO_RIGHT, 0.10f),
TransformItem.create(R.id.img_email, Direction.RIGHT_TO_LEFT, 0.3f),
TransformItem.create(R.id.textView_solicitaremail, Direction.LEFT_TO_RIGHT, 0.9f)
};
}
private void checkDatabaseManager() {
try {
if (manager == null) {
DatabaseManager.init(getContext());
manager = DatabaseManager.getInstance();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
错误
尝试获取null数组的长度
java.lang.NullPointerException: Attempt to get length of null array
at com.cleveroad.slidingtutorial.PageImpl.onDestroyView(PageImpl.java:71)
at com.cleveroad.slidingtutorial.PageFragment.onDestroyView(PageFragment.java:73)
at android.app.Fragment.performDestroyView(Fragment.java:2570)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
at android.app.FragmentManagerImpl.detachFragment(FragmentManager.java:1351)
at android.app.BackStackRecord.run(BackStackRecord.java:798)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1580)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:483)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)