0
xml에서 로더를 만들어 메뉴를 만들려고합니다. 나는 버튼에 문제가있다. 항상 널 포인터의 오류를 제공합니다. title.xmlxml 위젯에서 여러 객체를 처리 할 때 null 결과 #
<?xml version="1.0" encoding="utf-8" ?>
<title>
<background>Assets/background</background>
<song>Assets/title</song>
<button>
<texture>Assets/background</texture>
<position>10,10</position>
<buttonaction>exit</buttonaction>
</button>
</title>
xmlManager 그것은 항상 select new button()
에서 XML 관리자 내에서 중지
static public class xmlManager
{
static public titleData makeTitle(ContentManager content)
{
titleData title = new titleData();
System.IO.Stream stream = TitleContainer.OpenStream("Content/title.xml");
XDocument doc = XDocument.Load(stream);
var titleXML = doc.Descendants("title").First();
title.background = titleXML.Element("background").Value;
title.song = titleXML.Element("song").Value;
title.button = new List<Button>();
title.button = (from button in doc.Element("title").Elements("button")
select new Button()
{
texture = button.Element("texture").Value,
position = StringToVector(button.Element("Position").Value),
buttonAction = button.Element("buttonAction").Value
}).ToList();
return title;
}
static private Vector2 StringToVector(string str)
{
//convert a string to a point
Vector2 vector;
vector.X = Convert.ToInt32(str.Split(',')[0]);
vector.Y = Convert.ToInt32(str.Split(',')[1]);
return vector;
}
}
: 다음은 코드입니다.
나는 당신의 해결책을 시도했다. 그러나 그것은 그것을 지나치지 않을 것이다. –
@PhilipHoseaChristianto 위치가 XML에서 position이 소문자이기 때문에 고정 답변 인 –
xml의 buttonAction에 대한 buttonaction을 변경했지만 여전히 작동하지 않았습니다. 또한 문자열에 벡터 null 예외를 추가했습니다. –