java .lang.RuntimeException: невозможно запустить действие ComponentInfo {com.camera.robe / com.browse.simply.chi c .robe.EditorActivity}: - PullRequest
0 голосов
/ 27 января 2020

2020-01-27 04: 33: 23.779 5931-5931 / com.camera.robe E / AndroidRuntime: ИСКЛЮЧИТЕЛЬНОЕ ИСКЛЮЧЕНИЕ: основной процесс: com.camera.robe, PID: 5931 java .lang. RuntimeException: невозможно запустить действие ComponentInfo {com.camera.robe / com.browse.simply.chi c .robe.EditorActivity}: java .lang.NullPointerException: попытка вызвать виртуальный метод 'android. net .Uri android. net .Uri.normalizeScheme () 'для нулевой ссылки на объект

я реле, борюсь с этой ошибкой, может кто-нибудь помочь мне, пожалуйста?

Мое приложение запустилось нормально, но затем упало, и я получил:

какое-нибудь решение для этого? с приложением все в порядке, но когда я выбираю фотографию из галереи и нажимаю, чтобы импортировать ее для редактирования, приложение перестает работать с этой ошибкой сверху.

EditorActivity. java

package com.browse.simply.chic.robe;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.adobe.creativesdk.aviary.AdobeImageIntent;
import com.adobe.creativesdk.aviary.internal.headless.utils.MegaPixels;
import com.browse.simply.chic.Ads.AdmobAds;
import com.browse.simply.chic.Ads.FacebookAds;
import com.browse.simply.chic.Constants;
import com.browse.simply.chic.R;
import com.browse.simply.chic.Utils;
import androidx.annotation.NonNull;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class EditorActivity extends AppCompatActivity {

    private String uriPath;
    /* 1) Add a member variable for our Image View */
    Uri editedImageUri;

    protected Uri mMediaUri;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_editor);
        ButterKnife.bind(this);


        AdmobAds.loadNative(this, R.id.adViewnativeResult);
        AdmobAds.fullAd(this, getString(R.string.result_full));
       // FacebookAds.full(this, getString(R.string.result_full_fb));

        try {
            mMediaUri = getIntent().getData();
        } catch (Exception e) {
            e.printStackTrace();
        }
      Uri saved = Utils.getOutPutMediaFileUri(this, Constants.MEDIA_TYPE_IMAGE, getString(R.string.app_name));

        assert saved != null;
        Intent imageEditorIntent = new AdobeImageIntent.Builder(this)
                .setData(mMediaUri)
                .withOutput(saved)
                .withOutputFormat(Bitmap.CompressFormat.JPEG) // output format
                .withOutputQuality(90) // output quality
                .withOutputSize(MegaPixels.Mp15)
             //   .withVibrationEnabled(vibration)
                .build();

    /* 3) Start the Image Editor with request code 1 */
        startActivityForResult(imageEditorIntent, 1);
    }



    /* 3) Handle the results */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {

                /* 4) Make a case for the request code we passed to startActivityForResult() */
                case 1:

                    /* 5) Show the image! */
                    editedImageUri = data.getParcelableExtra(AdobeImageIntent.EXTRA_OUTPUT_URI);
                    Toast.makeText(this, "Saved to /sdcard/" + getString(R.string.app_name), Toast.LENGTH_SHORT).show();

                    break;
            }
        } else {
            Intent intent = new Intent(this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            AdmobAds.show(this);
        }
    }

    @OnClick(R.id.sharepic)
    public void shareImage() {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_STREAM, editedImageUri);
        startActivity(Intent.createChooser(intent, "Share with?"));
    }




    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        AdmobAds.show(this);
    }

}

MainActivity. java

package com.browse.simply.chic.robe;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.browse.simply.chic.Ads.AdmobAds;
import com.browse.simply.chic.Ads.FacebookAds;
import com.browse.simply.chic.BuildConfig;
import com.browse.simply.chic.Constants;
import com.browse.simply.chic.R;
import com.cocosw.bottomsheet.BottomSheet;
import com.mlsdev.rximagepicker.RxImagePicker;
import com.mlsdev.rximagepicker.Sources;

import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.functions.Consumer;


