0

I want to make a Android java package to intent to an activity But whenever i trying to intent it is giving me nullpointerexception When I run it There is a newweb.java class in which there is this function

Public Void openweb(Context con,String url){
    Intent i=new Intent(con,myweb.class);
i.putStringExtra("webcode",url);
startactivity(i);

   }

myweb is an activity

In Mainactivity

    newweb web=new newweb();
Web.openweb(Mainactivity.this,url);

But error occurred nullpointerexception in newweb during intent

Ajay Shaw
  • 1
  • 1
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 12 '22 at 19:22
  • Please edit your question. Post the relevant code and the exception message with stacktrace. This will help us pinpoint the problem. – David Wasser Apr 12 '22 at 21:39
  • Try the answers to [what is a nullpointer exception and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it#:~:text=The%20NullPointerException%20(NPE)%20occurs%20when,that%20does%20not%20actually%20exist.) – Alias Cartellano Apr 12 '22 at 22:53

1 Answers1

0

Your code is a bit unclear but i guess youre trying to load a url using a webview on button click

  1. In your Activity A
public void openWeb(String url){
Intent intent=new Intent(ActivityA.this,ActivityB.class);
intent.putExtra("webUrl",url);
startActivity(intent);
}

2.In your Activity B

Intent intent=getIntent();
String url=intent.getStringExtra("webUrl");
webView.loadUrl(url);
return 0
  • 132
  • 5