我有使用Xamarin Forms构建的android应用程序。为了使用移动设备的相机,我安装了Xam.Plugin.Media插件,并完全遵循this video的说明。
这是我的代码:
public async void TakePhotoAsAttachment(object sender, EventArgs e)
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", ":( No camera available.", "OK");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "Sample",
Name = "test.jpg"
});
if (file == null)
return;
await DisplayAlert("File Location", file.Path, "OK");
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
return stream;
});
}
但是,执行此代码时:
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "Sample",
Name = "test.jpg"
});
我收到此错误:
{抛出java.lang.ClassNotFoundException: md55b01af31820394fbfb172542d1258596.MediaPickerActivity ---> Java.Lang.ClassNotFoundException:没找到类 " md55b01af31820394fbfb172542d1258596.MediaPickerActivity"在路径上: DexPathList [[zip文件 " /data/app/com.companyname.EClinicForDoctor-1/base.apk"],nativeLibraryDirectories = [/数据/应用/ com.companyname.EClinicForDoctor-1 / LIB /臂, /data/app/com.companyname.EClinicForDoctor-1/base.apk!/lib/armeabi-v7a, / vendor / lib,/ system / lib]] ---内部异常堆栈跟踪的结束 ---在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000c]中< 657aa8fea4454dc898a9e5f379c58734>:0 at Java.Interop.JniEnvironment + StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference类型,Java.Interop.JniMethodInfo 方法,Java.Interop.JniArgumentValue * args)[0x00069] in < 54816278eed9488eb28d3597fecd78f8>:0 at Android.Runtime.JNIEnv.CallStaticObjectMethod(System.IntPtr jclass, System.IntPtr jmethod,Android.Runtime.JValue * parms)[0x0000e] in :0点 Android.Runtime.JNIEnv.CallStaticObjectMethod(System.IntPtr jclass, System.IntPtr jmethod,Android.Runtime.JValue [] parms)[0x00017] in :0点 Android.Runtime.JNIEnv.FindClass(System.String classname)[0x0003d] in:0 at Android.Runtime.JNIEnv.FindClass(System.Type type)[0x00084] in :Java.Lang.Class.FromType为0 (System.Type type)[0x00022] in:0
在Android.Content.Intent..ctor(Android.Content.Context packageContext,System.Type type)[0x00000] in :0点 Plugin.Media.MediaImplementation.CreateMediaIntent(System.Int32 id, System.String类型,System.String操作, Plugin.Media.Abstractions.StoreMediaOptions选项,System.Boolean 任务)[0x00000] in C:\项目\ mediaplugin的\ src \ Media.Plugin.Android \ MediaImplementation.cs:411 在Plugin.Media.MediaImplementation.TakeMediaAsync(System.String type,System.String动作, Plugin.Media.Abstractions.StoreMediaOptions options)[0x00044] in C:\项目\ mediaplugin的\ src \ Media.Plugin.Android \ MediaImplementation.cs:470 在Plugin.Media.MediaImplementation + d__17.MoveNext() [0x000ab] in C:\项目\ mediaplugin \ SRC \ Media.Plugin.Android \ MediaImplementation.cs:153---抛出异常的前一个位置的堆栈跟踪结束--- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() < 657aa8fea4454dc898a9e5f379c58734>中的[0x0000c]:0 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task任务)[0x0003e] in < 657aa8fea4454dc898a9e5f379c58734>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task任务)[0x00028] in < 657aa8fea4454dc898a9e5f379c58734>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task任务)[0x00008] in < 657aa8fea4454dc898a9e5f379c58734>:0 at System.Runtime.CompilerServices.TaskAwaiter`1 [TResult] .GetResult() [0x00000]在< 657aa8fea4454dc898a9e5f379c58734>中:0 at EClinicForDoctor.Pages.VisitsPage + d__17.MoveNext ()[0x00175]在E:\ Doctor Project \ Mobile中 应用程序\ V1 \ 4 \ EClinicForDoctor \ EClinicForDoctor \ EClinicForDoctor \网页\ VisitsPage.xaml.cs:235 ---托管Java.Lang.ClassNotFoundException堆栈跟踪结束--- java.lang.ClassNotFoundException: md55b01af31820394fbfb172542d1258596.MediaPickerActivity at java.lang.Class.classForName(Native Method)at java.lang.Class.forName(Class.java:324)at md5270abb39e60627f0f200893b490a1ade.ButtonRenderer_ButtonClickListener.n_onClick(母语 方法)at md5270abb39e60627f0f200893b490a1ade.ButtonRenderer_ButtonClickListener.onClick(ButtonRenderer_ButtonClickListener.java:30) 在android.view.View.performClick(View.java:5697)at android.widget.TextView.performClick(TextView.java:10826)at android.view.View $ PerformClick.run(View.java:22526)at android.os.Handler.handleCallback(Handler.java:739)at android.os.Handler.dispatchMessage(Handler.java:95)at android.os.Looper.loop(Looper.java:158)at android.app.ActivityThread.main(ActivityThread.java:7225)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 引起:java.lang.ClassNotFoundException:没找到类 " md55b01af31820394fbfb172542d1258596.MediaPickerActivity"在路径上: DexPathList [[zip文件 " /data/app/com.companyname.EClinicForDoctor-1/base.apk"],nativeLibraryDirectories = [/数据/应用/ com.companyname.EClinicForDoctor-1 / LIB /臂, /data/app/com.companyname.EClinicForDoctor-1/base.apk!/lib/armeabi-v7a, / vendor / lib,/ system / lib]] dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 在java.lang.ClassLoader.loadClass(ClassLoader.java:511)at java.lang.ClassLoader.loadClass(ClassLoader.java:469)...还有14个 抑制:java.lang.ClassNotFoundException: md55b01af31820394fbfb172542d1258596.MediaPickerActivity at java.lang.Class.classForName(Native Method)at java.lang.BootClassLoader.findClass(ClassLoader.java:781)at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)at java.lang.ClassLoader.loadClass(ClassLoader.java:504)...还有15个 引起:java.lang.NoClassDefFoundError:找不到使用的类 引导类加载器;没有可用的堆栈跟踪}
然后我从github读取了插件的说明,它与视频的指令有些相似,并且发生了同样的错误。怎么能解决这个问题呢?
答案 0 :(得分:6)
尝试删除项目的bin obj文件夹。
您的编译代码和NuGet位于obj,bin文件夹中。有时当你添加任何新的NuGet时,它不会进入obj,bin文件夹。它只使用早期编译的NuGet作为bin和obj的缓存。删除所有bin,obj force编译器以创建新的bin obj文件夹并重新编译解决方案。每当你在解决方案中添加任何新的NuGet时,最好删除bin,obj。