Android Activity无法启动

时间:2012-04-11 16:23:59

标签: java android

我正在从php脚本解析json数据。如果我在EditText字段中写入正确的值,则活动将开始。但在写完incorect后,一项活动将无法启动。如何解决?

我将仅显示有关使用布局项的部分,因为解析顺利。 也是什么样的aproach最好测试登录值?用户名很容易检查,因为它是由JSON返回的,但是密码呢。我认为把它放在JSON中是错误的选择。

try{
    JSONArray jArray = new JSONArray(result);
    for(int i=0;i<jArray.length();i++){
        JSONObject json_data = jArray.getJSONObject(i);
        usernameFromDB = json_data.getString("username");
        firstnameFromDB = json_data.getString("firstname");
        lastnameFromDB = json_data.getString("lastname");
        emailFromDB = json_data.getString("email");
        phoneFromDB = json_data.getString("phone1");
        skypeFromDB = json_data.getString("skype");
        cityFromDB = json_data.getString("city");
        descriptionFromDB = json_data.getString("description");

        System.out.println(usernameFromDB+ "  " + firstnameFromDB+"  "+lastnameFromDB+"  "
                + emailFromDB + "  " + phoneFromDB +"  " + skypeFromDB+ "  " + cityFromDB + "  "+
                descriptionFromDB);
    }
}
catch(JSONException e){
    AlertDialog alertDialog = new AlertDialog.Builder(MyMoodleApplicationActivity.this).create();
    alertDialog.setTitle("Klaida!");
    alertDialog.setMessage("Toks vartotojas neegzistuoja");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            return;
        }
    });
    alertDialog.show();
        Log.e("log_tag", "Error parsing data "+e.toString());
}
if(usr.length()== 0){
    AlertDialog alertDialog = new AlertDialog.Builder(MyMoodleApplicationActivity.this).create();
    alertDialog.setTitle("Klaida!");
    alertDialog.setMessage("Jus neivedete slapyvardžio");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            return;
        }
    });
    alertDialog.show();
}
else if(psw.length()==0){
    AlertDialog alertDialog = new AlertDialog.Builder(MyMoodleApplicationActivity.this).create();
    alertDialog.setTitle("Klaida!");
    alertDialog.setMessage("Jus neivedete slaptažodžio");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            return;
        }
    });
    alertDialog.show();
}
else if(usernameFromDB.equals(usr)){
    Intent in = new Intent(getApplicationContext(), LoggedUser.class);
    in.putExtra("firstname", firstnameFromDB);
    in.putExtra("lastname", lastnameFromDB);
    in.putExtra("email", emailFromDB);
    in.putExtra("phone1", phoneFromDB);
    in.putExtra("skype", skypeFromDB);
    in.putExtra("city", cityFromDB);
    in.putExtra("description", descriptionFromDB);

    startActivity(in);

0 个答案:

没有答案