___ ___ erkimt java.lang.IllegalArgumentException time to create a SnackBar ______ qstntxt ___

I'm developing an application that accesses moodle from my college and I posted the first version. Since then I've noticed some app crashes displayed on the Google Play console but I could not find the reason. The error you are giving in the Console is as follows:

%pre%

And good ... From what I understand the error is in the following function:

%pre%

When called by this one:

%pre%

Could anyone tell me what might be causing this error? I researched a lot but he's fine

    
______ azszpr326195 ___

I noticed that you have to call the Snack inside the onCreateView, but at the moment there is still no View to anchor the Snack

%pre%

Try to call the creation of the Snack on the next cycle, indicate using %code% or %code%

    
___

1

I'm developing an application that accesses moodle from my college and I posted the first version. Since then I've noticed some app crashes displayed on the Google Play console but I could not find the reason. The error you are giving in the Console is as follows:

java.lang.RuntimeException: 
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2695)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2769)
at android.app.ActivityThread.access$900 (ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1430)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:135)
at android.app.ActivityThread.main (ActivityThread.java:5910)
at java.lang.reflect.Method.invoke (Native Method)
at java.lang.reflect.Method.invoke (Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1200)

Caused by: java.lang.IllegalArgumentException: 
at android.support.design.widget.Snackbar.make (Snackbar.java:137)
at ufsj.apps.moodle.moodle_helpers.Helpers.createSnackBar (Helpers.java:79)
at ufsj.apps.moodle.moodle_index_fragments.CoursesFragment.populateMaterias 
(CoursesFragment.java:291)
at ufsj.apps.moodle.moodle_index_fragments.CoursesFragment.onCreateView 
(CoursesFragment.java:99)
at android.support.v4.app.Fragment.performCreateView (Fragment.java:2346)
at android.support.v4.app.FragmentManagerImpl.moveToState 
(FragmentManager.java:1428)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState 
(FragmentManager.java:1759)
at android.support.v4.app.FragmentManagerImpl.moveToState 
(FragmentManager.java:1827)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange 
(FragmentManager.java:3244)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated 
(FragmentManager.java:3200)
at android.support.v4.app.FragmentController.dispatchActivityCreated 
(FragmentController.java:195)
at android.support.v4.app.FragmentActivity.onStart 
(FragmentActivity.java:597)
at android.support.v7.app.AppCompatActivity.onStart 
(AppCompatActivity.java:177)
at android.app.Instrumentation.callActivityOnStart 
(Instrumentation.java:1248)
at android.app.Activity.performStart (Activity.java:6213)
at android.app.ActivityThread.performLaunchActivity 
(ActivityThread.java:2658)

And good ... From what I understand the error is in the following function:

public static void createSnackBar(View view, String message) {
    Snackbar = Snackbar.make(
            view,
            message,
            Snackbar.LENGTH_SHORT);

    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams)
            snackbar.getView().getLayoutParams();

    View snackBarView = snackbar.getView();
    snackBarView.setBackgroundColor(ResourcesCompat
            .getColor(
                    view.getResources(),
                    R.color.colorAccent,
                    null)); // snackbar background color

    snackbar.setActionTextColor(
            ResourcesCompat
                    .getColor(
                            view.getResources(),
                            R.color.colorPrimaryText,
                            null));

    params.setMargins(0, 0, 0, (int) (56 * 
    Resources.getSystem().getDisplayMetrics().density));
    snackbar.getView().setLayoutParams(params);

    snackbar.show();
   }
}

When called by this one:

 ...if (!Connectivity.INSTANCE.isConnected(getContext())) {
        Helpers.createSnackBar(getActivity().findViewById(R.id.main_content),"Verifique a conexão com a internet.");
    } else {...

Could anyone tell me what might be causing this error? I researched a lot but he's fine

    
asked by anonymous 29.08.2018 / 17:04

1 answer

0

I noticed that you have to call the Snack inside the onCreateView, but at the moment there is still no View to anchor the Snack

at ufsj.apps.moodle.moodle_index_fragments.CoursesFragment.onCreateView 
(CoursesFragment.java:99)

Try to call the creation of the Snack on the next cycle, indicate using OnStart or OnViewCreated

    
30.08.2018 / 19:26