InputStream = httpURLConnection.getInputStream();停止工作

时间:2017-12-15 06:28:13

标签: java php android wampserver

我正在创建一个Android项目,其中Registrationadmin活动使用HttpURLConnection连接到PHP文件(在本地服务器中,localhost);

我遇到以下代码行的问题: InputStream = httpURLConnection.getInputStream(); 当我运行项目时,应用程序此时停止,它还提供D / NetworkSecurityConfig:未指定Network Security Config,使用平台默认此错误

问题出在哪里?

我在这里报告代码部分:

<?php
echo "this is it";
error_reporting(0);
require "init.php";
$admname = $_POST["admname"];
$admpass = $_POST["admpass"];
$admemail = $_POST["admemail"];
$admmob=$_POST["admmob"];
//$admname = "sdf";
//$admpassword = "sdf";
//$admemail = "sdf@r54";
//$admmob="sdf";
$sql = "INSERT INTO `admin` (`admname`,`admemail`, `admpass`, `admmob`) 
VALUES ('".$admname."','".$admemail."' '".$admpass."', '".$admmob."');";
if(!mysqli_query($con, $sql)){
    echo '{"message":"Unable to save the data to the database."}';
}
?>

register.php是

<?php
echo "this is init";
error_reporting(0);

$db_name = "mydata";
$mysql_user = "root";
$mysql_pass = "";
$server_name = "localhost";

$con = mysqli_connect($server_name, $mysql_user, $mysql_pass, $db_name);

if(!$con){
    echo '{"message":"Unable to connect to the database."}';
}

?>

,init.php是

12-17 10:46:51.950 2559-2559/? I/zygote: Not late-enabling -Xcheck:jni (already on)
12-17 10:46:51.973 2559-2559/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
12-17 10:46:52.373 2559-2559/com.example.hp.healthcareapp I/InstantRun: starting instant run server: is main process

                                                                        [ 12-17 10:46:52.399  1636: 1809 D/         ]
                                                                        HostConnection::get() New Host Connection established 0x9078a080, tid 1809


                                                                        [ 12-17 10:46:52.400  1636: 1809 W/         ]
                                                                        Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 
