ClassNotFoundException Didn't Find Class SplashActivity on Path
ClassNotFoundException: Didn’t Find Class SplashActivity
on Path
A Short Blog Post
Another day, another error — this time with the splash screen on Xamarin.Forms. Can’t wait to switch to MAUI! Though, I’m sure I’ll run into errors there as well.
The error I encountered was:
Java.Lang.ClassNotFoundException: Didn't find class "com.companyname.myApp.SplashActivity" on path
What Went Wrong?
This error had me stumped for a while. After going on just three hours of sleep, I made a simple mistake with the naming in my Android Xamarin.Forms app.
Here’s how the manifest was declared:
Manifest Declaration:
<!-- SplashActivity declaration -->
<activity android:name=".SplashActivity"
android:theme="@style/SplashTheme"
android:exported="true"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Activity Class Declaration:
[Activity(Theme = "@style/SplashTheme",
Name = "myApp.SplashActivity",
MainLauncher = true,
NoHistory = true)]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
OxyPlot.Xamarin.Forms.Platform.Android.PlotViewRenderer.Init();
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}
Can You Spot the Issue?
The problem lies in the name. In the manifest, the activity is declared as .SplashActivity
, but in the class attribute, it’s declared as "myApp.SplashActivity"
. This mismatch caused the ClassNotFoundException
.
Key Things to Check if You Encounter this Error:
- Check the Generated Java Files: Is the class present in the compiled output?
- Ensure the Name Matches: Does the
Name
attribute in the[Activity]
declaration match what is declared in the manifest? - Check for Multiple Declarations: Do you have duplicate or conflicting declarations in the manifest or debug manifest?
- Verify Namespace and Path: Make sure the namespace and class names match across your code and manifest.
Final Thoughts:
It’s an easy mistake to make, but verifying the namespace and activity names in both the manifest and class declarations can save you hours of troubleshooting. I hope this helps you avoid the same issue!
Comments
Last modified on 2024-09-16