应用程序在设备本身上运行时崩溃,但当它连接到调试模式时工作正常

问题描述 投票:0回答:1

我正在开发一个应用程序来处理 Android 的库存,当它在设备本身上运行时崩溃(我使用的是三星 S 20+ 和 A 21S,但如果它在调试模式下连接到 Visual Studio,它就可以工作很好,它是一个与可观察集合相关的集合视图,视图模型有两组变量,其中包含所有记录,另一个处理过滤器,最初两者具有相同的数据子集(不应用过滤器) ,但是当我设置第二个值(即 CollectionView 上使用的值)时,应用程序崩溃了。

使用 Net Maui 8.0.60,目标是 14v min 版本 10

    public InventoryViewModel()
    {
        if (string.IsNullOrEmpty(Title))
            Title = "Inventario";
        SelectionMode = SelectionMode.Multiple;
        LoadInventory();
    }
    public void LoadInventory()
    {
        try
        {

            Inventory = new ObservableCollection<ProductsModel>();
            Inventory.Add(new ProductsModel { ProductId = 1, ProductName = "Perfume 1", ProductCategory = "P", Quantity = 1, UnitPrice = 3.53M, BarCode = "1234", IsImageOnServer = false });
            Inventory.Add(new ProductsModel { ProductId = 2, ProductName = "Perfume 2", ProductCategory = "P", Quantity = 2, UnitPrice = 4.63M, BarCode = "5697", IsImageOnServer = false });
            Inventory.Add(new ProductsModel { ProductId = 3, ProductName = "Perfume 3", ProductCategory = "P", Quantity = 3, UnitPrice = 5.73M, BarCode = "8741", IsImageOnServer = false });
            Inventory.Add(new ProductsModel { ProductId = 4, ProductName = "Perfume 4", ProductCategory = "P", Quantity = 2, UnitPrice = 6.83M, BarCode = "9965", IsImageOnServer = false });
            **SearchResults = Inventory;**   //Here is where the app crash.

        }
        catch (Exception)
        {
            throw;
        }
    }

我一直在努力:

  1. 定义可观察集合,然后向其中添加记录
  2. 将第一个的值直接分配给可观察集合,然后是第二个。
  3. 创建一个列表,然后转换为可观察的。
  4. 此外,在手机上以发布模式安装该应用程序。

在声明时添加一些延迟,然后添加数据,认为这是一个时间问题,但不是运气。

这是堆栈代码:

    Time    Device Name Type    PID Tag Message
    06-27 23:16:36.573  Samsung SM-A217M    Error   11830   AndroidRuntime  Process: com.gperfumes.crm, PID: 11830
    06-27 23:16:36.607  Samsung SM-A217M    Warning 5368    WindowManager   Prepare app transition: mNextAppTransitionRequests=[TRANSIT_CLOSE, TRANSIT_CLOSE, TRANSIT_CLOSE], mNextAppTransitionFlags=TRANSIT_FLAG_APP_CRASHED, displayId: 0 Callers=com.android.server.wm.DisplayContent.prepareAppTransition:6369 com.android.server.wm.DisplayContent.prepareAppTransition:6364 com.android.server.wm.ActivityRecord.finishIfPossible:3650 com.android.server.wm.ActivityRecord.finishIfPossible:3456 com.android.server.wm.Task.finishTopCrashedActivityLocked:8918 
    06-27 23:16:36.606  Samsung SM-A217M    Debug   5368    SGM:GameManager sendFocusOutConditionally() - mPrevNotiPkg: (unknown), userId: 0
    handleTaskFocused(), pkgName: com.sec.android.app.launcher, userID:0 mResumedPkgMap does not containsKey.
    06-27 23:16:36.606  Samsung SM-A217M    Debug   5368    SGM:GameManager handleTaskFocused().
    06-27 23:16:36.606  Samsung SM-A217M    Debug   5368    SGM:GameManager onLooperPrepared(), msg: MSG_TASK_FOCUSED, pkgName: com.sec.android.app.launcher, userId: 0
    06-27 23:16:36.605  Samsung SM-A217M    Debug   5368    SGM:GameManager TaskStackListener.onTaskFocusChanged(), taskId=23936, focused=true
    sendRunningComponentFocus(), pkgName: com.sec.android.app.launcher, userId: 0
    06-27 23:16:36.605  Samsung SM-A217M    Debug   5368    SGM:GameManager TaskStackListener.onTaskFocusChanged(), taskId=23965, focused=false
    06-27 23:16:36.605  Samsung SM-A217M    Debug   5368    StatusBarManagerService notifyRequestedSystemKey recent=false home=false
    06-27 23:16:36.605  Samsung SM-A217M    Debug   5368    MARsPolicyManager   onPackageResumedFG pkgName = com.gperfumes.crm, userId = 0
    06-27 23:16:36.605  Samsung SM-A217M    Verbose 5368    WindowManager   Changing focus from Window{dd96dcb u0 com.gperfumes.crm/crc646584e998dbc9d4ac.MainActivity} to null displayId=0 Callers=com.android.server.wm.RootWindowContainer.updateFocusedWindowLocked:583 com.android.server.wm.WindowManagerService.updateFocusedWindowLocked:6497 com.android.server.wm.ActivityTaskManagerService.setResumedActivityUncheckLocked:5498 com.android.server.wm.ActivityRecord.moveFocusableActivityToTop:3364 
    06-27 23:16:36.603  Samsung SM-A217M    Debug   5368    InputDispatcher Focused application set to (0): 99e7e90
    06-27 23:16:36.602  Samsung SM-A217M    Warning 5368    WindowManager   Prepare app transition: mNextAppTransitionRequests=[TRANSIT_CLOSE, TRANSIT_CLOSE], mNextAppTransitionFlags=TRANSIT_FLAG_APP_CRASHED, displayId: 0 Callers=com.android.server.wm.DisplayContent.prepareAppTransition:6369 com.android.server.wm.DisplayContent.requestTransitionAndLegacyPrepare:6384 com.android.server.wm.Task.finishTopCrashedActivityLocked:8917 com.android.server.wm.RootWindowContainer.lambda$finishTopCrashedActivities$20:2781 com.android.server.wm.RootWindowContainer$$ExternalSyntheticLambda30.accept:10 
    06-27 23:16:36.601  Samsung SM-A217M    Warning 5368    WindowManager   Prepare app transition: mNextAppTransitionRequests=[TRANSIT_CLOSE], mNextAppTransitionFlags=TRANSIT_FLAG_APP_CRASHED, displayId: 0 Callers=com.android.server.wm.DisplayContent.prepareAppTransition:6369 com.android.server.wm.Task.finishTopCrashedActivityLocked:8916 com.android.server.wm.RootWindowContainer.lambda$finishTopCrashedActivities$20:2781 com.android.server.wm.RootWindowContainer$$ExternalSyntheticLambda30.accept:10 com.android.server.wm.Task.forAllTasks:5181 
    06-27 23:16:36.599  Samsung SM-A217M    Warning 5368    ContextImpl Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1242 com.android.server.am.AppErrors.crashApplicationInner:724 com.android.server.am.AppErrors.crashApplication:584 com.android.server.am.ActivityManagerService.handleApplicationCrashInner:9793 com.android.server.am.ActivityManagerService.handleApplicationCrash:9672 
    Force finishing activity com.gperfumes.crm/crc646584e998dbc9d4ac.MainActivity
    06-27 23:16:36.599  Samsung SM-A217M    Warning 5368    ActivityManager crash : com.gperfumes.crm,10338
    06-27 23:16:36.598  Samsung SM-A217M    Debug   5368    Debug   low && ship && 3rdparty app crash, do not dump
    06-27 23:16:36.598  Samsung SM-A217M    Info    5368    DropBoxManagerService   add tag=data_app_crash isTagEnabled=true flags=0x2
    06-27 23:16:36.593  Samsung SM-A217M    Info    11830   MonoDroid   
    06-27 23:16:36.593  Samsung SM-A217M    Info    11830   MonoDroid   android.runtime.JavaProxyThrowable: [System.Reflection.TargetInvocationException]: Arg_TargetInvocationException
        at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Unknown Source:0)
        at System.RuntimeType.CreateInstanceMono(Unknown Source:0)
        at System.RuntimeType.CreateInstanceDefaultCtor(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing+TypeRouteFactory.GetOrCreate(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing.GetOrCreateContent(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection.GetOrCreateFromRoute(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection+<GoToAsync>d__65.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellNavigationManager+<GoToAsync>d__14.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at CRM.ViewModels.InventoryViewModel+<>c+<<get_EditProductCommand>b__41_0>d.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0(Unknown Source:0)
        at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0(Unknown Source:0)
        at Java.Lang.Thread+RunnableImplementor.Run(Unknown Source:0)
        at Java.Lang.IRunnableInvoker.n_Run(Unknown Source:0)
        at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(Unknown Source:0)
        at mono.java.lang.RunnableImplementor.n_run(Native Method)
        at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
    06-27 23:16:36.593  Samsung SM-A217M    Info    11830   MonoDroid   
    --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---
    06-27 23:16:36.592  Samsung SM-A217M    Info    11830   MonoDroid   android.runtime.JavaProxyThrowable: [System.Reflection.TargetInvocationException]: Arg_TargetInvocationException
        at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Unknown Source:0)
        at System.RuntimeType.CreateInstanceMono(Unknown Source:0)
        at System.RuntimeType.CreateInstanceDefaultCtor(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing+TypeRouteFactory.GetOrCreate(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing.GetOrCreateContent(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection.GetOrCreateFromRoute(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection+<GoToAsync>d__65.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellNavigationManager+<GoToAsync>d__14.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at CRM.ViewModels.InventoryViewModel+<>c+<<get_EditProductCommand>b__41_0>d.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0(Unknown Source:0)
        at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0(Unknown Source:0)
        at Java.Lang.Thread+RunnableImplementor.Run(Unknown Source:0)
        at Java.Lang.IRunnableInvoker.n_Run(Unknown Source:0)
        at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(Unknown Source:0)
        at mono.java.lang.RunnableImplementor.n_run(Native Method)
        at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
    06-27 23:16:36.592  Samsung SM-A217M    Info    11830   MonoDroid   
    --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---
    06-27 23:16:36.592  Samsung SM-A217M    Info    11830   MonoDroid   Android.Runtime.JavaProxyThrowable: Exception_WasThrown, Android.Runtime.JavaProxyThrowable
    06-27 23:16:36.584  Samsung SM-A217M    Info    11830   MonoDroid   UNHANDLED EXCEPTION:
    06-27 23:16:36.582  Samsung SM-A217M    Warning 11830   monodroid-assembly  Shared library 'liblog' not loaded, p/invoke '__android_log_print' may fail
    06-27 23:16:36.573  Samsung SM-A217M    Error   11830   AndroidRuntime  android.runtime.JavaProxyThrowable: [System.Reflection.TargetInvocationException]: Arg_TargetInvocationException
        at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Unknown Source:0)
        at System.RuntimeType.CreateInstanceMono(Unknown Source:0)
        at System.RuntimeType.CreateInstanceDefaultCtor(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing+TypeRouteFactory.GetOrCreate(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing.GetOrCreateContent(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection.GetOrCreateFromRoute(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection+<GoToAsync>d__65.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellNavigationManager+<GoToAsync>d__14.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at CRM.ViewModels.InventoryViewModel+<>c+<<get_EditProductCommand>b__41_0>d.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0(Unknown Source:0)
        at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0(Unknown Source:0)
        at Java.Lang.Thread+RunnableImplementor.Run(Unknown Source:0)
        at Java.Lang.IRunnableInvoker.n_Run(Unknown Source:0)
        at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(Unknown Source:0)
        at mono.java.lang.RunnableImplementor.n_run(Native Method)
        at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
android crash maui observablecollection
1个回答
0
投票

感谢大家的评论,与他们一起,我找到了问题的解决方案。

问题出在 XAML 代码中,而不是在 C# 中,collectionview 上有错误的引用,我指向了对不存在名称的引用。

我阅读了所有这篇文章,其中有人引用了一个不存在的颜色名称,我开始注释掉所有控件,然后一一启用(在 XAML 上),直到找到根本原因(我没有玩因为我认为问题出在 C# 代码而不是 XAML)

                        <SwipeView.RightItems>
                            <SwipeItems Mode="Reveal">
                                <SwipeItem Text="Editar" 
                                           BackgroundColor="#4CAF50"
                                           IconImageSource="{FontImage FontFamily='AwesomeIcons', Glyph={x:Static FontHelpers:FontHelperAwesome.Pencil}, Size=30, Color=LightGreen}" 
                                           Command="{Binding BindingContext.EditTransactionCommand, **Source={x:Reference TransactionStatementCollectionView}}"** //This reference was pointing to the wrong name 
                                           CommandParameter="{Binding .}" />
                            </SwipeItems>
                        </SwipeView.RightItems>
© www.soinside.com 2019 - 2024. All rights reserved.