12-17 10:46:52.926 2559-2609/com.example.hp.healthcareapp D/OpenGLRenderer: HWUI GL Pipeline
12-17 10:46:53.046 2559-2609/com.example.hp.healthcareapp I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
12-17 10:46:53.047 2559-2609/com.example.hp.healthcareapp I/OpenGLRenderer: Initialized EGL, version 1.4
12-17 10:46:53.047 2559-2609/com.example.hp.healthcareapp D/OpenGLRenderer: Swap behavior 1
12-17 10:46:53.047 2559-2609/com.example.hp.healthcareapp W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
12-17 10:46:53.047 2559-2609/com.example.hp.healthcareapp D/OpenGLRenderer: Swap behavior 0
12-17 10:46:53.056 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglCreateContext: 0xa4b850c0: maj 2 min 0 rcv 2
12-17 10:46:53.129 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglMakeCurrent: 0xa4b850c0: ver 2 0 (tinfo 0xa4b83280)
12-17 10:46:53.264 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglMakeCurrent: 0xa4b850c0: ver 2 0 (tinfo 0xa4b83280)
12-17 10:46:53.576 2559-2559/com.example.hp.healthcareapp V/View: dispatchProvideAutofillStructure(): not laid out, ignoring 0 children of 1073741835
12-17 10:46:53.583 2559-2559/com.example.hp.healthcareapp I/AssistStructure: Flattened final assist data: 3512 bytes, containing 1 windows, 13 views
12-17 10:47:18.106 2559-2564/com.example.hp.healthcareapp I/zygote: Do partial code cache collection, code=23KB, data=30KB
12-17 10:47:18.108 2559-2564/com.example.hp.healthcareapp I/zygote: After code cache collection, code=23KB, data=30KB
12-17 10:47:18.108 2559-2564/com.example.hp.healthcareapp I/zygote: Increasing code cache capacity to 128KB
12-17 10:47:34.711 2559-2564/com.example.hp.healthcareapp I/zygote: Do partial code cache collection, code=61KB, data=59KB
12-17 10:47:34.713 2559-2564/com.example.hp.healthcareapp I/zygote: After code cache collection, code=61KB, data=59KB
12-17 10:47:34.713 2559-2564/com.example.hp.healthcareapp I/zygote: Increasing code cache capacity to 256KB
12-17 10:48:16.020 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglMakeCurrent: 0xa4b850c0: ver 2 0 (tinfo 0xa4b83280)
12-17 10:48:16.073 2559-2564/com.example.hp.healthcareapp I/zygote: Do full code cache collection, code=101KB, data=112KB
12-17 10:48:16.073 2559-2564/com.example.hp.healthcareapp I/zygote: After code cache collection, code=96KB, data=89KB
12-17 10:48:18.492 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglMakeCurrent: 0xa4b850c0: ver 2 0 (tinfo 0xa4b83280)
12-17 10:48:18.552 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglMakeCurrent: 0xa4b850c0: ver 2 0 (tinfo 0xa4b83280)
12-17 10:48:18.690 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglMakeCurrent: 0xa4b850c0: ver 2 0 (tinfo 0xa4b83280)
12-17 10:48:18.769 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglMakeCurrent: 0xa4b850c0: ver 2 0 (tinfo 0xa4b83280)
12-17 10:48:18.814 2559-2559/com.example.hp.healthcareapp V/View: dispatchProvideAutofillStructure(): not laid out, ignoring 0 children of 1073741834
12-17 10:48:18.822 2559-2559/com.example.hp.healthcareapp I/AssistStructure: Flattened final assist data: 3440 bytes, containing 1 windows, 12 views
12-17 10:48:18.837 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglMakeCurrent: 0xa4b850c0: ver 2 0 (tinfo 0xa4b83280)
12-17 10:48:19.106 2559-2609/com.example.hp.healthcareapp D/EGL_emulation: eglMakeCurrent: 0xa4b850c0: ver 2 0 (tinfo 0xa4b83280)
12-17 10:48:21.823 2559-2564/com.example.hp.healthcareapp I/zygote: Do partial code cache collection, code=122KB, data=111KB
12-17 10:48:21.823 2559-2564/com.example.hp.healthcareapp I/zygote: After code cache collection, code=122KB, data=111KB
12-17 10:48:21.823 2559-2564/com.example.hp.healthcareapp I/zygote: Increasing code cache capacity to 512KB
12-17 10:48:27.463 2559-2564/com.example.hp.healthcareapp I/zygote: Do full code cache collection, code=243KB, data=197KB
12-17 10:48:27.464 2559-2564/com.example.hp.healthcareapp I/zygote: After code cache collection, code=238KB, data=161KB
12-17 10:48:39.837 2559-2564/com.example.hp.healthcareapp I/zygote: Do partial code cache collection, code=247KB, data=176KB
12-17 10:48:39.838 2559-2564/com.example.hp.healthcareapp I/zygote: After code cache collection, code=247KB, data=176KB
12-17 10:48:39.842 2559-2564/com.example.hp.healthcareapp I/zygote: Increasing code cache capacity to 1024KB
12-17 10:48:51.981 2559-3513/com.example.hp.healthcareapp D/NetworkSecurityConfig: No Network Security Config specified, using platform default
12-17 10:48:52.010 2559-3513/com.example.hp.healthcareapp D/executes: this is executed
12-17 10:49:22.165 2559-3513/com.example.hp.healthcareapp W/System.err: java.io.FileNotFoundException: http://10.14.83.2:8080/register.php
12-17 10:49:22.165 2559-3513/com.example.hp.healthcareapp W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
12-17 10:49:22.165 2559-3513/com.example.hp.healthcareapp W/System.err:     at com.example.hp.healthcareapp.Registrationadmin$BackGround.doInBackground(Registrationadmin.java:91)
12-17 10:49:22.165 2559-3513/com.example.hp.healthcareapp W/System.err:     at com.example.hp.healthcareapp.Registrationadmin$BackGround.doInBackground(Registrationadmin.java:70)
12-17 10:49:22.166 2559-3513/com.example.hp.healthcareapp W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:333)
12-17 10:49:22.166 2559-3513/com.example.hp.healthcareapp W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
12-17 10:49:22.166 2559-3513/com.example.hp.healthcareapp W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
12-17 10:49:22.166 2559-3513/com.example.hp.healthcareapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
12-17 10:49:22.167 2559-3513/com.example.hp.healthcareapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
12-17 10:49:22.167 2559-3513/com.example.hp.healthcareapp W/System.err:     at java.lang.Thread.run(Thread.java:764)
12-17 10:49:22.167 2559-3513/com.example.hp.healthcareapp D/IOEX3: http://10.14.83.2:8080/register.php

这是我的logcat

project

由于

2 个答案:

答案 0 :(得分:0)

D / NetworkSecurityConfig:表示警告或警告不是错误,但仍然是应用程序崩溃

检查ineternet权限 检查您的服务器协议http或https 和参考https://developer.android.com/training/articles/security-config.html

答案 1 :(得分:0)

你可以尝试

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name='slc_pc'>
  <option>select</option>
 </select>