2 xiaorourou945 xiaorourou945 于 2016.02.28 00:18 提问

空指针,大神版主帮帮忙吧

public class StartLoginActivity extends Activity {

// 账号输入框
private EditText inputAccount;

//密码输入框
private EditText inputPassword;

// 登录按钮
private Button loginButton;

private GlobalVariable mGlobalVariable;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    //透明状态栏
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    //透明导航栏
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

    inputAccount = (EditText) findViewById(R.id.account_edittext);
    inputPassword = (EditText) findViewById(R.id.password_edittext);

    Button loginButton = (Button) findViewById(R.id.login_button);
    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View source) {
            GlobalVariable mGlobalVariable = new GlobalVariable();
            new GeocodeingTask().execute( mGlobalVariable.account = inputAccount.getText().toString(), mGlobalVariable.password = inputPassword.getText().toString());
        }
    });
}

public class GeocodeingTask extends AsyncTask<String, Void, List<GlobalVariable>> {

    @Override
    protected List<GlobalVariable> doInBackground(String... params) {

        String json = RequestUtil.RequestJson("http://wechat.svner.com/login.php", "POST", params[0]);
        Gson gson = new Gson();
        class tmp {
            public int result;
        }
        System.out.println(json);
        tmp n = gson.fromJson(json, tmp.class);
        if (n.result == 0) {
            Toast.makeText(getApplicationContext(), "账号或密码错误", Toast.LENGTH_SHORT).show();
            System.out.print("error============================");
        } else {
            Intent intent = new Intent(StartLoginActivity.this, StartMainBodyActivity.class);
            startActivity(intent);
        }
        return null;
    }
}

}
。。。
。。。
。。。
public class GlobalVariable {
public String account;
public String password;
}
图片说明图片说明

1个回答

caozhy
caozhy   Ds   Rxr 2016.02.28 06:22
已采纳

tmp n = gson.fromJson(json, tmp.class);
看下这一步解析json是不是正确,服务器怎么返回的。

xiaorourou945
xiaorourou945 搞定了,谢谢
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!