question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] Unhandled exception at application startup

See original GitHub issue

Bug

Version Number of Plugin: 2.6.2 Compile using Android version: Use Latest Platform (Android 7.1 (Nougat)) Target Android version: Use Compile using SDK version Device Tested On: Moto G4, Android 7.0 (build NPJ25.93-14) Simulator Tested On: None

Expected Behavior

The application should start properly without errors when the plugin is installed and set up as per the instructions.

Actual Behavior

Upon starting the application, an unhandled Exception is raised when calling base.OnCreate(bundle) within MainActivity.OnCreate override:

Java.Lang.NullPointerException: Attempt to invoke virtual method ‘void android.view.View.setId(int)’ on a null object reference

Steps to reproduce the Behavior

  • I added the plugin to a Xamarin.Forms (PCL) application along with the corresponding Android device application.
  • I updated the AndroidManifest.xml as per the “readme.txt”
  • I added the xml folder to the Resources folder
  • I added the file file_paths.xml to the xml folder
  • I ran the application on the device

I am also using Prism.Forms with Unity within the application if that makes any difference, though the application does not get as far as creating the App class.

MainActivity.OnCreate()

protected override void OnCreate(Android.OS.Bundle bundle) {

	TabLayoutResource = Resource.Layout.Tabbar;
	ToolbarResource = Resource.Layout.Toolbar;

	base.SetTheme(Resource.Style.MainTheme);

	base.OnCreate(bundle);
	//base.SetStatusBarColor(Color.Orange);

	global::Xamarin.Forms.Forms.Init(this, bundle);
	Acr.UserDialogs.UserDialogs.Init(this);
	LoadApplication(new App(new AndroidInitializer()));
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.mydomain.myapp">
	<application android:label="My application" android:icon="@drawable/icon">
		<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.mydomain.myapp.fileprovider" android:exported="false" android:grantUriPermissions="true">
			<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
		</provider>
	</application>
	<uses-feature android:name="android.hardware.camera" android:required="true" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
	<uses-sdk android:minSdkVersion="15" />
</manifest>

file_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
	<external-path name="my_images" path="Android/data/com.mydomain.myapp/files/Pictures" />
	<external-path name="my_movies" path="Android/data/com.mydomain.myapp/files/Movies" />
</paths>

I have found an article in the Xamarin forums indicating that the error is caused by the presence of any file within the Resources/xml folder. If I exclude this folder from the project then the application starts without issue leading me to believe that this is in fact the cause of the problem but there has been no reply within that forum post as to any workaround.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

40reactions
pbielinskicommented, Apr 28, 2017

delete bin and obj folders on Android project and rebuild it

2reactions
angeliericommented, Nov 14, 2018

I think it’s mandatory as a xamarin developer to have a ‘nuke’ script which deletes all the solutions bin and obj folders 😃

I recomend https://github.com/madskristensen/CloseAllTabs

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle Android exceptions and avoid application ...
You can handle exceptions using: try/catch or runCatching; In Android, you can handle all unhandled exceptions using: Thread.
Read more >
Android: Handle critical exception at startup
When I'm using the UncaughtExceptionHandler, the exceptions end up being caught and logged, but the app doesn't shut down. Instead, in the logs ......
Read more >
Crashes | App quality
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >
Handling Uncaught-Exceptions in Android
Tracking down all exceptions is the crucial part of the development. ... In this article I am going to show you how you...
Read more >
c# - How to treat unhandled exceptions? (Terminate the ...
Start with analysing the following points: ... After an unhandled exception your application is in an unknown state.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found