Android Question File Provider

Discussion in 'Android Questions' started by BarryW, Jul 18, 2019.

  1. BarryW

    BarryW Active Member Licensed User

    when adding this

    Code:
    #Extends: android.support.v7.app.AppCompatActivity
    then using this code from Erel

    Code:
    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

    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Where is the full error message and the relevant code?
     
  3. BarryW

    BarryW Active Member Licensed User

    Here is my manifest

    Code:
    '
    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

    Code:
    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
     
  4. BarryW

    BarryW Active Member Licensed User

  5. Erel

    Erel Administrator Staff Member Licensed User

  6. BarryW

    BarryW Active Member Licensed User

    Here is the error after

    Code:
    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
     
  7. BarryW

    BarryW Active Member Licensed User

    I cannot upload the whole project for the some security reasons. Maybe i can just post here some parts of the code.
     
  8. BarryW

    BarryW Active Member Licensed User

    Here is the header of Main Activity

    Code:
    #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
     
  9. BarryW

    BarryW Active Member Licensed User

    Here is the list of libraries i used

    Capture.PNG
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Create a small project with the manifest code and AppCompat and upload it.
     
  11. BarryW

    BarryW Active Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice