Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# [Xamarin]无法从服务(java.lang.reflect.InvocationTargetException)启动通知_C#_Service_Xamarin_Notifications - Fatal编程技术网

C# [Xamarin]无法从服务(java.lang.reflect.InvocationTargetException)启动通知

C# [Xamarin]无法从服务(java.lang.reflect.InvocationTargetException)启动通知,c#,service,xamarin,notifications,C#,Service,Xamarin,Notifications,我试图在服务中发送通知,但得到了java.lang.reflect.InvocationTargetException。 这是我在服务“OnStartCommand”中调用的函数。。。 我复制粘贴了示例中的代码分配,因为我试图实现这一点,但我被困在这里 // Pass the current button press count value to the next activity: Bundle valuesForActivity = new Bundle();

我试图在服务中发送通知,但得到了java.lang.reflect.InvocationTargetException。 这是我在服务“OnStartCommand”中调用的函数。。。 我复制粘贴了示例中的代码分配,因为我试图实现这一点,但我被困在这里

// Pass the current button press count value to the next activity:
        Bundle valuesForActivity = new Bundle();
        valuesForActivity.PutInt ("count", 3);

        // When the user clicks the notification, SecondActivity will start up.
        Intent resultIntent = new Intent(this, typeof (MainActivity));

        // Pass some values to SecondActivity:
        resultIntent.PutExtras (valuesForActivity);

        // Construct a back stack for cross-task navigation:
        TaskStackBuilder stackBuilder = TaskStackBuilder.Create (this);
        stackBuilder.AddParentStack (Java.Lang.Class.FromType(typeof(MainActivity
        )));
        stackBuilder.AddNextIntent (resultIntent);

        // Create the PendingIntent with the back stack:            
        PendingIntent resultPendingIntent = 
            stackBuilder.GetPendingIntent (0, (int)PendingIntentFlags.UpdateCurrent);

        // Build the notification:
        NotificationCompat.Builder builder = new NotificationCompat.Builder (this)
            .SetAutoCancel (true)                    // Dismiss from the notif. area when clicked
            .SetContentIntent (resultPendingIntent)  // Start 2nd activity when the intent is clicked.
            .SetContentTitle ("Button Clicked")      // Set its title
            .SetNumber (1)                       // Display the count in the Content Info
            .SetSmallIcon(Resource.Drawable.Icon)  // Display this icon
            .SetContentText (String.Format(
                "The button has been clicked {0} times")); // The message to display.

        // Finally, publish the notification:
        NotificationManager notificationManager = 
            (NotificationManager)GetSystemService(Context.NotificationService);
        notificationManager.Notify(ButtonClickNotificationId, builder.Build());

我不明白为什么我会遇到这个问题,但这是我第一次提供服务和通知,请帮助我伙计们

您是否尝试使用Forms.Context代替MainActivity?异常的消息是什么?java.lang.reflect.InvocationTargetException