得到此错误sendUserActionEvent()mView == null

时间:2016-05-02 09:56:41

标签: android login null

我是菜鸟,所以我找到了解决这个问题的方法,我得到了答案。我使用下面的代码实现了一个正常工作的登录系统,但我刚开始收到此错误sendUserActionEvent()mView == null,我无法再次登录。

  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);
    }
});
  }
}

05-02 11:20:52.500 4397-4397 / com.soultracker D /活动:performCreate调用secproduct feature valuefalse

05-02 11:20:52.500 4397-4397 / com.soultracker D / Activity:performCreate调试弹性值truetrue

05-02 11:20:52.545 4397-4520 / com.soultracker D / OpenGLRenderer:渲染所请求的脏区:true

05-02 11:20:52.550 4397-4397 / com.soultracker D / Atlas:验证地图...... 05-02 11:20:52.615 4397-4520 / com.soultracker I / OpenGLRenderer:初始化的EGL,版本1.4

05-02 11:20:52.630 4397-4520 / com.soultracker I / OpenGLRenderer:为上下文启用了HWUI保护,&amp; this = 0xaed09128,&amp; mEglDisplay = 1,&amp; mEglConfig = -1361804364

05-02 11:20:52.655 4397-4520 / com.soultracker D / OpenGLRenderer:启用调试模式0 05-02 11:20:52.940 4397-4397 / com.soultracker I /时间表:时间表:

Activity_idle id:android.os.BinderProxy@165b7f42 time:42856202 05-02 11:21:00.160 4397-4397 / com.soultracker D / ViewRootImpl:ViewPostImeInputStage ACTION_DOWN 05-02 11:21:16.540 4397-4397 / com.soultracker D / ViewRootImpl:ViewPostImeInputStage ACTION_DOWN 05-02 11:21:21.290 4397-4397 / com.soultracker D / ViewRootImpl:ViewPostImeInputStage ACTION_DOWN 05-02 11:21:21.440 4397-4397 / com.soultracker D / AbsListView:获取MotionRecognitionManager 05-02 11:21:25.740 4397-4397 / com.soultracker E / ViewRootImpl:sendUserActionEvent()mView == null

0 个答案:

没有答案