Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6144157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:36:44+00:00 2026-05-23T18:36:44+00:00

I am a newbie in java and was trying android development . The following

  • 0

I am a newbie in java and was trying android development . The following code generated malformedURLException.can someone help me identify the exception.
Any hint would be highly helpful

package com.example.helloandroid;

import android.app.Activity;
//import android.widget.TextView;
import android.os.Bundle;
import java.net.*;
import java.io.*;
import android.widget.TextView;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        String outdata = "";
        URL url_g = new URL("http://www.google.com/");
        URLConnection ukr = url_g.openConnection();

        BufferedReader in = new BufferedReader(new InputStreamReader(ukr.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null)
            outdata += inputLine;
        in.close();
       tv.setText(outdata);
       setContentView(tv);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:36:45+00:00Added an answer on May 23, 2026 at 6:36 pm

    This is because URL constructor ( new URL(“http://www.google.com/”) ) throws a Checked Exception, in this case MalformedURLException, which means that you have to catch it or declare it in your method.

    Use a try/catch or the throws clause in the onCreate method.

    try/catch solution:

    public void onCreate(Bundle savedInstanceState) {
        ...
        try {
            URL url_g = new URL("http://www.google.com/");
        } catch(MalformedURLException e) {
            //Do something with the exception.
        }
        ...
    }
    

    Throws solution:

    @Override
    public void onCreate(Bundle savedInstanceState) throws MalformedURLException {
        ...
        URL url_g = new URL("http://www.google.com/");
        ...
    }
    

    Check this for more information on exceptions.

    http://download.oracle.com/javase/tutorial/essential/exceptions/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie to C++ learning by converting a java program to c++. The following code
Newbie question on drools. I am trying to access the following java class in
I am a java newbie and I am trying to understand the code given
I'm a Java newbie. I'm trying to figure out whether a number is a
I am a newbie to Java Web Application development. So far all I have
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
Newbie to LINQ, and trying to write the following query... select f.Section_ID, f.Page_ID, f.SortOrder,
I am a newbie to AS400-Java programming. I am trying to create my first
I am newbie with JPA. I'm trying to run some sample code using JPA
Java newbie here, I'm having trouble setting a new line in this code: String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.