Android Question FileProvider Error

james_sgp

Active Member
Licensed User
Longtime User
Hi, I`m trying to use FileProvider with my app....the demo works perfectly. But when I add it into my own app, I am getting this error when the app runs. Appreciate if someone can point me to what I`ve missed?

Thanks, James

java.lang.RuntimeException: Unable to start activity ComponentInfo{RAID.FirstAid/RAID.FirstAid.main}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.widget.ContentFrameLayout.setId(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3092)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6986)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.widget.ContentFrameLayout.setId(int)' on a null object reference
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:703)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:457)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:145)
at RAID.FirstAid.main.onCreate(main.java:63)
at android.app.Activity.performCreate(Activity.java:7326)
at android.app.Activity.performCreate(Activity.java:7317)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
... 11 more
 

james_sgp

Active Member
Licensed User
Longtime User
Tried that, I found that when I add the following into the Manifest it causes the error. Without it the app runs but obviously FileProvider doesn`t....
B4X:
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" />
)

I`m running B4A 9.50, and it is installing on a Galaxy S9+ with Android 9, with minSDK = 16 and targetSDK=29
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
jahswani, ok your comment made me think so I re-booted PC and phone; now it runs ok. So guessing there was something hanging around in memory.
Thanks
 
Upvote 0
Top