非法参数异常:无法找到配置的根

没有人

我尝试按照本指南共享从 glide 加载到 imageview 中的图像,它给了我一个非法参数异常。我已经在下面发布了代码和堆栈跟踪,它

主要活动.xml

public class MainActivity extends AppCompatActivity {

    private EditText editText;
    private ShareActionProvider myShareActionProvider;
    //private Bitmap bitmap;
    private Uri uri;
    private Intent shareIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final ImageView imageView = (ImageView) findViewById(R.id.imageView);

        String hi = "http://37n98a43dqtb4bua9n28nidp.wpengine.netdna-cdn.com/wp-content/uploads/2016/09/MyFriendPikachu.jpg";

        Glide
                .with(this)
                .load(hi)
                .listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        prepareShareIntent(((GlideBitmapDrawable) resource).getBitmap());
                        attachShareIntentAction();
                        return false;
                    }
                })
                .placeholder(R.drawable.ic_action_name)
                .error(R.drawable.ic_img_error)
                .centerCrop()
                .into(imageView);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.img_menu, menu);

        MenuItem item = menu.findItem(R.id.action_share);

        myShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
        attachShareIntentAction();

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();

        return super.onOptionsItemSelected(item);


    }

    public void prepareShareIntent(Bitmap drawableImage) {

        Uri bmpUri = getBitmapFromDrawable(drawableImage);

        shareIntent = new Intent();

        shareIntent.setAction(Intent.ACTION_SEND);

        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);

        shareIntent.setType("image/*");

    }


    public void attachShareIntentAction() {

        if (myShareActionProvider != null && shareIntent != null)

            myShareActionProvider.setShareIntent(shareIntent);

    }


    public Uri getBitmapFromDrawable(Bitmap bmp) {


        Uri bmpUri = null;

        try {

            //also tried getExternalDir(Environment.DIRECTORY_PICTURES)
            File file = new File(Environment.getExternalStorageDirectory(), "images" + System.currentTimeMillis() + ".png");

            FileOutputStream out = new FileOutputStream(file);

            bmp.compress(Bitmap.CompressFormat.PNG, 90, out);

            out.close();


            bmpUri = FileProvider.getUriForFile(MainActivity.this, "com.example.imnobody.sampleprojectnetwork.fileprovider", file);  // use this version for API >= 24

            // **Note:** For API < 24, you may use bmpUri = Uri.fromFile(file);

        } catch (IOException e) {

            e.printStackTrace();

        }

        return bmpUri;

    }

}

Androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.imnobody.sampleprojectnetwork">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />





    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider

            android:name="android.support.v4.content.FileProvider"

            android:authorities="com.example.imnobody.sampleprojectnetwork.fileprovider"

            android:exported="false"

            android:grantUriPermissions="true">

            <meta-data


                android:name="android.support.FILE_PROVIDER_PATHS"

                android:resource="@xml/fileprovider" />

        </provider>
    </application>

</manifest>

文件提供者.xml

<?xml version="1.0" encoding="utf-8"?>

<paths>

    <external-file-path

        name="images"

        path="Pictures"  />

</paths>

堆栈跟踪

java.lang.IllegalArgumentException:无法在 android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711) at android.support.v4.content 中找到包含 /storage/sdcard0/images1502651207040.png 的配置根目录.FileProvider.getUriForFile(FileProvider.java:400) at com.example.imnobody.sampleprojectnetwork.MainActivity.getBitmapFromDrawable(MainActivity.java:134) at com.example.imnobody.sampleprojectnetwork.MainActivity.prepareShareIntent(MainActivity.java:95) at com.example.imnobody.sampleprojectnetwork.MainActivity$1.onResourceReady(MainActivity.java:59) 在 com.example.imnobody.sampleprojectnetwork.MainActivity$1.onResourceReady(MainActivity.java:51) 在 com.bumptech.glide.request.GenericRequest。 onResourceReady(GenericRequest.java:522) 在 com.bumptech.glide.request.GenericRequest。onResourceReady(GenericRequest.java:507) at com.bumptech.glide.load.engine.EngineJob.handleResultOnMainThread(EngineJob.java:158) at com.bumptech.glide.load.engine.EngineJob.access$100(EngineJob.java:22) ) 在 com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(EngineJob.java:202) 在 android.os.Handler.dispatchMessage(Handler.java:106) 在 android.os.Looper.loop(Looper. java:193) 在 android.app.ActivityThread.main(ActivityThread.java:5292) 在 java.lang.reflect.Method.invokeNative(Native Method) 在 java.lang.reflect.Method.invoke(Method.java:515)在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 在 dalvik.system.NativeSglide.load.engine.EngineJob.access$100(EngineJob.java:22) 在 com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(EngineJob.java:202) 在 android.os.Handler.dispatchMessage(Handler .java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5292) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) at com.android.internal.os.ZygoteInit.main( ZygoteInit.java:640) 在 dalvik.system.NativeSglide.load.engine.EngineJob.access$100(EngineJob.java:22) 在 com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(EngineJob.java:202) 在 android.os.Handler.dispatchMessage(Handler .java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5292) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) at com.android.internal.os.ZygoteInit.main( ZygoteInit.java:640) 在 dalvik.system.NativeSActivityThread.main(ActivityThread.java:5292) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os。 ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) at dalvik.system.NativeSActivityThread.main(ActivityThread.java:5292) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os。 ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) at dalvik.system.NativeS

