Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"java.net.MalformedURLException: Protocol not found" read to html file

Tags:

java

I receviced an error: java.net.MalformedURLException: Protocol not found

I want to read an HTML file on the web

mainfest :::::   uses-permission android:name="android.permission.INTERNET"

uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" 

import com.doviz.R.id;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {

public String inputLine;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String myUri = "";
    myUri = "www.tcmb.gov.tr/kurlar/today.html";


    Toast.makeText( this, "step-1 " , Toast.LENGTH_LONG).show();
    try{
            Toast.makeText( this, "step -2" , Toast.LENGTH_LONG).show();
            myUri = "www.tcmb.gov.tr/kurlar/today.html";

        URL url = new URL(myUri);

        Toast.makeText( this, "step-3" , Toast.LENGTH_LONG).show();
            final InputStream is =url.openStream();
            Toast.makeText( this, "step -4" , Toast.LENGTH_LONG).show();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            Toast.makeText( this, "step -5 " , Toast.LENGTH_LONG).show();   
        String line;
        Toast.makeText( this, "step-6" , Toast.LENGTH_LONG).show();
        while ((line=reader.readLine())!=null){
           // page.add(line);
        }
        Toast.makeText( this, " step-7" , Toast.LENGTH_LONG).show();
    }
    catch(Exception e){
        //e.printStackTrace();
        TextView tx =(TextView)findViewById(id.TextView1); 
        tx.setText(myUri + " >>> "+  e.getMessage());
        Toast.makeText( this, "problem = " + e.getMessage() + " -- "+ e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
        //System.exit(1);
    }

    Toast.makeText( this, "step -8" , Toast.LENGTH_LONG).show();



}
like image 763
sananne Ahsgh Avatar asked Oct 17 '12 12:10

sananne Ahsgh


People also ask

How do I fix Java net MalformedURLException?

Handling MalformedURLException The only Solution for this is to make sure that the url you have passed is legal, with a proper protocol. The best way to do it is validating the URL before you proceed with your program. For validation you can use regular expression or other libraries that provide url validators.

What is Java net MalformedURLException?

java.net.MalformedURLException. Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a specification string or the string could not be parsed.


1 Answers

Your URI is not a URI. There is no protocol component. It needs http:// or whatever other protocol you intend.

like image 180
user207421 Avatar answered Nov 15 '22 22:11

user207421