public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);


        AdmobAds.loadNative(this, R.id.adViewnativemain);
        AdmobAds.fullAd(this, getString(R.string.main_full));
        FacebookAds.full(this, getString(R.string.main_full_fb));



        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        String action = intent.getAction();
        Uri uri2 = intent.getData();
        if (Intent.ACTION_SEND.equals(action)) {
            assert extras != null;
            if (extras.containsKey(Intent.EXTRA_STREAM)) {
                Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
                Intent recipientsIntent = new Intent(MainActivity.this, EditorActivity.class);
                recipientsIntent.setData(uri);
                startActivity(recipientsIntent);
            }
        } else if (Intent.ACTION_VIEW.equals(action)) {
            Intent recipientsIntent = new Intent(MainActivity.this, EditorActivity.class);
            recipientsIntent.setData(uri2);
            startActivity(recipientsIntent);

        }
    }

    public static boolean MyStartActivity(Intent aIntent, Context c) {
        try {
            c.startActivity(aIntent);
            return true;
        } catch (ActivityNotFoundException e) {
            return false;
        }
    }

    @OnClick(R.id.camera)
    public void camera(){
        if (Build.VERSION.SDK_INT >= 23) {
            if (checkSelfPermission(Manifest.permission.CAMERA)
                    != PackageManager.PERMISSION_GRANTED) {

                requestPermissions(new String[]{Manifest.permission.CAMERA},
                        Constants.CAMERA_PERMISSION);
            }else {
                //permission is automatically granted on sdk<23 upon installation
                openCamera();
            }
        } else {
            //permission is automatically granted on sdk<23 upon installation
            openCamera();
        }
}
    @SuppressLint("CheckResult")
    private void openCamera() {
        //camera

        RxImagePicker.with(this).requestImage(Sources.CAMERA).subscribe(new Consumer<Uri>() {
            @Override
            public void accept(@NonNull Uri uri) throws Exception {
                Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                mediaScanIntent.setData(uri);
                sendBroadcast(mediaScanIntent);
                Intent recipientsIntent = new Intent(MainActivity.this, EditorActivity.class);
                recipientsIntent.setData(uri);
                startActivity(recipientsIntent);
            }
        });

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {
            //gallery
            case Constants.REQUEST_WRITE_STORAGE_PERMISSION:
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    launchGallery();
                } else {
                    Toast.makeText(MainActivity.this, "You need to allow Storage permission first", Toast.LENGTH_SHORT).show();
                }
                break;



            //camera
            case Constants.CAMERA_PERMISSION:
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    openCamera();
                } else {
                    Toast.makeText(MainActivity.this, "You need to allow Camera permission first", Toast.LENGTH_SHORT).show();
                }
                break;
            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK) {
            switch (requestCode){
                 case Constants.SELECT_PHOTO:
                    final Uri imageUri = data.getData();
                    Intent recipientsIntent2 = new Intent(MainActivity.this, EditorActivity.class);
                    recipientsIntent2.setData(imageUri);
                    startActivity(recipientsIntent2);
                    break;
            }

        }


    }

    @OnClick(R.id.more)
    public void more(){
            openQuickMenuPro();

    }



    public void rate() {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("market://details?id=" + BuildConfig.APPLICATION_ID));
        if (!MyStartActivity(intent, MainActivity.this)) {
            intent.setData(Uri.parse(BuildConfig.APPLICATION_ID));
            if (!MyStartActivity(intent, MainActivity.this)) {
                Toast.makeText(MainActivity.this,
                        "Please download Google play store.",
                        Toast.LENGTH_SHORT).show();
            }
        }

    }
    @OnClick(R.id.gallery)
    public void gallery() {
        if (Build.VERSION.SDK_INT >= 23) {
            if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        Constants.REQUEST_WRITE_STORAGE_PERMISSION);

            }else {
                launchGallery();
            }
        }else {
            launchGallery();
        }
    }
    public void launchGallery() {
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, Constants.SELECT_PHOTO);
    }



    public void share() {
        Intent shareIntent =
                new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        //add a subject
        shareIntent.putExtra(Intent.EXTRA_SUBJECT,
                "Hey download this cool photo editor i found on Google play.");
        String shareMessage = getString(R.string.app_name) + " is a cool photo editing app for android check this out." +
                " \n https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID;
        //add the message
        shareIntent.putExtra(Intent.EXTRA_TEXT,
                shareMessage);
        //start the chooser for sharing
        startActivity(Intent.createChooser(shareIntent,
                "Share with.."));
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        AdmobAds.show(this);
        finish();
    }



    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        AdmobAds.show(this);
        finish();
    }

    private void openQuickMenuPro() {
        new BottomSheet.Builder(this).sheet(R.menu.main_pro).listener(new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                    case R.id.rate:
                        rate();
                        break;
                    case R.id.share:
                        share();
                        break;
                    case R.id.moreApp:
                        moreApp(MainActivity.this);
                        break;

                }
            }
        }).show();

    }



    public void moreApp(Context c) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("market://search?q=pub:"+ getString(R.string.dev_name)));
        if (!MyStartActivity(intent, c)) {
            intent.setData(Uri.parse("http://play.google.com/store/search?q=pub:"+ getString(R.string.dev_name)));
            if (!MyStartActivity(intent, c)) {
                Toast.makeText(MainActivity.this,
                        "Please download Google play store.",
                        Toast.LENGTH_SHORT).show();
            }
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...