0

I have an app, which parses RSS feed into list, and when we click on the item of the list it calls the other activity to display in WebView the content inside rss feed link:

public class ListListener implements OnItemClickListener {
  // List item's reference
  List<RssItem> listItems;
  // Calling activity reference
  Activity activity;

  public ListListener(List<RssItem> aListItems, Activity anActivity) {
    listItems = aListItems;
    activity  = anActivity;
  }

/**
 * Start a browser with url from the rss item.
 */
  public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
    //Intent i = new Intent(Intent.ACTION_VIEW);
    //i.setData(Uri.parse(listItems.get(pos).getLink()));
    Intent i = new Intent(activity, WebPageActivity.class);
    i.putExtra("LINK", Uri.parse(listItems.get(pos).getLink()));
    //Intent intent = new Intent(this, WebPageController(listItems.get(pos).getLink()));
    activity.startActivity(i);

  }

}

And from onItemClick it supposed to call that WebView activity to display the webpage

  public class WebPageActivity extends ActionBarActivity {
    private WebView webview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();
        String url = intent.getStringExtra("LINK");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_page);

        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webview = (WebView) findViewById(R.id.webView1);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(url);
     }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.web_page, menu);
    return true;
}

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
   }
   }

There is no mistakes in compilation, but when I click in the app to go on WebPage activity it stops. Here is my logcat http://pastie.org/9606345

Ophelia
  • 549
  • 1
  • 5
  • 26

3 Answers3

0

replace your onCreate with this code :

@Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();
        String url = intent.getStringExtra("LINK");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_page);

        webview = (WebView) findViewById(R.id.webView1);
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);

        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(url);
     }

the problem is that you get WebSettings before define webview id .

Sats
  • 875
  • 6
  • 12
0

Try out as below:

public class WebPageActivity extends ActionBarActivity {
    private WebView webview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_page);

        Intent intent = getIntent();
        String url = intent.getStringExtra("LINK");

         webview = (WebView) findViewById(R.id.webView1);
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);

        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(url);
     }
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
0

Check this Answer, it says you need to fix your project dependencies as 'gen' first, then 'src'. Give it a try. It should solve ClassDefNotFound error

Community
  • 1
  • 1
Darpan
  • 5,623
  • 3
  • 48
  • 80