xamarin.android中的java.lang.reflect.InvocationTargetException

时间:2015-06-20 10:37:53

标签: android android-fragments xamarin xamarin.android

单击片段中的按钮时出现此异常 以下是我的片段的代码

    public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
        {
            int pos = position + 1;
            if (pos == 1) {
                View view = LayoutInflater.From (container.Context).Inflate (Resource.Layout.pager_item, container, false);
                container.AddView (view);
                return view;
            } else if (pos == 2) {
                View view = LayoutInflater.From (container.Context).Inflate (Resource.Layout.BookAService, container, false);
                Spinner spinner = view.FindViewById<Spinner> (Resource.Id.spinner);
                var adapter = ArrayAdapter.CreateFromResource (
                                  container.Context, Resource.Array.planets_array, Android.Resource.Layout.SimpleDropDownItem1Line);

                adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleDropDownItem1Line);
                spinner.Adapter = adapter;
                var sel = spinner.SelectedItem.ToString();
                    Button but = view.FindViewById<Button>(Resource.Id.buttonservice);
                try{
                    but.Click += async (object sender, EventArgs e) => {
                        ParseObject Service = new ParseObject("Services Ordered");
                        Service["userid"] = ParseUser.CurrentUser.ObjectId;
                        Service["Name"] = sel;
                        Service["Username"] = ParseUser.CurrentUser.Get<String>("Name");
                        await Service.SaveAsync();
                        Toast.MakeText(container.Context,"Your Service request is taken and our will be processed within One hour",
                        ToastLength.Long).Show();
                    };
                }catch (Exception e){
                    Toast.MakeText (container.Context, e.ToString (), ToastLength.Long).Show ();
                }
                container.AddView (view);
                return view;


            } else {
                View view = LayoutInflater.From (container.Context).Inflate (Resource.Layout.LogIn, container, false);
                container.AddView (view);
                return view;
            }
        }

当我单击片段中的按钮时,代码会抛出异常

    java.lang.reflect.InvocationTargetException

我也试图抓住异常并将其烘烤到屏幕,但它没有帮助 请帮忙。谢谢。

1 个答案:

答案 0 :(得分:0)

问题是由于声明解析对象的空间。

    ParseObject Service = new ParseObject("Services Ordered");
相关问题