gpt4 book ai didi

java - 为什么我的if语句条件是: "if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE)" always false?

转载 作者:行者123 更新时间:2023-11-30 05:41:09 35 4
gpt4 key购买 nike

我一直在关注如何选择图片、裁剪图片并将其上传到我的应用程序的教程...它选择、裁剪但上传未裁剪的图片...我没有看到任何错误。 ..

有:

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_WRITE_PERMISSION && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//THIS IS HAPPEN WHEN USER CLICK ALLOW ON PERMISSION
//START PICK IMAGE ACTIVITY
CropImage.startPickImageActivity(addceleb.this);
}
}

这将启动该功能:

@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri imageUri = CropImage.getPickImageResultUri(this, data);
Log.i("RESPONSE getPath", imageUri.getPath());
Log.i("RESPONSE getScheme", imageUri.getScheme());
Log.i("RESPONSE PathSegments", imageUri.getPathSegments().toString());
//GET IMAGEVIEW RESULT URI AND PASS TO IMAGEVIEW
imageView.setImageURI(imageUri);

//NOW CROP IMAGE URI
CropImage.activity(imageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.setMultiTouchEnabled(true)
.setRequestedSize(800, 800)
.setAspectRatio(1,1)
.start(this);

if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
Log.i("RESPONSE getUri", result.getUri().toString());
//GET CROPPED IMAGE URI AND PASS TO IMAGEVIEW
imageView.setImageURI(result.getUri());
}
}
}

显示以下建议:


Condition 'requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE' is always 'false' less... (Ctrl+F1)
Inspection info: This inspection analyzes method control and data flow to report possible conditions that are always true or false, expressions whose value is statically proven to be constant, and situations that can lead to nullability contract violations.
Variables, method parameters and return values marked as @Nullable or @NotNull are treated as nullable (or not-null, respectively) and used during the analysis to check nullability contracts, e.g. report NullPointerException (NPE) errors that might be produced.
More complex contracts can be defined using @Contract annotation, for example:
@Contract("_, null -> null") — method returns null if its second argument is null @Contract("_, null -> null; _, !null -> !null") — method returns null if its second argument is null and not-null otherwise @Contract("true -> fail") — a typical assertFalse method which throws an exception if true is passed to it
The inspection can be configured to use custom @Nullable
@NotNull annotations (by default the ones from annotations.jar will be used)

最佳答案

这是一个条件:

if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE /* && ... */) {
// ...
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
// ...
}
}

除非PICK_IMAGE_CHOOSER_REQUEST_CODE == CROP_IMAGE_ACTIVITY_REQUEST_CODE,否则后面的条件将为假。

关于java - 为什么我的if语句条件是: "if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE)" always false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55627644/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com