-2

I have similar problem like the one in the link below.!

passing url and title to a webview in android

I have a code like this in the MainActivity:

ListView lv;
Arrayadapter<String>aa;
String items[]={"item1","item2"};

@Override
protected void onCreate(Bundle Savedinstancestate){
super.onCreate(Savedinstancestate);
lv=(ListView)findViewById(R.id.listView1);

aa=new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_dropdown_item_1line,items) ;
lv.setAdapter(aa);

lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Intent newActivity0 = new Intent(MainActivity.this, Mywebpage.class);
    newActivity0.putExtra("title", str[position]);
    switch (position) {
        case 0:
            newActivity0.putExtra("url", "http://www.google.com");
            break;
        case 1:
            newActivity0.putExtra("url", "file:///android_asset/item1.html");
            break;
        case 2:
            newActivity0.putExtra("url", "file://android_asset/item2.html");
            break;
    }

and in Mypage class get intent is like

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webviewpage);

    Bundle extras = getIntent().getExtras();
    String title, url;

    if (extras != null) {
        title = extras.getString("title");
        url = extras.getString("url");

        WebView wbView = (WebView) findViewById(R.id.WebView);
        wbView.getSettings().setJavaScriptEnabled(true);
        wbView.loadUrl(url);

//WbView.setWebViewClient(new myWebViewClient()); }

And have tried with and without setting webview clients(the line which I have commented towards end, with a corresponding class).

I am getting Runtime NULLPOINTER Exception when I try to click on the item.

Community
  • 1
  • 1
Manikandan
  • 417
  • 4
  • 8
  • 18
  • 2
    @Lele There **aren't** too many slashes: they have to be exactly **3**, as correctly posted. – Phantômaxx Mar 02 '15 at 12:12
  • 1
    I would pass only the file name. The rest can be added in the receiving Activity. – Phantômaxx Mar 02 '15 at 12:17
  • When I click on list item getting runtime NULLPOINTER exception in performLaunchActivity instrumentation.newActivity and ActivityThread.performLaunchActivity...caused at android.app.Activity.findViewById at mypage.java file – Manikandan Mar 02 '15 at 12:22
  • Is setting a code like w1.SetWebviewclient (new mywebview()); mandatory.? – Manikandan Mar 02 '15 at 12:27
  • @Der-Golem i did as suggested by you.. Concatenated the string in second activity.. But it didn't work till now.. Trying still.. :) – Manikandan Mar 02 '15 at 12:32
  • 1
    Wel it's hard to tell, by seeing little or no code... is the variable passed? does the file exist? is the extension consistent (htm vs html)? how do you load the url into the WebView? Also the full log would help. It seems there's a fail in finding the View. – Phantômaxx Mar 02 '15 at 12:34
  • 1
    Maybe `setContentView()` hasn't been called **before** finding the View? – Phantômaxx Mar 02 '15 at 12:39
  • @Der-Golem added corresponding code.. – Manikandan Mar 02 '15 at 13:18
  • 1
    `in Mypage class get intent` <=> `... , Mywebpage.class);` Class name mismatch. And this one lacks a slash: `newActivity0.putExtra("url", "file://android_asset/item2.html");` – Phantômaxx Mar 02 '15 at 13:39
  • Checking that.. Will update/edit this comment soon.. – Manikandan Mar 02 '15 at 16:57
  • It's not working as per the suggestion and also there's no GetIntent used in the code..guess its mandate for implicit intents – Manikandan Mar 02 '15 at 18:44
  • 1
    Add your logcat and line in which you are getting nullpointer exception. – Darpan Mar 03 '15 at 04:56
  • Sure..unable to save the complete logcat..these were lines which had that issue.. When I click on list item getting runtime NULLPOINTER exception in performLaunchActivity instrumentation.newActivity and ActivityThread.performLaunchActivity...caused at android.app.Activity.findViewById at mypage.java file can you please try to replicate this at your end..? – Manikandan Mar 03 '15 at 18:59
  • @Darpan, had added the answer, but thanks for taking your time out.! :-) – Manikandan Mar 05 '15 at 15:13

1 Answers1

0

I found the answer to the problem! I had declared Webview, identifying it before onCreate method in my Second Activity, which has resulted in this problem.!

Also in the code, which had provided previously, as putExtra("stringname", "value");

And so, after getting extras, in Bundle

extras.getExtra("stringname");

is enough and had previously messed up in that place.!

Guess, any additional logcat information would have helped further in resolving atleast one of the issues.! Since it had been quite sometime, after which I was able to get the logcat information due to a few issues, I worked on own.! But thanks for helping out.! Had upvoted all.! :-)

Manikandan
  • 417
  • 4
  • 8
  • 18