我收到此错误sendUserActionEvent()mView == null

时间:2016-04-29 08:44:25

标签: android login null

我是一个新手,我实现此登录之前有这个代码工作,我开始得到这个错误sendUserActionEvent()mView == null 在我的logcat中,我再也无法在我的应用程序中登录,我谷歌相当一点没有解决方案

 public class Activity_Login extends Activity implements OnClickListener {
 ImageView img_login,img_register;
 EditText edit_email,edit_password;
 ConnectiveCheckingActivity con;
 Utils util;
 List<UserProfile_List> ulist;
 int n=0;
 CheckBox check_remember;
 TextView text_forgot;
 Button btn_f1,btn_f2;
 int reminder=0;
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    con = new ConnectiveCheckingActivity(Activity_Login.this);
    util = new Utils(Activity_Login.this);
    edit_email = (EditText)findViewById(R.id.edit_email);
    edit_password = (EditText)findViewById(R.id.edit_password);
    btn_f1 = (Button)findViewById(R.id.front_arrow);
    btn_f2 = (Button)findViewById(R.id.front_arrow1);
    edit_password = (EditText)findViewById(R.id.edit_password);
    text_forgot = (TextView)findViewById(R.id.lbl_forgot);
    check_remember = (CheckBox)findViewById(R.id.check_remember);
    int remember=util.LoadPrefInt(Utils.REMEMBER_ME);
    if(remember==1)
    {
        check_remember.setChecked(true);
        edit_email.setText(util.LoadPref(Utils.USER_EMAIL));
        edit_password.setText(util.LoadPref(Utils.USER_PASSWORD));
    }
    else
    {
        check_remember.setChecked(false);
        edit_email.setText("");
        edit_password.setText("");

    }

    check_remember.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (((CheckBox) v).isChecked()) {
                util.SavePrefInt("rememberme",1);


            }
            else  
            {
                util.SavePrefInt("rememberme",0);


            }
        }
    });
    img_login=(ImageView)findViewById(R.id.img_login);
    img_register=(ImageView)findViewById(R.id.img_register);
    img_login.setOnClickListener(this);
    img_register.setOnClickListener(this);
    text_forgot.setOnClickListener(this);
   }
   @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.img_login:
        if(edit_email.getText().toString().length() == 0)
                {

            edit_email.setError( "Email is required!" );

                }
        else if(edit_password.getText().toString().length() == 0)
        {
            edit_password.setError( "Password is required!" );
        }
        else
        {
            String email=edit_email.getText().toString();

            String password=edit_password.getText().toString();


            if(con.getConnection())
            {

             Login(email,password);
            }
            else{
                con.showalert();
            }
        }
        break;
    case R.id.lbl_forgot:
    Intent i1=new Intent(Activity_Login.this,Activity_ForgotPassword.class);
        startActivity(i1);
        break;

    case R.id.img_register:

        Intent i=new Intent(Activity_Login.this,Activity_Register.class);
        startActivity(i);
        break;

     case R.id.front_arrow:
        edit_email.clearFocus();
        edit_password.requestFocus();
     break;
       case R.id.front_arrow1:
        edit_email.clearFocus();
        edit_password.clearFocus();
        img_login.requestFocus();
        break;

       default:
        break;
    }
   }

    public void Login(final String email,final String password) {

     DialogUtils.showDialog(DialogUtils.DialogType.PROGRESS_DIALOG,
            Activity_Login.this, getString(R.string.loading));
     OkHttpClient client = new OkHttpClient();

     RequestBody formBody = new FormEncodingBuilder()
            .add("username", email)

            .add("password", password)

            .build();
     Request request = new Request.Builder()
            .get()
        .url(getString(R.string.api))

            .post(formBody).build();

      client.newCall(request).enqueue(new Callback() {
        @Override
        public void onResponse(final Response response) throws IOException {
            DialogUtils.dismissDialog(
            DialogUtils.DialogType.PROGRESS_DIALOG, Activity_Login.this);
            final String result = response.body().string().trim();

            LogUtils.i("onSuccess result "+ result);
            try {

                if (result != null) {

                    n=1;

                }
            } catch (JsonSyntaxException e) {
                e.printStackTrace();

            }
            runOnUiThread(new Runnable() {
                public void run() {
                    if(n==1)
                    {


                        Log.i("username",edit_email.getText().toString());
                    Log.i("password",edit_password.getText().toString());
                        util.SavePref("useremail", email);
                        util.SavePref("userpassword", password);
            if(result.contains("Error please enter a username or password"))
                        {
                util.ShowToast("Error please enter a username or password");

                        }
            else if(result.contains("Error Invalid username or password"))
                        {
                    util.ShowToast("Error Invalid username or password");
                        }
                        else
                        {

                            String resultdata =result.substring(9, result.length()-1);
                            try {
                                String userid = null;
  String  rid=null,zid=null,user_img=null,pcf=null,cmid=null,cmname=null,cid=null,firstname=null,lastname=null,title=null;
                                Gson gson = new Gson();
                            ulist = Arrays.asList(gson.fromJson(resultdata,
                                        UserProfile_List[].class));

                                if (ulist.size() > 0) {
                                    for (int i = 0; i < ulist.size(); i++) {

                                        userid=ulist.get(i).id;
                                        rid=ulist.get(i).rid;
                                        zid=ulist.get(i).zid;
                                        cid=ulist.get(i).cid;
                                        user_img=ulist.get(i).img_mid;
                                        pcf=ulist.get(i).pcf;
                                        cmid=ulist.get(i).cmid;
                                        cmname=ulist.get(i).cmname;
                                        firstname=ulist.get(i).firstname;
                                        lastname=ulist.get(i).lastname;
                                        title=ulist.get(i).title;


                                    }
                                    LogUtils.i("userid"+userid);
                                    LogUtils.i("rid"+rid);
                                    LogUtils.i("zid"+zid);
                                    util.SavePref("userimage", user_img);

                                    util.SavePref("userid", userid);
                                    util.SavePref("firstname", firstname);
                                    util.SavePref("lastname", lastname);
                                    util.SavePref("title", title);
                                    util.SavePref("userid", userid);
                                    util.LoadPref(Utils.USER_ID);
                                    util.SavePref("rid", rid);

                                    util.SavePref("zid", zid);
                                    util.SavePref("cid", cid);
                                    util.SavePref("pcf", pcf);
                                    util.LoadPref(Utils.PCF);
                                    util.SavePref("cmid", cmid);
                                    util.LoadPref(Utils.CM_ID);
                                    util.SavePref("cmname", cmname);
                                    util.LoadPref(Utils.CM_NAME);

                                    util.SavePref("useremail", email);
                                    util.SavePref("userpassword", password);
                            String  user_id = util.LoadPref(Utils.USER_ID);


            Intent i=new  Intent(Activity_Login.this,Activity_Home.class);
                                    i.putExtra("tabpage", "1");
                                    startActivity(i);
                                    finish();

                                }

                            } catch (JsonSyntaxException e) {
                            }

                        }

                    }}
            });

             }

        @Override
        public void onFailure(Request arg0, IOException arg1) {
            DialogUtils.dismissDialog(
                    DialogUtils.DialogType.PROGRESS_DIALOG,  Activity_Login.this);
        }
    });
  }
}

0 个答案:

没有答案