0

我正在尝试在显示进度条后实现登录,但它显示错误。下面是我正在使用的代码

class PostService extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
            String s = UserFunctions.response;
        Log.d(Details.TAG, "checking i response...");
            UserFunctions.basicLogin(email, password);
            Log.d(Details.TAG,
                    s + " " + UserFunctions.basicLogin(email, password));

            return s;
        }

        Intent i;

        @Override
        protected void onPostExecute(String r) {
            // TODO Auto-generated method stub
            super.onPostExecute(UserFunctions.response);
            Log.d(Details.TAG, "Password Point");
            if(UserFunctions.basicLogin(email, password)){
                i = new Intent("com.example.eve_haps.DASHBOARDACTIVITY");
                startActivity(i);
            }else {
                Toast.makeText(MainActivity.this,
                        "Login UnSuccesful. Check email and/or password",
                        Toast.LENGTH_SHORT).show();
            }

        }

    }

但它返回一个错误日志

E/AndroidRuntime( 7465): FATAL EXCEPTION: main
E/AndroidRuntime( 7465): java.lang.StringIndexOutOfBoundsException: length=0; regionStart=0; regionLength=17
E/AndroidRuntime( 7465):    at java.lang.String.startEndAndLength(String.java:593)
E/AndroidRuntime( 7465):    at java.lang.String.substring(String.java:1474)
E/AndroidRuntime( 7465):    at com.example.eve_haps.UserFunctions.basicLogin(UserFunctions.java:107)
E/AndroidRuntime( 7465):    at com.example.eve_haps.MainActivity$PostService.onPostExecute(MainActivity.java:105)
E/AndroidRuntime( 7465):    at com.example.eve_haps.MainActivity$PostService.onPostExecute(MainActivity.java:1)
E/AndroidRuntime( 7465):    at android.os.AsyncTask.finish(AsyncTask.java:602)
E/AndroidRuntime( 7465):    at android.os.AsyncTask.access$600(AsyncTask.java:156)
E/AndroidRuntime( 7465):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
E/AndroidRuntime( 7465):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 7465):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 7465):    at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 7465):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 7465):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 7465):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 7465):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 7465):    at dalvik.system.NativeStart.main(Native Method)

下面是实现登录的代码

public static boolean basicLogin(String email, String password) {

        String msg = "Login successful";
        boolean status = false;
        String url;
        String links[] = {
                "..." + "?user=",
                "..." + "?actn=login"
                        + "&user=" };
        auth_link = links[0]+email + "&password=" + password;
        response = Connect.doHTTPGet(auth_link);
//      result = getHttpResponse(url);
        Log.d(Details.TAG, " " + msg.length() + " " + UserFunctions.response.substring(0, 17) + " "+ UserFunctions.response.substring(0, 17).length() );
        if (UserFunctions.response.substring(0, 17).trim().equals(msg)) {
            Log.d(Details.TAG, " " + msg.length() + " " + UserFunctions.response.substring(0, 17));
            status = true;
        } 
        Log.d(Details.TAG, " " + "Connection Test"
                + UserFunctions.response);

        return status;

请问是什么错误。我会回复感谢

4

0 回答 0