onCreate()方法被跳过

时间:2018-07-11 08:48:19

标签: java android logcat android-logcat

我正在创建一个类似Instagram的应用,现在我很难过。用户选择图像时,他们单击下一步按钮,然后转到下一个场景以编写标题。但是发生的事情是用户只是上传图片而没有去现场添加字幕。他们直接添加到要添加字幕后显示的场景。

这些是我的LogCat上显示的错误:

07-10 15:23:21.150 30970-31309/tabian.com.hash E/ImageLoader: UIL doesn't support scheme(protocol) by default [com.google.android.gms.tasks.zzu@f488c6e]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))
java.lang.UnsupportedOperationException: UIL doesn't support scheme(protocol) by default [com.google.android.gms.tasks.zzu@f488c6e]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromOtherSource(BaseImageDownloader.java:280)
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:99)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.downloadImage(LoadAndDisplayImageTask.java:291)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryCacheImageOnDisk(LoadAndDisplayImageTask.java:274)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:230)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:136)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

at java.lang.Thread.run(Thread.java:818)

这是我认为失败的代码:

GalleryFragment:

TextView nextScreen = view.findViewById(R.id.tvNext);
nextScreen.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.d(TAG, "onClick: Navigating to the final share screen.");

        if(isTaskRoot ()){
            Intent intent = new Intent(GalleryFragment.this.getActivity(), NextActivity.class);
            intent.putExtra(getString(R.string.selected_image), mSelectedImage);
            GalleryFragment.this.startActivity(intent);
        }else{
            Intent intent = new Intent(GalleryFragment.this.getActivity(), AccountSettingsActivity.class);
            intent.putExtra(getString(R.string.selected_image), mSelectedImage);
            intent.putExtra(getString(R.string.return_to_fragment), getString(R.string.edit_profile_fragment));
            GalleryFragment.this.startActivity(intent);
            Objects.requireNonNull(GalleryFragment.this.getActivity()).finish();
        }
    }
});

UniversalImageLoader:

public static void setImage(String imgURL, ImageView image, final ProgressBar mProgressBar, String append){

    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.displayImage(append + imgURL, image, new ImageLoadingListener() {
        @Override
        public void onLoadingStarted(String imageUri, View view) {
            if(mProgressBar != null){
                mProgressBar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            if(mProgressBar != null){
                mProgressBar.setVisibility(View.GONE);
            }
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            if(mProgressBar != null){
                mProgressBar.setVisibility(View.GONE);
            }
        }

        @Override
        public void onLoadingCancelled(String imageUri, View view) {
            if(mProgressBar != null){
                mProgressBar.setVisibility(View.GONE);
            }
        }
    });
}
}

编辑:

private String mAppend = "file:/";

//use the grid adapter to adapter the images to gridview
    GridImageAdapter adapter = new 
GridImageAdapter(GalleryFragment.this.getActivity(), 
R.layout.layout_grid_imageview, mAppend, imgURLs);
    gridView.setAdapter(adapter);

    if (imgURLs.isEmpty()) {
        // Array list is empty, handle accordingly
    } else {
        //set the first image to be displayed when the activity fragment view is inflated
        try {
            setImage(imgURLs.get(0), galleryImage, mAppend);
            mSelectedImage = imgURLs.get(0);
        } catch (ArrayIndexOutOfBoundsException e) {
            Log.e(TAG, "setupGridView: ArrayIndexOutOfBoundsException: " + e.getMessage());
        }

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d(TAG, "onItemClick: Selected an image: " + imgURLs.get(position));

                setImage(imgURLs.get(position), galleryImage, mAppend);
                mSelectedImage = imgURLs.get(position);
            }
        });
    }
}

private void setImage(String imgURL, ImageView image, String append){
    Log.d(TAG, "setImage: Setting image");

    ImageLoader imageLoader = ImageLoader.getInstance();

    imageLoader.displayImage(append + imgURL, image, new ImageLoadingListener() {
        @Override
        public void onLoadingStarted(String imageUri, View view) {
            mProgressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            mProgressBar.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            mProgressBar.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onLoadingCancelled(String imageUri, View view) {
            mProgressBar.setVisibility(View.INVISIBLE);
        }
    });
}
}

编辑2 !!

public static void setImage(String imgURL, ImageView image, final ProgressBar mProgressBar, String append){

    FirebaseStorage storage = FirebaseStorage.getInstance();
    StorageReference storageRef = storage.getReferenceFromUrl("Url to storage");


 storageRef.child("users/me/profile.png").getDownloadUrl().
addOnSuccessListener(new OnSuccessListener<Uri>() {
        @Override
        public void onSuccess(Uri uri) {
            // HERE will be your proper URI to load by Universal Image Loader
            Log.e("uri1", uri.toString());
        }
     }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle any errors
        }
    });

1 个答案:

答案 0 :(得分:1)

库Universalimageloader对于要加载的图像有问题,因为您为图像提供了错误的URL。

文档中有指定的URI,您需要使用URI来加载图像。在加载String imgUrl之前先打印它,然后告诉我那里有什么?

来自library documentation

的可接受的URI示例
"file:///mnt/sdcard/image.png" // from SD card
"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content://media/external/images/media/13" // from content provider
"content://media/external/video/media/13" // from content provider (video thumbnail)
"assets://image.png" // from assets
"drawable://" + R.drawable.img // from drawables (non-9patch images)

所以...您想用以下网址显示照片:

“文件:/” +“ gs://hash-a921f.appspot.com/photos/users/YqwhCwkBm8WM6Vd3PjcHHPl2suZ2/profile_photo”

这是错误的URI。您必须从firebase检索“ profile_photo”的真实URI。

我认为您可以通过以下链接进行操作:https://firebase.google.com/docs/storage/android/download-files#download_data_via_url

您必须在执行setImage()方法之前执行它。

storageRef.child("users/me/profile.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                // HERE will be your proper URI to load by Universal Image Loader
                // Now you can use setImage() method, use uri.toString() as imageUrl. Remove "append" variable in setImage() method.
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception exception) {
                // Handle any errors
            }
        });