How to Create a new URL object

public URL (String spec) was added in API level 1
Creates a new URL instance by parsing spec.
Throws: MalformedURLException - if spec could not be parsed as a URL.

1. Declare a URL object named myURL.

2. In the MainActivity.java file, add the below line to the imports section.

import java.net.MalformedURLException;

3. Add the below line to the onCreate method. 

try {
myUrl = new URL("http://www.androidsbs.blogspot.com");
} catch (MalformedURLException e) { 
e.printStackTrace();
//Toast.makeText(this, "URL: Malformed URL Exception", Toast.LENGTH_LONG).show();

4. Compile and run!

Next Recommended Article: How to Declare a new HttpURLConnection