0

主な目的は、アプリを Web 上の mysql データベースに接続することです。データは JSON 形式で収集されます。log cat からデータが入っているように見えますが、データを受信した後もアプリがクラッシュし続けます。これは、logCat から取得したエラーです。

    E/SpannableStringBuilder(3081): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
09-08 06:17:57.720: E/SpannableStringBuilder(3081): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
09-08 06:17:57.740: E/SpannableStringBuilder(3081): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
09-08 06:17:57.740: E/SpannableStringBuilder(3081): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
09-08 06:18:05.655: E/JSON(3081): {"tag":"login","success":1,"error":0,"uid":"20","user":{"name":"mash","email":"mafulun4real@gmail.com","created_at":"28\/04\/13 06:27:"}}n
09-08 06:18:05.665: E/AndroidRuntime(3081): FATAL EXCEPTION: main
09-08 06:18:05.665: E/AndroidRuntime(3081): java.lang.NullPointerException
09-08 06:18:05.665: E/AndroidRuntime(3081):     at com.nairation.rss.LoginActivity.onPostExecute(LoginActivity.java:70)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at com.nairation.rss.LoginActivity.onPostExecute(LoginActivity.java:1)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at android.os.AsyncTask.finish(AsyncTask.java:631)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at android.os.Looper.loop(Looper.java:137)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at android.app.ActivityThread.main(ActivityThread.java:5289)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at java.lang.reflect.Method.invokeNative(Native Method)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at java.lang.reflect.Method.invoke(Method.java:525)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
09-08 06:18:05.665: E/AndroidRuntime(3081):     at dalvik.system.NativeStart.main(Native Method)

これがコードです

package com.nairation.rss;

import org.json.JSONException;
import org.json.JSONObject;

import com.nairation.library.DatabaseHandler;
import com.nairation.library.JSONParser;
import com.nairation.library.UserFunctions;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.widget.EditText;

public class LoginActivity extends AsyncTask<String, Void, Integer>{

    private ProgressDialog progressDialog;
    private int responsecode = 0;
    private JSONParser jparser;
    private String username;
    private String password;
    private Login activity;

    public LoginActivity(ProgressDialog progressDialog){
        this.progressDialog = progressDialog;
    }
    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        progressDialog.show();
    }

    @Override
    protected Integer doInBackground(String... params) {
        // TODO Auto-generated method stub
        int count = params.length;
        if(count == 2){
            username = params[0];
            password = params[1];
            UserFunctions userfunc = new UserFunctions();
            JSONObject jp = userfunc.loginUser(username, password);
            try{
                if(jp.getString("success") != null){
                    String res = jp.getString("success");

                    if(Integer.parseInt(res) == 1){
                        //Dat means the use is successfully logged in
                        DatabaseHandler db = new DatabaseHandler(activity.getApplicationContext());
                        JSONObject juser = jp.getJSONObject("user");
                        userfunc.logoutUser(activity.getApplicationContext());
                        db.addUser(juser.getString("name"), juser.getString("email"), jp.getString("uid"), juser.getString("created_at"));
                        responsecode = 1;
                    }
                }
            } catch(NullPointerException e){
                e.printStackTrace();
            } catch(JSONException e){
                e.printStackTrace();
            }
        }else{
            responsecode = 0;
        }
        return responsecode;
    }

    @Override
    protected void onPostExecute(Integer responsecode) {
        // TODO Auto-generated method stub
        //super.onPostExecute(responsecode);
        EditText username = (EditText) activity.findViewById(R.id.loginname);
        EditText pword = (EditText) activity.findViewById(R.id.loginpass);

        if (responsecode == 1){
            username.setText("");
            pword.setText("");
            progressDialog.dismiss();
        }

        if (responsecode == 0){
            progressDialog.dismiss();
            activity.showLoginError(responsecode);
        }
    }

}
4

2 に答える 2