Android Question File Provider

BarryW

Active Member
Licensed User
Longtime User
when adding this

B4X:
#Extends: android.support.v7.app.AppCompatActivity

then using this code from Erel

B4X:
AddManifestText(<uses-permission
   android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="18" />
)

AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)

gives and error

B4X:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.main}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setId(int)' on a null object reference
 

BarryW

Active Member
Licensed User
Longtime User
Here is my manifest

B4X:
'
This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
SetApplicationAttribute(android:hardwareAccelerated, "true")
SetApplicationAttribute(android:theme, "@style/MyAppTheme")

AddPermission("android.permission.ACCESS_FINE_LOCATION")
AddPermission("android.permission.ACCESS_COARSE_LOCATION")
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.READ_EXTERNAL_STORAGE")

CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="@style/Theme.AppCompat.Light">
        <item name="colorPrimary">#F9A11B</item>
        <item name="colorPrimaryDark">#EA881D</item>
        <item name="colorAccent">#AA8800</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>
</resources>
)
AddManifestText(<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />
)
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)
AddPermission(android.permission.REQUEST_INSTALL_PACKAGES)

Here is the application error log

B4X:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.main}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setId(int)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2841)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2919)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:171)
    at android.app.ActivityThread.main(ActivityThread.java:6656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setId(int)' on a null object reference
    at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:703)
    at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:457)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:145)
    at com.delivery.felco.main.onCreate(main.java:61)
    at android.app.Activity.performCreate(Activity.java:7074)
    at android.app.Activity.performCreate(Activity.java:7065)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2794)
    ... 9 more
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
FileProvider is not related to this error.

AppCompat example is available here: https://www.b4x.com/android/forum/threads/appcompat-with-toolbar-minimal-example.79896/#content

Does it work if you remove these two lines:
B4X:
<item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
?

Can you upload the project?

Here is the error after

B4X:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.delivery.felco/com.my.app.main}: java.lang.NullPointerException: Attempt to invoke interface method 'void android.support.v7.widget.DecorContentParent.setWindowCallback(android.view.Window$Callback)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2841)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2919)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:171)
    at android.app.ActivityThread.main(ActivityThread.java:6656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void android.support.v7.widget.DecorContentParent.setWindowCallback(android.view.Window$Callback)' on a null object reference
    at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:611)
    at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:457)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:145)
    at com.delivery.felco.main.onCreate(main.java:61)
    at android.app.Activity.performCreate(Activity.java:7074)
    at android.app.Activity.performCreate(Activity.java:7065)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2794)
    ... 9 more
 
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
I cannot upload the whole project for the some security reasons. Maybe i can just post here some parts of the code.
 
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
Here is the header of Main Activity

B4X:
#Region  Project Attributes
    #ApplicationLabel: My App
    #VersionCode: 1
    #VersionName: 1.9.0
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
    #IgnoreWarnings: 32
    #BridgeLogger: True
#End Region

#Extends: android.support.v7.app.AppCompatActivity
#AdditionalRes: ../Res
#AdditionalRes: ../res.SweetAlertDialog
#AdditionalRes: ../res.MaterialIshProgress
#AdditionalJar: com.android.support:support-v4
#AdditionalJar: com.google.android.gms:play-services-location

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region
 
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
Here is the list of libraries i used

Capture.PNG
 
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
Hi Erel thanks for you help. I already fix it, but i not sure what happen. For the benefits of the others for this post, I tried to comment #AdditionalResources one by one then run it. Then I remove all the codes from Activity Create and it runs successfully. After that, I tried to uncomment the codes from #AdditionalResources then run it. Lastly I bring back the codes from the Activity Create and successfully it runs. Maybe it its IDE's bug but I not sure. Once again thank you for your fully support.
 
Upvote 0
Top