ParseUser错误

时间:2015-11-20 21:04:22

标签: java android parse-platform

enter image description here我正在我的项目中使用Parse。我需要获取一些ParseUser数据并显示它。 但是当我尝试获取Phone1 Phone2Gender并使用user.get("Phone1").toString()将其强制转换为字符串时,我得到一个nullPointerException,但我不知道为什么。

这是我的代码:

public class Profile extends Activity
{

RelativeLayout menu;
ParseUser user = ParseUser.getCurrentUser();
TextView name;
TextView age;
TextView gender;
ImageView photo;
EditText address;
EditText email;
EditText phone1;
EditText phone2;
TextView counter;
ProgressBar loading;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    menu = (RelativeLayout)findViewById(R.id.menuProfile);
    name = (TextView) findViewById(R.id.textProfileName);
    age = (TextView) findViewById(R.id.textProfileBirth);
    gender = (TextView) findViewById(R.id.textProfileGender);
    photo = (ImageView) findViewById(R.id.imageProfile);
    address = (EditText) findViewById(R.id.fieldProfileAddress);
    email = (EditText) findViewById(R.id.fieldProfileEmail);
    phone1 = (EditText) findViewById(R.id.fieldProfilePhone1);
    phone2 = (EditText) findViewById(R.id.fieldProfilePhone2);
    counter = (TextView) findViewById(R.id.textProfileCounter);
    loading = (ProgressBar) findViewById(R.id.loadingProfile);
    name.setText(user.get("Name").toString());
    age.setText(user.get("BirthDay").toString() + "/" + user.get("BirthMonth").toString() + "/" + user.get("BirthYear").toString());
    gender.setText(user.get("Gender").toString());//I got the error here
    email.setText(user.getEmail());
    phone1.setText(user.get("Phone1").toString());//I get the error here
    phone2.setText(user.get("Phone2").toString());//I got the error here        
    counter.setText(Integer.parseInt(user.get("Trocas").toString()));        
    double lat = Double.parseDouble(user.get("Lat").toString());
    double lng = Double.parseDouble(user.get("Lng").toString());
    try {
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        address.setText(geocoder.getFromLocation(lat, lng, 1).get(0).getAddressLine(0) + "\n" + geocoder.getFromLocation(lat, lng, 1).get(0).getLocality() + "," + geocoder.getFromLocation(lat, lng, 1).get(0).getAdminArea());
    } catch (IOException e) {
        e.printStackTrace();
    }
    ParseFile file = (ParseFile)user.get("Photo");
        file.getDataInBackground(new GetDataCallback() {
            public void done(byte[] data, ParseException e) {
                if (e == null) {
                    Bitmap img1 = BitmapFactory.decodeByteArray(data, 0, data.length);
                    photo.setImageBitmap(img1);
                } else {
                    Log.d("test", "There was a problem downloading the data.");
                }
            }
        });        
}

Phone1Phone2Gender是字符串,它们在我的Parse表中有值。

那么,我应该怎么做才能让这个工作,我不能只放一个if(user.get("Gender)!=null),我必须有这个信息。

现实化:

我尝试了phone1.setText(String.valueOf(user.get("Phone1")));并显示为null。我100%确定我的表中有数据。它不是空的。

0 个答案:

没有答案