照着第二版第一行代码敲的调用摄像头部分,因为编译器提示没有android.support.v4.content.fileprovider。就自己导了一个名字带provider的

android.provider.DocumentsProvider

报错信息如下:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.cameraalbumtest, PID: 13140
    java.lang.RuntimeException: Unable to get provider android.provider.DocumentsProvider: java.lang.InstantiationException: java.lang.Class<android.provider.DocumentsProvider> cannot be instantiated
        at android.app.ActivityThread.installProvider(ActivityThread.java:7400)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6917)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6823)
        at android.app.ActivityThread.access$1400(ActivityThread.java:255)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2089)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:230)
        at android.app.ActivityThread.main(ActivityThread.java:7768)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:508)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
     Caused by: java.lang.InstantiationException: java.lang.Class<android.provider.DocumentsProvider> cannot be instantiated
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)
        at androidx.core.app.CoreComponentFactory.instantiateProvider(CoreComponentFactory.java:60)
        at android.app.ActivityThread.installProvider(ActivityThread.java:7384)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6917) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6823) 
        at android.app.ActivityThread.access$1400(ActivityThread.java:255) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2089) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:230) 
        at android.app.ActivityThread.main(ActivityThread.java:7768) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:508) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) 
<provider
            android:authorities="${applicationId}.fileprovider"
            android:name="androidx.core.content.FileProvider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"/>
        </provider>

可以

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