Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Jonathan Etienne
Jonathan Etienne
24,572 Points

Unexpected error prompted from calling "webView.loadUrl(mUrl)"

Good day all,

I am going through the blogreader section, and have stumbled upon the following issues during the "Easy Sharing" module.

"webView.loadUrl(mUrl)"

I sense that this the source of the problem, because I try commenting out various part of the code, until I realized that when this line was commented it would not crash, but it wasn't the error would be prompted.

The entire code that i use is the following (in the BlogView activity java file):

package com.dooba.blogreader;

import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; import android.os.Build;

public class BlogWebViewActivity extends Activity {

protected String mUrl;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_blog_web_view);

    Intent intent = getIntent();
    Uri blogUri = intent.getData();
    mUrl = blogUri.toString();

    WebView webView = (WebView) findViewById(R.id.webView1); 
    webView.loadUrl(mUrl); 
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();

    if (itemId == R.id.action_share) {
        sharePost();
    }

    return super.onOptionsItemSelected(item);
} 

private void sharePost() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, mUrl);
    startActivity(Intent.createChooser(shareIntent, getString(R.string.share_chooser_title)));
}

}

Thanks in advance for your time, and effort into helping me resolve this dilemma.