Home WebBackForwardList has a Null Pointer. How can I make it display my ListView instead of being Null?
Reply: 0

WebBackForwardList has a Null Pointer. How can I make it display my ListView instead of being Null?

user4883
1#
user4883 Published in June 20, 2018, 10:54 pm

The snippet of code where this is located and is not working:

Button btn5 = (Button) findViewById(R.id.historyBtn);
        btn5.setOnClickListener(new View.OnClickListener()

    {
        //gets the id of the webview in use
        WebView webView = (WebView) findViewById(R.id.WebviewScreen);

        public void onClick(View v) {

            //changes layout to histlist
           setContentView(R.layout.histlist);
            //displays the list
            ListView list = (ListView)findViewById(R.id.list);
            setupListScreen();

            WebBackForwardList currentList = webView.copyBackForwardList();
            int currentSize = currentList.getSize();

            for(int i = 0; i < currentSize; ++i) {
                WebHistoryItem item = currentList.getItemAtIndex(i);
                String url = item.getUrl();
                String[] newlist = {url};

                ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, newlist);

                list.setAdapter(adapter);
            }


        }




    });

The overall code (the snippet being near the bottom):

public class MainActivity extends Activity {



final int REQUEST_IMAGE_CAPTURE = 1;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setupScreenOne();
}


void setupScreenOne() {
    setContentView(R.layout.activity_main);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

    //when the search button is entered, it should return the text in the searchview and make it show on webview
    Button btn = (Button) findViewById(R.id.SearchBtn);
    btn.setOnClickListener(new View.OnClickListener() {
        //find webview to be used
        WebView webView = (WebView) findViewById(R.id.WebviewScreen);




        public void onClick(View v) {

            try {
                //gets the text from the searchview box
                SearchView searchinfo = (SearchView) findViewById(R.id.searchView);
                //turns into string from searchView
                String newstring = searchinfo.getQuery().toString();

                webView.loadUrl("https://www.google.com/search?q=" + newstring);
                webView.setWebViewClient(new WebViewClient());
            } catch (Exception e) {
                Log.d("onclickfucked", "1  ");
            }
        }
    });

    Button btn2 = (Button) findViewById(R.id.menuBtn);
    btn2.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            setContentView(R.layout.menu_screen);
            setupMenu();

        }

    });

    Button btn9 = (Button) findViewById(R.id.refreshBtn);
    btn9.setOnClickListener(new View.OnClickListener() {
        WebView webView = (WebView) findViewById(R.id.WebviewScreen);
        public void onClick(View v) {
            webView.reload();

        }

    });
}

void setupMenu() {


    Button btn3 = (Button) findViewById(R.id.backBtn);
    btn3.setOnClickListener(new View.OnClickListener()

    {

        public void onClick(View v) {
           setContentView(R.layout.activity_main);
            setupScreenOne();

        }

    });


    Button btn4 = (Button) findViewById(R.id.selfieBtn);
    btn4.setOnClickListener(new View.OnClickListener()

    {

        public void onClick(View v){

                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                    startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);

            }
        }

    });
    Button btn5 = (Button) findViewById(R.id.historyBtn);
    btn5.setOnClickListener(new View.OnClickListener()

    {
        //gets the id of the webview in use
        WebView webView = (WebView) findViewById(R.id.WebviewScreen);

        public void onClick(View v) {

            //changes layout to histlist
           setContentView(R.layout.histlist);
            //displays the list
            ListView list = (ListView)findViewById(R.id.list);
            setupListScreen();

            WebBackForwardList currentList = webView.copyBackForwardList();
            int currentSize = currentList.getSize();

            for(int i = 0; i < currentSize; ++i) {
                WebHistoryItem item = currentList.getItemAtIndex(i);
                String url = item.getUrl();
                String[] newlist = {url};

                ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, newlist);

                list.setAdapter(adapter);
            }


        }




    });
}

void setupListScreen(){


}


}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.240934 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO