No view found for id 0x7f0801d0 (com.example.recycler/top_this_week_webview) for fragment TopThisWeekFragment

Published

I have a small project but there is an error, here I explain where the error is

The complete error is as follows: :

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.androidrion.navigationdrawer, PID: 30525
    java.lang.IllegalArgumentException: No view found for id 0x7f0801d0 (com.androidrion.navigationdrawer:id/top_this_week_webview) for fragment TopThisWeekFragment{1e467af} (485eb865-b2d8-4991-84c5-68ae567ba105 id=0x7f0801d0)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:513)
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
        at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7386)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)

And here I will attach some files related to the error above :

MemberListAdapter.java

@Override
    public void onBindViewHolder(MemberViewHolder holder, int position) {
        final Member member = memberList.get(position);

        holder.memberThumb.setImageResource(member.getThumb());
        holder.memberName.setText(member.getName());
        //holder.memberTeam.setText(member.getTeam());
        holder.itemView.setOnClickListener(v -> {
            AppCompatActivity activity = (AppCompatActivity) v.getContext();
            Fragment myFragment = new TopThisWeekFragment();
            activity.getSupportFragmentManager().beginTransaction().
                    replace(R.id.top_this_week_webview, myFragment).
                    addToBackStack(null).commit();
        });
    }

TopThisWeekFragment.java

@SuppressLint("SetJavaScriptEnabled")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        //assert savedInstanceState != null;
        //savedInstanceState.putInt("position", position);
        
        // Inflate the layout for this fragment
        //setContentView(R.layout.fragment_top_this_week);
        View view =  inflater.inflate(R.layout.fragment_top_this_week, container, false);

        mWebView = view.findViewById(R.id.top_this_week_webview);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.getSettings().setDisplayZoomControls(false);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.setWebViewClient(new WebViewClient() {
            @Nullable
            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
                if(url.contains("google")||url.contains("facebook")){
                    InputStream textStream = new ByteArrayInputStream("".getBytes());
                    return getTextWebResource(textStream);
                }
                return super.shouldInterceptRequest(view, url);
            }
            @Override
            public void onPageFinished(WebView view, String url){

                mWebView.loadUrl("javascript:(function() { " +
                        "document.getElementsByTagName('header')[0].style.display = 'none'; " + "})()");
                mWebView.loadUrl("javascript:(function() { " +
                        "document.getElementsByTagName('nav')[0].style.display = 'none'; " + "})()");
                mWebView.loadUrl("javascript:(function() { " +
                        "document.getElementsByTagName('section')[0].style.display = 'none'; " + "})()");

            }
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {

                mWebView.loadUrl("javascript:(function() { " +
                        "document.getElementsByTagName('header')[0].style.display = 'none'; " + "})()");
                mWebView.loadUrl("javascript:(function() { " +
                        "document.getElementsByTagName('nav')[0].style.display = 'none'; " + "})()");
                mWebView.loadUrl("javascript:(function() { " +
                        "document.getElementsByTagName('section')[0].style.display = 'none'; " + "})()");
            }
        });
        mWebView.loadUrl("https://example.com");
        //int position = 0;
        //mWebView.loadUrl(MemberListAdapter.memberList.get(position).getUrl());
        return view;
    } 

fragment_top_this_week.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.AboutFragment">

    <!-- TODO: Update blank fragment layout -->
    <WebView
        android:id="@+id/top_this_week_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

Maybe there are friends here who are willing to help, thank you.

Source: Android Questions

Published
Categorized as adapter, android, fragment, java, onclicklistener

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq