public class MainActivity extends AppCompatActivity {
WebView webview;
//I did this
Intent intent = getIntent();
String I = intent.getStringExtra( "Author" );
// and removed this
String url="http://pixelay.com/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview= (WebView) findViewById(R.id.webview);
new MyAsynTask().execute();
}
private class MyAsynTask extends AsyncTask<Void, Void, Document> {
@Override
protected Document doInBackground(Void... voids) {
Document document = null;
try {
// Here
document= Jsoup.connect(I).get();
document.getElementsByClass("main-navigation").remove();
document.getElementsByClass("custom-header-image").remove();
} catch (IOException e) {
e.printStackTrace();
}
return document;
}
@Override
protected void onPostExecute(Document document) {
super.onPostExecute(document);
//Here
webview.loadDataWithBaseURL(I,document.toString(),"text/html","utf-8","");
webview.getSettings().setCacheMode(
WebSettings.LOAD_CACHE_ELSE_NETWORK );
webview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view,
WebResourceRequest request) {
//Here
view.loadUrl(I);
return super.shouldOverrideUrlLoading(view, request);
}
});
}
}
But it does not work
Logcat shows this
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object
How can I can do that? Please help me