I'm new to the Xamarin. I'm trying to create my own view in an Android aplication, but it's throwing an ClassNotFoundException on constructor. I was searching for similar issues but I haven't found similar one (only here is something that I think may be quite similar, but it isn't solved in fact — answers tell to edit java file, but it's not possible when working in Xamarin). Here's my code of MainActivity.cs:
using Android.App;
using Android.OS;
namespace App5
{
[Activity(Label = "App5", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
View1 view = new View1(this);
SetContentView(view);
//SetContentView(Resource.Layout.Main);
}
}
}
and View1.cs:
using Android.Content;
using Android.Views;
namespace App5
{
public class View1 : View
{
public View1(Context context)
: base(context)
{
}
}
}
and this is description of the exception:
Java.Lang.ClassNotFoundException: Didn't find class "md593b8d625023f6802361dd1b8a6546be5.View1" on path: DexPathList[[zip file "/data/app/App5.App5-1/base.apk"],nativeLibraryDirectories=[/data/app/App5.App5-1/lib/arm64, /system/fake-libs64, /data/app/App5.App5-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
It's very strange that when I comment the inheriting from View and inheriting the constructor, and of course SetContentView to a layout in the resource, system “can find this class” and the app doesn't crash.
I'm using VisualStudio 2015 and have the latest stable version of Xamarin installed.
Try to delete bin and obj and rebuild project. This start happend to me after last visual studio update. Another think is kill msbuilld proceses too.
来源:https://stackoverflow.com/questions/47812966/xamarin-custom-view-classnotfoundexception