我如何解决此错误,System.NotSupportedException:无法激活JNI句柄0x7fec3e5620

时间:2018-12-13 12:18:26

标签: android xamarin

我尝试搜索错误,但似乎无法将找到的结果链接到我的应用程序。 这是我每次运行程序时遇到的错误。

Unhandled Exception:

System.NotSupportedException: Could not activate JNI Handle
0x7fec3e5620 (key_handle 0xe1ccda9) of Java 
type 'md5ca0dbb1ec41706184e899fc3d5b0057e/MainActivity'
as managed type 'PowerCellShipping3.MainActivity'. occurred

这是我的C#代码。我不确定是什么真正导致了错误,因为我从未遇到过该错误(显然)。

protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.activity_main);

        scan = FindViewById<Button>(Resource.Id.btnScan);
        lbviewScan = FindViewById<ListView>(Resource.Id.lvbScanned);
        lbviewReject = FindViewById<ListView>(Resource.Id.lbRejected);
        tvscanned = FindViewById<TextView>(Resource.Id.textView4);
        tvreject = FindViewById<TextView>(Resource.Id.textView5);
        etLot = FindViewById<EditText>(Resource.Id.etLotNumber);

        scan.Click += delegate {

            //Call Your Method When User Clicks The Button
            btnClick();
        };

    }

    /**************************************************************************************************************************************************************/

public class ToDoTasks
    {
        [PrimaryKey, AutoIncrement, Column("@Lot_Number")]
        public int Id { get; set; }

        [MaxLength(100)]
        public string Task { get; set; }
    }

    public List<string> GetData()
    {

        var db = new SQLiteConnection("Data Source = obdbnsql3; Persist Security Info=True;User ID = sa" + "Password=P0w3r1T");
        List<string> data = new List<string>();
        foreach (var item in db.Table<ToDoTasks>())
        {
            var objectItem =  item.Task.ToString();

            data.Add(objectItem);
        }
        return data;

    }

    /***************************************************************************************************************************************************************/
    public void btnClick()
    {

        sql1 = "update [Otto_Internal_Apps].[dbo].[Shipping_Detail] set [Box_Scanned] = 1, [Shipment_Scan_Date] = GETDATE(), [Box_Rejected] = 0 " +
              "where [Lot_No] = @Lot_Number and  ([Box_Rejected] != 1 or [Box_Rejected] is null)";

        SQLiteCommand sqlCommand = new SQLiteCommand(connection);

        sqlCommand.CommandText.Replace(sql1,sql1);

        string attempt = sql1;
        int iCount = Convert.ToInt32(attempt);

        sqlCommand.CommandText.Remove(iCount,iCount);

        /********************************************************************************************************************************/

        string attempt2 = "@Lot_Number";
        int iCount2 = Convert.ToInt32(attempt2);
        //sqlCommand.Parameters.AddWithValue("@Lot_number", etLot.Text);
        sqlCommand.CommandText.Insert(iCount2, etLot.Text);

        /********************************************************************************************************************************/

        try
        {   // Execute the query and return the rows affected 
            sql2 = "select top 1 * from [Otto_Internal_Apps].[dbo].[Shipping_Detail] where [Lot_No] = @Lot_Number and [Box_Rejected] = 1";

            int iRowsAffected = sqlCommand.ExecuteNonQuery();

                // if the rows affected is zero then the lot no. does not exist and must be inserted as a rejected scan
                if (iRowsAffected == 0)
                {

                    sqlCommand.CommandText = sql2;


                    sql3 = "INSERT INTO [Otto_Internal_Apps].[dbo].[Shipping_Detail] ([Lot_No],[Box_Rejected]) VALUES(@Lot_Number, 1) ";

                    //lbviewScan.Load(sqlCommand.ExecuteQuery);

                var items = GetData();
                var listView = FindViewById<ListView>(Resource.Id.lvbScanned);

                listView.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);

                if (lbviewScan.Count == 0)
                        {
                            sqlCommand.CommandText = sql3;

                        string attempt3 = sql3;
                        int iCount3 = Convert.ToInt32(attempt3);

                        sqlCommand.CommandText.Remove(iCount3, iCount3);

                        string attempt4 = "@Lot_Number";
                        int iCount4 = Convert.ToInt32(attempt4);

                        sqlCommand.CommandText.Insert(iCount4, etLot.Text);

                        sqlCommand.ExecuteNonQuery();
                        }


                //int iItemFound = lbviewReject.Items.IndexOf(etLot.Text);
                int iItemFound = itemList.IndexOf(etLot.Text);

                    if (iItemFound == -1)
                    {
                    //lbviewReject.Items.Add(etLot.Text);
                    itemList.Add(etLot.Text);
                }    
                }
                else
                {
                //int iItemFound = lbviewScan.Items.IndexOf(etLot.Text);
                int iItemFound = itemList.IndexOf(etLot.Text);
                    if (iItemFound == -1)
                    {
                    //lbviewScan.Items.Add(etLot.Text);
                    itemList.Add(etLot.Text);
                }

                    Console.Beep(800, 200);
                }
            }
            catch (SQLException sqle)
            {

            Toast.MakeText(ApplicationContext, sqle.Message, ToastLength.Long).Show();
            Console.Beep(2000, 1600);
                return;
            }

我在Xamarin网站上看到的其他帖子似乎是类似的错误,但就像我之前说的那样,我仍然找不到解决方案。 我认为该错误可能是由于其中一个列表框引起的,但我不确定。

任何帮助将不胜感激。谢谢

0 个答案:

没有答案