共享软件

首先,在您的元数据中,更改external-file-pathexternal-files-path,添加缺少的s.

其次,/storage/sdcard0/images1502651207040.png将不匹配修复的元数据。元数据期望您使用getExternalFilesDir(),特别是Pictures那里目录。你的路径不像那样。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

FileProvider“无法找到已配置的根”异常

来自分类Dev

FileProvider“无法找到已配置的根”异常

来自分类Dev

MapperScannerConfigurer 配置导致非法参数异常

来自分类Dev

非法参数异常未找到搜索字段的映射

来自分类Dev

Android:FileProvider“无法找到配置的根”

来自分类Dev

引发非法参数异常

来自分类Dev

关于java非法参数异常

来自分类Dev

Grails非法参数约束异常

来自分类Dev

Kotlin KCallable 非法参数异常

来自分类Dev

Apache骆驼:绑定非法参数异常

来自分类Dev

非法参数异常:n必须为正

来自分类Dev

Java中的URL非法参数异常

来自分类Dev

设计问题。抛出非法参数的检查异常

来自分类Dev

正则表达式非法参数异常

来自分类Dev

格式化Calendar对象时非法的参数异常

来自分类Dev

泽西岛REST日期@XmlAttribute导致非法参数异常

来自分类Dev

生成随机数时获取非法参数异常

来自分类Dev

格式化Calendar对象时非法的参数异常

来自分类Dev

Android上的Google Cloud Endpoint非法参数异常

来自分类Dev

在Java中读取XML文件时出现非法参数异常

来自分类Dev

尝试使用映射创建索引时获取非法参数异常

来自分类Dev

Android Recycler 视图中 Picasso 的非法参数异常

来自分类Dev

文件提供程序异常:无法找到包含以下内容的已配置根目录

来自分类Dev

javaFX Alert抛出无法捕获的非法状态异常?

来自分类Dev

非法状态异常。由于工具栏,活动无法启动

来自分类Dev

加密的ArchLinux:无法找到根设备

来自分类Dev

Gradle错误:无法在配置容器上为参数[受害者]找到方法maybeCreate()

来自分类Dev

在Eclipse中使用Jetty时获取非法参数异常/运行时异常

来自分类Dev

简单游标适配器抛出异常非法参数异常?

Related 相关文章

  1. 1

    FileProvider“无法找到已配置的根”异常

  2. 2

    FileProvider“无法找到已配置的根”异常

  3. 3

    MapperScannerConfigurer 配置导致非法参数异常

  4. 4

    非法参数异常未找到搜索字段的映射

  5. 5

    Android:FileProvider“无法找到配置的根”

  6. 6

    引发非法参数异常

  7. 7

    关于java非法参数异常

  8. 8

    Grails非法参数约束异常

  9. 9

    Kotlin KCallable 非法参数异常

  10. 10

    Apache骆驼:绑定非法参数异常

  11. 11

    非法参数异常:n必须为正

  12. 12

    Java中的URL非法参数异常

  13. 13

    设计问题。抛出非法参数的检查异常

  14. 14

    正则表达式非法参数异常

  15. 15

    格式化Calendar对象时非法的参数异常

  16. 16

    泽西岛REST日期@XmlAttribute导致非法参数异常

  17. 17

    生成随机数时获取非法参数异常

  18. 18

    格式化Calendar对象时非法的参数异常

  19. 19

    Android上的Google Cloud Endpoint非法参数异常

  20. 20

    在Java中读取XML文件时出现非法参数异常

  21. 21

    尝试使用映射创建索引时获取非法参数异常

  22. 22

    Android Recycler 视图中 Picasso 的非法参数异常

  23. 23

    文件提供程序异常:无法找到包含以下内容的已配置根目录

  24. 24

    javaFX Alert抛出无法捕获的非法状态异常?

  25. 25

    非法状态异常。由于工具栏,活动无法启动

  26. 26

    加密的ArchLinux:无法找到根设备

  27. 27

    Gradle错误:无法在配置容器上为参数[受害者]找到方法maybeCreate()

  28. 28

    在Eclipse中使用Jetty时获取非法参数异常/运行时异常

  29. 29

    简单游标适配器抛出异常非法参数异常?

热门标签

归档