Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in xml preview #2

Open
romainhamm opened this issue Jan 24, 2019 · 4 comments
Open

Problem in xml preview #2

romainhamm opened this issue Jan 24, 2019 · 4 comments
Labels
bug Something isn't working

Comments

@romainhamm
Copy link

With the original version of the library or this fork, I have a problem during xml preview but not when I launch my app directly on a phone. It's annoying because if I put this customview in a scrollview I can't scroll in preview.

It's in this method com.github.ialokim.phonefield.CountriesAdapter.getView

This is the stackStrace : java.lang.NullPointerException at android.content.res.Resources_Delegate.getDrawable(Resources_Delegate.java:189) at android.content.res.Resources.getDrawable(Resources.java:827) at android.content.Context.getDrawable(Context.java:635) at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463) at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203) at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191) at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102) at androidx.appcompat.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:86) at androidx.appcompat.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:94) at com.github.ialokim.phonefield.CountriesAdapter.getView(Unknown Source) at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:204) at android.widget.Spinner.onMeasure(Spinner.java:602) at androidx.appcompat.widget.AppCompatSpinner.onMeasure_Original(AppCompatSpinner.java:421) at androidx.appcompat.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java) at android.view.View.measure_Original(View.java:23169) at android.view.View_Delegate.measure(View_Delegate.java:80) at android.view.View.measure(View.java:23133) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535) at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1187) at android.widget.LinearLayout.onMeasure(LinearLayout.java:706) at android.view.View.measure_Original(View.java:23169) at android.view.View_Delegate.measure(View_Delegate.java:80) at android.view.View.measure(View.java:23133) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535) at android.widget.LinearLayout.measureVertical(LinearLayout.java:825) at android.widget.LinearLayout.onMeasure(LinearLayout.java:704) at android.view.View.measure_Original(View.java:23169) at android.view.View_Delegate.measure(View_Delegate.java:80) at android.view.View.measure(View.java:23133) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535) at android.widget.LinearLayout.measureVertical(LinearLayout.java:825) at android.widget.LinearLayout.onMeasure(LinearLayout.java:704) at android.view.View.measure_Original(View.java:23169) at android.view.View_Delegate.measure(View_Delegate.java:80) at android.view.View.measure(View.java:23133) at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1308) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.widget.ScrollView.onMeasure(ScrollView.java:350) at android.view.View.measure_Original(View.java:23169) at android.view.View_Delegate.measure(View_Delegate.java:80) at android.view.View.measure(View.java:23133) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.view.View.measure_Original(View.java:23169) at android.view.View_Delegate.measure(View_Delegate.java:80) at android.view.View.measure(View.java:23133) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) at android.view.View.measure_Original(View.java:23169) at android.view.View_Delegate.measure(View_Delegate.java:80) at android.view.View.measure(View.java:23133) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.view.View.measure_Original(View.java:23169) at android.view.View_Delegate.measure(View_Delegate.java:80) at android.view.View.measure(View.java:23133) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) at android.view.View.measure_Original(View.java:23169) at android.view.View_Delegate.measure(View_Delegate.java:80) at android.view.View.measure(View.java:23133) at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:604) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:343) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:385) at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:509) at com.android.tools.idea.rendering.RenderTask.lambda$inflate$4(RenderTask.java:638) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

@ialokim ialokim added the bug Something isn't working label Jan 24, 2019
@ialokim
Copy link
Owner

ialokim commented Jan 24, 2019

Thanks for your issue, I've noticed that too already, but didn't look into it.

If you have some time, could you investigate why exactly this is happening? I suspect the application context required in line 57 to cause the problem. Maybe we could just display a "dummy" flag while in xml preview mode with isInEditMode()?

@romainhamm
Copy link
Author

I think the same thing, we need to use the isInEditMode() method but unfortunately I have not time today to investigate this. I'm going to take a look this weekend 😃

@romainhamm
Copy link
Author

romainhamm commented Jan 29, 2019

After investigate I added this method in my CustomPhoneInputLayout class :

    @Override
    protected void prepareView() {
         if (!isInEditMode())
            super.prepareView();
    }

It's not the more elegant solution but it works. I can now scroll in the preview mode but the PhoneField layout isn't displayed. To go more deeper I think we can add isInEditMode() in prepareView() by wrapping the adapter (and in all location when it is called) and the editText is still displayed.

@ialokim
Copy link
Owner

ialokim commented Feb 1, 2019

Checking this fix with the sample app results in always getting another error:
java.lang.ClassNotFoundException: com.google.i18n.phonenumbers.NumberParseException.

This class is imported in PhoneField.java, but for some reason it is not available while displaying the xml preview. The isInEditMode() method doesn't work in this case as the PhoneInputLayout.java extends the PhoneField and for now, I don't have any other ideas.

Would be great if you could clone the repository and try to preview the sample app's main_layout.xml in your Android Studio version to confirm it's not an odd problem with my local configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants