0

I want to call the class "Market", which describes the webview. It should be done "onclick" when clicking on scrollable menu. But after I click the button my app just crashes, and I have no idea what to do now.

Main Activity:

switch (item.getItemId()) {
            case R.id.item1:
                //your action
                break;
            case R.id.item2:
                //your action
                break;
            case R.id.item3:
                //your action
                break;
            case R.id.item4:
                //your action
                setContentView(R.layout.market_activity);
                market.setthepage();
                break;
            case R.id.item5:
                //your action
                break;

Market Class:


public class Market extends AppCompatActivity {

    WebView wb;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        }
        public void setthepage(){
            wb = (WebView) findViewById(R.id.web_market);
            wb.getSettings().setJavaScriptEnabled(true);
            wb.loadUrl("https://www.pepper.pl/");
        }

    @Override
    public void onBackPressed() {

        if (wb.canGoBack()){
            wb.goBack();
        }else{
            super.onBackPressed();
        }
    }}

.. and a simple webview.

I was trying using intend, context etc. but am probably using it wrong. Can you help me with my problem?

Thank you in advance, Milo

EAS
  • 366
  • 2
  • 18
Milo
  • 11
  • 1
  • Where in MainActivity do you call this switch? Also please add crash log. – Torima Mar 27 '22 at 22:14
  • Ok, I did it somehow. Had to change the function name to "onCreate" in Market class. Thank you for your response. – Milo Mar 27 '22 at 23:10
  • If you are still willing to help, I have other problem (already posted few days ago) here: https://stackoverflow.com/questions/71488321/text-in-textview-is-not-showing-strings-from-java-file-openweathermap – Milo Mar 27 '22 at 23:11
  • Do you intend for `Market` to be a separate activity? If not, it should not inherit from `AppCompatActivity`. Aside from that, it's not clear what you're asking, and if you app crashes you should add the crash log to your question. – Tyler V Mar 28 '22 at 02:17
  • If you have already answered this question, then provide the answer and mark it as such. – Matt Zappitello Mar 29 '22 at 20:25

0 Answers0