不支持协议(Android)



我正在尝试在电话间隙中开发应用程序。它监视服务器作业。目前服务器不可用,所以我把我的系统作为服务器。我将项目文件放在安装服务器的同一目录中。我正试图在主要活动中访问我的文件。但它在我的模拟器上显示错误。错误标题为"不支持协议"。我在下面分享主活动文件和html文件。请看这些文件。主活动文件:

package com.example.productionmonitor;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends DroidGap{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        System.out.println("Here");
        super.setIntegerProperty("loadUrlTimeoutValue",120000);
       super.loadUrl("file////C:/Program Files/Elixir Technologies/Tango/tomcat/webapps/productionmanagerserver/Monitor app/productionMonitor.htm");
        //super.loadUrl("file:///android_asset/www/productionMonitor.htm");
        //super.loadUrl("C:///|Program Files/Elixir Technologies/TangotomcatwebappsproductionmanagerserverMonitor appproductionMonitor.htm");
        //super.loadUrl("http:///localhost:8080/productionmanagerserver/productionMonitor.htm");
    }

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

这是我保存在位置(C:\Program Files\Elixir Technologies\Dango\tomcat\webapps\productionmanagerserver\Monitor-app\login.html(的html文件,我想访问该文件。

<!doctype html>
<html lang="en-US">
<head>
    <meta charset="utf-8">
    <title>Login</title>
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Varela+Round">
    <link rel="stylesheet" href="./files/login.css">
    <!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script>
    var strFile ;
    function userLogin()
    {
        window.location.href = "productionMonitor.htm";
    }
    function init()
        {
            var xmlhttp = null ;
            try {
                xmlhttp = new XMLHttpRequest();
            } catch (trymicrosoft) {
                try {
                    xmlhttp = new ActiveXObject("MsXML2.XMLHTTP");
                } catch (othermicrosoft) {
                    try {
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (failed) {
                            xmlhttp = null;
                        }
                    }
                }
            if (xmlhttp == null)
            alert("Error creating request object!");
            if ("withCredentials" in xmlhttp) {
                // Check if the XMLHttpRequest object has a "withCredentials" property.
                // "withCredentials" only exists on XMLHTTPRequest2 objects.
                //xhr.open(method, url, true);
            } else if (typeof XDomainRequest != "undefined") {
                // Otherwise, check if XDomainRequest.
                // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
                xmlhttp = new XDomainRequest();
            }               
            return xmlhttp ;
        }
        function CallWebservice()
        {
            var req = init() ;
            var url ="http://localhost:8080/identityserver/domains/allData";
            req.open('GET',url,true);
            req.send(null);             
            req.onreadystatechange = function() {
                if (req.readyState != 4) return; // Not there yet
                if (req.status != 200) {
                     // Handle request failure here...
                    alert("Call failed");
                    return;
                }
                // Request successful, read the response
                strFile = req.responseText ;
                parseDomainList(strFile);                       
            }
        }
        function parseDomainList(dlist)
        {
            var xmlDoc = new DOMParser().parseFromString(strFile,'text/xml');
            var domain = xmlDoc.getElementsByTagName("domain");
            for (i=0;i<domain.length;i++)
            {
                var dname =domain[i].getElementsByTagName("domain_name");
                var domainid = document.getElementById("domain") ;
                var option=document.createElement("option");
                domainid.appendChild(option);               
            }
            alert(strFile) ;
            userLogin() ;
        }
    </script>
</head>
<body>
    <div id="login">
        <h2><span class="fontawesome-lock"></span>Sign In</h2>
        <form action="javascript:void(0);" method="POST">
            <fieldset>
                <p><label for="email">User Name</label></p>
                <p><input type="email" id="email" value="admin" onBlur="if(this.value=='')this.value='admin'" onFocus="if(admin')this.value=''"></p> 
                <p><label for="password">Password</label></p>
                <p><input type="password" id="password" value="admin" onBlur="if(this.value=='')this.value='admin'" onFocus="if(this.value=='admin')this.value=''"></p>
                <p><label for="domain">Domain List</label></p>
                <p><select type="domain" id="domain"> </select> </p>                
                <p><input type="submit" value="Sign In" onclick="CallWebservice()"></p>
            </fieldset>
        </form>
    </div> <!-- end login -->
</body> 
</html>

把文件放在windows机器上的哪个位置并不重要。无论是您的android设备还是Emulator都无法访问它们。如果你仔细想想,那就太可怕了。

你需要把你的开发机器变成一个合适的服务器,然后从模拟器中用特殊的ip地址10.0.2.2访问它,这是开发机器的环回。如果你在一台设备上进行测试,你需要访问开发机器的本地IP地址,假设你在同一个局域网上。

最新更新