Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不支持协议(Android)_Java_Javascript_Android_Cordova - Fatal编程技术网

Java 不支持协议(Android)

Java 不支持协议(Android),java,javascript,android,cordova,Java,Javascript,Android,Cordova,我正在尝试在phone gap中开发应用程序。它监视服务器作业。当前服务器不可用,因此我将系统设置为服务器。我将项目文件放在安装服务器的同一目录中。我正在尝试访问主活动中的文件。但它在我的模拟器上显示错误。错误标题协议不受支持。我正在分享下面的主要活动文件和html文件。请看这些文件。 主活动文件: package com.example.productionmonitor; import org.apache.cordova.DroidGap; import android.os.Bundle

我正在尝试在phone gap中开发应用程序。它监视服务器作业。当前服务器不可用,因此我将系统设置为服务器。我将项目文件放在安装服务器的同一目录中。我正在尝试访问主活动中的文件。但它在我的模拟器上显示错误。错误标题协议不受支持。我正在分享下面的主要活动文件和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\/Tango\tomcat\webapps\productionmanagerserver\Monitor app\productionMonitor.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\Tango\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>

登录
var-strFile;
函数userLogin()
{
window.location.href=“productionMonitor.htm”;
}
函数init()
{
var xmlhttp=null;
试一试{
xmlhttp=新的XMLHttpRequest();
}捕获(trymicrosoft){
试一试{
xmlhttp=新的ActiveXObject(“MsXML2.xmlhttp”);
}捕获(其他Microsoft){
试一试{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}捕获(失败){
xmlhttp=null;
}
}
}
if(xmlhttp==null)
警报(“创建请求对象时出错!”);
if(xmlhttp中的“带凭据”){
//检查XMLHttpRequest对象是否具有“withCredentials”属性。
//“withCredentials”仅存在于XMLHTTPRequest2对象上。
//open(方法、url、true);
}else if(XDomainRequest的类型!=“未定义”){
//否则,请检查XDomainRequest是否满足要求。
//XDomainRequest仅存在于IE中,是IE发出CORS请求的方式。
xmlhttp=新的XDomainRequest();
}               
返回xmlhttp;
}
函数CallWebservice()
{
var req=init();
变量url=”http://localhost:8080/identityserver/domains/allData";
请求打开('GET',url,true);
请求发送(空);
req.onreadystatechange=函数(){
if(req.readyState!=4)返回;//尚未返回
如果(请求状态!=200){
//在此处处理请求失败。。。
警报(“呼叫失败”);
返回;
}
//请求成功,请读取响应
strFile=req.responseText;
parseDomainList(strFile);
}
}
函数parseDomainList(dlist)
{
var xmlDoc=new DOMParser().parseFromString(strFile,'text/xml');
var domain=xmlDoc.getElementsByTagName(“域”);

对于(i=0;i来说,将文件放在windows计算机的何处并不重要。无论是android设备还是模拟器都无法访问这些文件。如果你仔细想想,那会很可怕

您需要将开发机器转换为适当的服务器,然后使用emulator的专用ip地址10.0.2.2访问它,这是开发机器的环回。如果您在设备上进行测试,则需要访问开发机器的本地ip地址,假定您在同一LAN上