Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

My Xamarin Android app crashes on launch if I put anything in the Resources/xml folder

$
0
0

I've run across a few vague mentions of this issue across the internet, but nothing very clear.

I'm trying to implement Android Preferences for my Xamarin Android project. Normally, that means creating a preferences XML file, loading it from a resource, and inflating it into an Android Fragment or Activity. However, If I add even an empty XML file to my project's "Resources/xml" file, the app immediately crashes on startup.

Pertinent lines of the crash log:

07-27 17:00:58.554 E/AndroidRuntime(17562): FATAL EXCEPTION: main
07-27 17:00:58.554 E/AndroidRuntime(17562): Process: com.mycompany.MyApp, PID: 17562
07-27 17:00:58.554 E/AndroidRuntime(17562): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.MyApp/md5f066c239292502fb4e67fb5be45f54ab.SplashActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.ContentFrameLayout.setId(int)' on a null object reference
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.app.ActivityThread.access$900(ActivityThread.java:157)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.os.Handler.dispatchMessage(Handler.java:102)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.os.Looper.loop(Looper.java:148)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.app.ActivityThread.main(ActivityThread.java:5527)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at java.lang.reflect.Method.invoke(Native Method)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
07-27 17:00:58.554 E/AndroidRuntime(17562): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.ContentFrameLayout.setId(int)' on a null object reference
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:487)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:309)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.support.v7.app.AppCompatDelegateImplV7.onPostCreate(AppCompatDelegateImplV7.java:166)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.support.v7.app.AppCompatActivity.onPostCreate(AppCompatActivity.java:94)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1189)
07-27 17:00:58.554 E/AndroidRuntime(17562):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
07-27 17:00:58.554 E/AndroidRuntime(17562):     ... 9 more
07-27 17:01:02.037 I/Process (17562): Sending signal. PID: 17562 SIG: 9

Here's my SplashActivity:

[Activity(Theme = "@style/SplashTheme", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
        base.OnCreate(savedInstanceState, persistentState);
    }

    protected override void OnResume()
    {
        base.OnResume();
        Task startupWork = new Task(() => { Startup(); });
        startupWork.Start();
    }

    protected override void OnPause()
    {
        base.OnPause();
        Finish();
        OverridePendingTransition(0, Resource.Animation.splash_fade_out);
    }

    async void Startup()
    {
        StartActivity(new Intent(Application.Context, typeof(MainActivity)));
    }
}

Here's my XML file, although literally any file, including a well-formed PreferenceScreen file will also make it crash:

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

Is there a way I can get around this bug? Or is there something I'm doing wrong on my end?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>