首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"java.net.MalformedURLException:找不到协议“读取到html文件

"java.net.MalformedURLException:找不到协议“读取到html文件
EN

Stack Overflow用户
提问于 2012-10-17 20:45:05
回答 2查看 37.9K关注 0票数 11

我收到一个错误:java.net.MalformedURLException: Protocol not found

我想在网上读一个HTML文件

代码语言:javascript
复制
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();



}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-17 20:47:54

您的URI不是URI。没有协议组件。它需要http://或您想要的任何其他协议。

票数 38
EN

Stack Overflow用户

发布于 2016-07-14 20:39:57

代码语言:javascript
复制
String myUri = "";



myUri = "www.tcmb.gov.tr/kurlar/today.html";

你的uri不是completed.you,你可以像这样写完整的url。

代码语言:javascript
复制
String myUri="https://www.tcmb.gov.tr/kurlar/today.html";
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12934621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档