NullReferenceExplantion(C#)
Posted: 2016年4月23日(土) 23:27
デバッグしボタンを押すと
NullReferenceExplantionはハンドルされませんでした。
型 'System.NullReferenceException' のハンドルされていない例外が PresentationFramework.dll で発生しました
追加情報:オブジェクト参照がオブジェクト インスタンスに設定されていません。
と表示されます。
コードは前書いたものの続きというか違うものです。
NullReferenceExplantionはハンドルされませんでした。
型 'System.NullReferenceException' のハンドルされていない例外が PresentationFramework.dll で発生しました
追加情報:オブジェクト参照がオブジェクト インスタンスに設定されていません。
と表示されます。
コードは前書いたものの続きというか違うものです。
//Settings1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WPF
{
/// <summary>
/// Settings1.xaml の相互作用ロジック
/// </summary>
public partial class Settings1 : Window
{
public Settings1()
{
InitializeComponent();
}
private void btn0_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void radio_TCP_Checked(object sender, RoutedEventArgs e)//ラジオボタンTCP
{
this.changebar.DataContext = "TCP";
}
private void radio_UDP_Checked(object sender, RoutedEventArgs e)//ラジオボタンUDP
{
this.changebar.DataContext = "UDP";
}
/* // ラジオボタンのチェック状態変更時の処理
// チェックがオンになった場合の処理
private void radio_TCP_Checked(object sender, RoutedEventArgs e)
{
this.changebar.DataContext = "チェックがオンになりました";
}*/
}
}
<Window x:Class="WPF.Settings1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPF"
mc:Ignorable="d"
Title="Settings1" Height="400" Width="600">
<Grid>
<Button Name="btn0" HorizontalAlignment="Center"
VerticalAlignment="Center" Width="60" Height="48" Margin="522,10,10,311" Click="btn0_Click">
閉じる
</Button>
<TextBlock x:Name="JavaPlace" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Javaの場所" VerticalAlignment="Top" Width="100" Height="20"/>
<TextBox x:Name="JavaPlace_Box" HorizontalAlignment="Left" Height="23" Margin="10,35,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="161"/>
<TextBlock x:Name="PortSettings" HorizontalAlignment="Left" Margin="10,292,0,0" TextWrapping="Wrap" Text="ポート設定" VerticalAlignment="Top" Width="100" Height="20" RenderTransformOrigin="-0.29,0.6"/>
<RadioButton x:Name="radio_TCP" Content="TCP" HorizontalAlignment="Left" Margin="10,312,0,0" VerticalAlignment="Top" Width="45" Height="15" GroupName="UPnP_Type" IsChecked="True" Checked="radio_TCP_Checked"/>
<RadioButton x:Name="radio_UDP" Content="UDP" HorizontalAlignment="Left" Margin="10,332,0,0" VerticalAlignment="Top" Width="45" GroupName="UPnP_Port" Checked="radio_UDP_Checked"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="60,318,0,0" TextWrapping="Wrap" Text="25565" VerticalAlignment="Top" Width="73"/>
<TextBlock x:Name="changebar" HorizontalAlignment="Left" Margin="10,352,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="572"/>
</Grid>
</Window>