我试图创建具有多个功能的小部件,其中一个是手电筒。
我使用新的Camera2
api但无法真正使用它。
我创建了自定义CameraManager.TorchCallback
类来处理火炬开/关回调,但constructor
调用抛出ClassNotFound
异常:
没找到课程" md50ef6a3f50a79fbeb48e8252e4750d416.FlashLightCallback" on path:DexPathList [[zip file" /data/app/com.arsena.rooting-1/base.apk"],nativeLibraryDirectories = [/ data / app / com.arsena.rooting-1 / lib / arm,/ vendor / lib,/ system / lib]]
以下是我appWidget
的部分来源:
public class RootWidgets : AppWidgetProvider, IFlashLightStateListener
{
Context _context;
public override void OnReceive(Context context, Intent intent)
{
if (/* some condition */)
{
_context = context;
UpdateWidget(context);
return;
}
}
#region IFlashLightStateListener implementation
bool _flashLightEnabled;
public bool IsFlashLightEnabled
{
get
{
return _flashLightEnabled;
}
set
{
_flashLightEnabled = value;
UpdateWidget(_context);
}
}
#endregion
private void UpdateWidget(Context context)
{
// some actions...
CameraManager cameraManager = (CameraManager)context.GetSystemService(Context.CameraService);
var callBack = new FlashLightCallback(this);
cameraManager.RegisterTorchCallback(callBack, null);
// some actions...
}
}
FlashLightCallback
上课:
public class FlashLightCallback : CameraManager.TorchCallback
{
IFlashLightStateListener _fListener;
Context _context;
public FlashLightCallback(IFlashLightStateListener flashStateListener) // here comes exception
{
_fListener = flashStateListener;
}
public override void OnTorchModeChanged(string cameraId, bool enabled)
{
base.OnTorchModeChanged(cameraId, enabled);
_fListener.IsFlashLightEnabled = enabled;
}
}
public interface IFlashLightStateListener
{
bool IsFlashLightEnabled { get; set; }
}
完整的异常堆栈跟踪:
[flashlight] Java.Lang.ClassNotFoundException: Didn't find class "md50ef6a3f50a79fbeb48e8252e4750d416.FlashLightCallback" on path: DexPathList[[zip file "/data/app/com.arsena.rooting-1/base.apk"],nativeLibraryDirectories=[/data/app/com.arsena.rooting-1/lib/arm, /vendor/lib, /system/lib]]
[flashlight] at Java.Interop.JniEnvironment+Types.FindClass (System.String classname) [0x00132] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.Types.cs:66
[flashlight] at Java.Interop.JniType..ctor (System.String classname) [0x00008] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniType.cs:30
[flashlight] at Java.Interop.JniPeerMembers+JniInstanceMethods..ctor (System.Type declaringType) [0x0006a] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:25
[flashlight] at Java.Interop.JniPeerMembers+JniInstanceMethods.GetConstructorsForType (System.Type declaringType) [0x0003b] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:80
[flashlight] at Java.Interop.JniPeerMembers+JniInstanceMethods.StartCreateInstance (System.String constructorSignature, System.Type declaringType, Java.Interop.JniArgumentValue* parameters) [0x00044] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:111
[flashlight] at Android.Hardware.Camera2.CameraManager+TorchCallback..ctor () [0x00022] in /Users/builder/data/lanes/3340/4e275588/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Hardware.Camera2.CameraManager.cs:175
[flashlight] at Rooting.FlashLightCallback..ctor (IFlashLightStateListener flashStateListener) [0x00000] in /Users/imac/Projects/Rooting/Rooting/FlashLightCallback.cs:12
[flashlight] at Rooting.RootWidget.UpdateWidget (Android.Content.Context context) [0x001fe] in /Users/imac/Projects/Rooting/Rooting/RootWidget.cs:173
[flashlight] --- End of managed exception stack trace ---
[flashlight] java.lang.ClassNotFoundException: Didn't find class "md50ef6a3f50a79fbeb48e8252e4750d416.FlashLightCallback" on path: DexPathList[[zip file "/data/app/com.arsena.rooting-1/base.apk"],nativeLibraryDirectories=[/data/app/com.arsena.rooting-1/lib/arm, /vendor/lib, /system/lib]]
[flashlight] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
[flashlight] at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
[flashlight] at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
[flashlight] at md50ef6a3f50a79fbeb48e8252e4750d416.RootWidget.n_onReceive(Native Method)
[flashlight] at md50ef6a3f50a79fbeb48e8252e4750d416.RootWidget.onReceive(RootWidget.java:29)
[flashlight] at android.app.ActivityThread.handleReceiver(ActivityThread.java:3022)
[flashlight] at android.app.ActivityThread.access$1800(ActivityThread.java:179)
[flashlight] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1539)
[flashlight] at android.os.Handler.dispatchMessage(Handler.java:102)
[flashlight] at android.os.Looper.loop(Looper.java:145)
[flashlight] at android.app.ActivityThread.main(ActivityThread.java:5972)
[flashlight] at java.lang.reflect.Method.invoke(Native Method)
[flashlight] at java.lang.reflect.Method.invoke(Method.java:372)
[flashlight] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
[flashlight] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
[flashlight] Suppressed: java.lang.NoClassDefFoundError: md50ef6a3f50a79fbeb48e8252e4750d416.FlashLightCallback
[flashlight] at dalvik.system.DexFile.defineClassNative(Native Method)
[flashlight] at dalvik.system.DexFile.defineClass(DexFile.java:226)
[flashlight] at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
[flashlight] at dalvik.system.DexPathList.findClass(DexPathList.java:321)
[flashlight] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
[flashlight] ... 14 more
[flashlight] Suppressed: java.lang.ClassNotFoundException: md50ef6a3f50a79fbeb48e8252e4750d416.FlashLightCallback
[flashlight] at java.lang.Class.classForName(Native Method)
[flashlight] at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
[flashlight] at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
[flashlight] at java.lang.ClassLoader.loadClass(ClassLoader.jav
任何想法我做错了什么?
修改:
使用sample复制例外。