public class MainActivity extends AppCompatActivity {
    SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         sp = getSharedPreferences("userInfo", Context.MODE_WORLD_READABLE);
         EditText ed = findViewById(R.id.et_user_name);
         EditText ed1 = findViewById(R.id.et_psw);
        Button btn = findViewById(R.id.btn_login);
       final CheckBox  rem=(CheckBox) findViewById(R.id.cb_mima);
        CheckBox  auto=(CheckBox) findViewById(R.id.cb_auto);  if (rem.isChecked()) {            ed.setText(sp.getString("username", ""));
            ed1.setText(sp.getString("password", ""));           if (auto.isChecked()) {               Intent intent11 =new Intent(MainActivity.this,Main3Activity.class);
                        startActivity(intent11);
            }      }
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {                String username = ((EditText)findViewById(R.id.et_user_name)).getText().toString();
                String pwd = ((EditText)findViewById(R.id.et_psw)).getText().toString();                if (username.equals("陈同学")&&pwd.equals("19970601")){
                    Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                   /*if (rem.isChecked()) {
                     SharedPreferences.Editor editor=sp.edit();
                        editor.putString("username", username);
                        editor.putString("password", pwd);
                       editor.commit();                    }*/
                    Intent intent22 =new Intent(MainActivity.this,Main3Activity.class);
                    startActivity(intent22);
                }
                else{
                    Toast.makeText(MainActivity.this, "用户名密码错误", Toast.LENGTH_SHORT).show();
                }           }       });
   }无错误,但闪退,不知道什么原因

解决方案 »

  1.   

    把logcat贴出来看看。
      

  2.   

    public class MainActivity extends Activity {
    EditText ed,ed1;
        SharedPreferences sp;
        Button btn;
        CheckBox  rem,auto;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
             sp = getSharedPreferences("userInfo", Context.MODE_WORLD_READABLE);
             ed = (EditText)findViewById(R.id.et_user_name);
             ed1 =(EditText) findViewById(R.id.et_psw);
            btn = (Button)findViewById(R.id.btn_login);
           rem=(CheckBox) findViewById(R.id.cb_mima);
            auto=(CheckBox) findViewById(R.id.cb_auto);
    try {
      if (rem.isChecked()) {            ed.setText(sp.getString("username", ""));
                ed1.setText(sp.getString("password", ""));           if (auto.isChecked()) {               Intent intent11 =new Intent(MainActivity.this,Main3Activity.class);
                            startActivity(intent11);
                }      }
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {                String username =ed.getText().toString();
                    String pwd =ed1.getText().toString();                if (username.equals("陈同学")&&pwd.equals("19970601")){
                        Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                       if (rem.isChecked()) {
                         SharedPreferences.Editor editor=sp.edit();
                            editor.putString("username", username);
                            editor.putString("password", pwd);
                           editor.commit();                    }
                        Intent intent22 =new Intent(MainActivity.this,Main3Activity.class);
                        startActivity(intent22);
                    }
                    else{
                        Toast.makeText(MainActivity.this, "用户名密码错误", Toast.LENGTH_SHORT).show();
                    }           }       });
    }
    catch (Exception e)
    {
        Toast.makeText(getApplication(),e.toString() ,Toast.LENGTH_LONG).show();
    }
       }
    }  
    没崩溃啊
      

  3.   

    参考这个https://bbs.csdn.net/topics/392456107
      

  4.   

    是否在登录界面就调用了WIFI相关功能 却没有动态开启 wifi 网络权限