Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.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 安卓,登录问题_Java_Php_Android_Json - Fatal编程技术网

Java 安卓,登录问题

Java 安卓,登录问题,java,php,android,json,Java,Php,Android,Json,我目前正在开发一个Android应用程序。当我尝试登录时,日志猫中出现以下错误 11-30 21:23:18.694: E/JSON Parser(1914): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject 11-30 21:23:18.923: W/dalvikvm(1914): threadid=10: thr

我目前正在开发一个Android应用程序。当我尝试登录时,日志猫中出现以下错误

11-30 21:23:18.694: E/JSON Parser(1914): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
11-30 21:23:18.923: W/dalvikvm(1914): threadid=10: thread exiting with uncaught exception (group=0xb3e56288)

11-29 22:23:17.329: E/AndroidRuntime(1858): FATAL EXCEPTION: AsyncTask #1
11-29 22:23:17.329: E/AndroidRuntime(1858): java.lang.RuntimeException: An error occured while executing doInBackground()
11-29 22:23:17.329: E/AndroidRuntime(1858):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at java.lang.Thread.run(Thread.java:856)
11-29 22:23:17.329: E/AndroidRuntime(1858): Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=localhost/BCASStudentInfo/login.php
11-29 22:23:17.329: E/AndroidRuntime(1858):     at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:591)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at com.bcas.bcasstudentinfo.JSONParser.makeHttpRequest(JSONParser.java:110)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at com.bcas.bcasstudentinfo.Login$TryLogin.doInBackground(Login.java:134)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at com.bcas.bcasstudentinfo.Login$TryLogin.doInBackground(Login.java:1)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-29 22:23:17.329: E/AndroidRuntime(1858):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-29 22:23:17.329: E/AndroidRuntime(1858):     ... 5 more
11-29 22:23:22.417: E/WindowManager(1858): Activity com.bcas.bcasstudentinfo.Login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@b45b4a40 that was originally added here
11-29 22:23:22.417: E/WindowManager(1858): android.view.WindowLeaked: Activity com.bcas.bcasstudentinfo.Login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@b45b4a40 that was originally added here
11-29 22:23:22.417: E/WindowManager(1858):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
11-29 22:23:22.417: E/WindowManager(1858):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
11-29 22:23:22.417: E/WindowManager(1858):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
11-29 22:23:22.417: E/WindowManager(1858):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
11-29 22:23:22.417: E/WindowManager(1858):  at android.view.Window$LocalWindowManager.addView(Window.java:547)
11-29 22:23:22.417: E/WindowManager(1858):  at android.app.Dialog.show(Dialog.java:277)
11-29 22:23:22.417: E/WindowManager(1858):  at com.bcas.bcasstudentinfo.Login$TryLogin.onPreExecute(Login.java:119)
11-29 22:23:22.417: E/WindowManager(1858):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
11-29 22:23:22.417: E/WindowManager(1858):  at android.os.AsyncTask.execute(AsyncTask.java:534)
11-29 22:23:22.417: E/WindowManager(1858):  at com.bcas.bcasstudentinfo.Login$1.onClick(Login.java:70)
11-29 22:23:22.417: E/WindowManager(1858):  at android.view.View.performClick(View.java:4084)
11-29 22:23:22.417: E/WindowManager(1858):  at android.view.View$PerformClick.run(View.java:16966)
11-29 22:23:22.417: E/WindowManager(1858):  at android.os.Handler.handleCallback(Handler.java:615)
11-29 22:23:22.417: E/WindowManager(1858):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-29 22:23:22.417: E/WindowManager(1858):  at android.os.Looper.loop(Looper.java:137)
11-29 22:23:22.417: E/WindowManager(1858):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-29 22:23:22.417: E/WindowManager(1858):  at java.lang.reflect.Method.invokeNative(Native Method)
11-29 22:23:22.417: E/WindowManager(1858):  at java.lang.reflect.Method.invoke(Method.java:511)
11-29 22:23:22.417: E/WindowManager(1858):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-29 22:23:22.417: E/WindowManager(1858):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-29 22:23:22.417: E/WindowManager(1858):  at dalvik.system.NativeStart.main(Native Method)

11-30 21:23:18.694:E/JSON解析器(1914):解析数据org.JSON.JSONException:Value时出错您的登录URL应该是

http://localhost/BCASStudentInfo/login.php
而不是

localhost/BCASStudentInfo/login.php

我尝试过使用
private静态最终字符串登录\u URL=”http://10.0.2.2/BCASStudentInfo/login.php";我仍然收到相同的错误,我的应用程序停止工作您试图在退出活动后显示对话框。对于此错误,“Activity com.bcas.bcasstudentinfo.Login已泄漏window com.android.internal.policy.impl.PhoneWindow$DecorView@b45b4a40最初添加在这里的是“尝试删除并检查一次agian..so sais”E/JSON解析器(1914):解析数据org.json.JSONException时出错:Value抱歉,我是android新手,实际上我想把“LOG”放在哪里。该值将包含在“json”变量中,因此它将作为json对象
<?php
    $host = "localhost";
    $dbname = "bcasdb";    
    $username = "root";
    $password = "";

    $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');

    try
    {

        $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
    }
    catch(PDOException $ex)
    {
        die("Failed to connect to the database: " . $ex->getMessage());
    }

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
    {
        function undo_magic_quotes_gpc(&$array)
        {
            foreach($array as &$value)
            {
                if(is_array($value))
                {
                    undo_magic_quotes_gpc($value);
                }
                else
                {
                    $value = stripslashes($value);
                }
            }
        }

        undo_magic_quotes_gpc($_POST);
        undo_magic_quotes_gpc($_GET);
        undo_magic_quotes_gpc($_COOKIE);
    }

    header('Content-Type: text/html; charset=utf-8');

    session_start();
?>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }


    public JSONObject getJSONFromUrl(final String url) {

        // Making HTTP request
        try {
            // Construct the client and the HTTP request.
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            // Execute the POST request and store the response locally.
            HttpResponse httpResponse = httpClient.execute(httpPost);
            // Extract data from the response.
            HttpEntity httpEntity = httpResponse.getEntity();
            // Open an inputStream with the data content.
            is = httpEntity.getContent();

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            // Create a BufferedReader to parse through the inputStream.
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            // Declare a string builder to help with the parsing.
            StringBuilder sb = new StringBuilder();
            // Declare a string to store the JSON object data in string form.
            String line = null;

            // Build the string until null.
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }

            // Close the input stream.
            is.close();
            // Convert the string builder data to an actual string.
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // Try to parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // Return the JSON Object.
        return jObj;

    }


    // function get json from url
    // by making HTTP POST or GET mehtod
    public JSONObject makeHttpRequest(String url, String method,
            List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if(method == "POST"){
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            }else if(method == "GET"){
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}
http://localhost/BCASStudentInfo/login.php
localhost/BCASStudentInfo/login.php