我想在我的Parse用户中检索图片存储以显示在我的imageview上,不知何故它只是崩溃了。基本上是我的个人资料页面上的代码。我的布局设置了一个imagview。我存储的图像位于名为“file”的字段中,文件名为uploaded_file.png。我希望它加载到图像视图,我设置一个监听器,以便它允许用户采取和上传新图片。
我的代码如下:非常感谢任何帮助。非常感谢。
public class ProfileActivity extends Activity {
protected TextView mUsername;
protected EditText mPassword;
protected TextView mEmail;
protected TextView mCreateAccountTextView;
protected ParseUser mCurrentUser;
protected List<ParseUser> mUsers;
protected TextView chEmailbutton;
protected TextView chPassbutton;
protected ImageView profilePicture;
protected Uri mMediaUri;
protected String mFileType;
protected ParseObject currentObject;
protected TextView savePixButton;
final int PIC_CROP = 1;
//private static final String EMAIL_PATTERN =
// "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
// + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private Uri mImageCaptureUri;
private ImageView mImageView;
private static final int PICK_FROM_CAMERA = 1;
private static final int CROP_FROM_CAMERA = 2;
private static final int PICK_FROM_FILE = 3;
String username;
String email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.profile);
mUsername = (TextView) findViewById(R.id.usernameField);
mEmail = (TextView)findViewById(R.id.emailField);
mCurrentUser = ParseUser.getCurrentUser();
username = mCurrentUser.getUsername();
email = mCurrentUser.getEmail();
mUsername.setText(username);
mEmail.setText(email);
mMediaUri = getIntent().getData();
currentObject = mCurrentUser.getParseObject("file");
ParseFile image = currentObject.getParseFile("uploaded_file.png");
final ParseImageView imageView = (ParseImageView) findViewById(R.id.profilepix);
imageView.setParseFile(image);
imageView.loadInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
// The image is loaded and displayed!
int oldHeight = imageView.getHeight();
int oldWidth = imageView.getWidth();
//Log.v("LOG!!!!!!", "imageView height = " + oldHeight); // DISPLAYS 90 px
//Log.v("LOG!!!!!!", "imageView width = " + oldWidth); // DISPLAYS 90 px
}
});
profilePicture = (ImageView)findViewById(R.id.profilepix);
profilePicture.setOnClickListener(new View.OnClickListener() {
LogCat错误
05-13 23:20:44.439: E/ViewRootImpl(31057): sendUserActionEvent() mView == null
05-13 23:20:47.969: E/AndroidRuntime(31057): FATAL EXCEPTION: main
05-13 23:20:47.969: E/AndroidRuntime(31057): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fappbulously.sharemate/com.fappbulously.sharemate.ProfileActivity}: java.lang.NullPointerException
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.app.ActivityThread.access$700(ActivityThread.java:159)
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.os.Handler.dispatchMessage(Handler.java:99)
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.os.Looper.loop(Looper.java:137)
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.app.ActivityThread.main(ActivityThread.java:5419)
05-13 23:20:47.969: E/AndroidRuntime(31057): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 23:20:47.969: E/AndroidRuntime(31057): at java.lang.reflect.Method.invoke(Method.java:525)
05-13 23:20:47.969: E/AndroidRuntime(31057): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
05-13 23:20:47.969: E/AndroidRuntime(31057): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
05-13 23:20:47.969: E/AndroidRuntime(31057): at dalvik.system.NativeStart.main(Native Method)
05-13 23:20:47.969: E/AndroidRuntime(31057): Caused by: java.lang.NullPointerException
05-13 23:20:47.969: E/AndroidRuntime(31057): at com.fappbulously.sharemate.ProfileActivity.onCreate(ProfileActivity.java:95)
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.app.Activity.performCreate(Activity.java:5372)
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
05-13 23:20:47.969: E/AndroidRuntime(31057): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
05-13 23:20:47.969: E/AndroidRuntime(31057): ... 11 more
答案 0 :(得分:0)
我认为问题来自这一行:
mCurrentUser.getParseObject("file");
您正试图从ParseObject
表格的“文件”列中获取Users
,然后尝试从ParseFile
获取可能不存在的ParseObject
存在。
您想要的是从位于名为“file”的列中的ParseFile
表中检索Users
。由于ParseUser
继承自ParseObject
,您可以执行此操作:
ParseUser.getCurrentUser().getParseFile("file")