我一直在使用簡單的嘗試在我的XML文件中這一類閱讀。我真的不知道我是否正確註釋了類。Android的XML註釋
我不知道如果我需要這部分:
public Frame()
{
super();
}
public Frame(int num, int x, int y, int width, int height,int offsetx,int offsety, int duration)
{
this.Num = num;
this.X = x;
this.Y = y;
this.Width = width;
this.Height = height;
this.OffsetX = offsetx;
this.OffsetY = offsety;
this.Duration = duration;]
什麼是超()呢?我需要獲得者/安裝者嗎?我添加了getters或setters嗎?他們是自動自動還是自動調用?
下面是完整的類:
public class SpriteAnimationManag
{
// Animation frame class
@Element(name = "Frame")
public class Frame
{
@Element(name = "Num")
public int Num;
@Element(name = "X")
public int X;
@Element(name = "Y")
public int Y;
@Element(name = "Width")
public int Width;
@Element(name = "Height")
public int Height;
@Element(name = "OffSetX")
public int OffsetX;
@Element(name = "OffSetY")
public int OffsetY;
@Element(name = "Duration")
public float Duration;
public Frame()
{
super();
}
public Frame(int num, int x, int y, int width, int height,int offsetx,int offsety, int duration)
{
this.Num = num;
this.X = x;
this.Y = y;
this.Width = width;
this.Height = height;
this.OffsetX = offsetx;
this.OffsetY = offsety;
this.Duration = duration;
}
}
// Animaiton class to hold the name and frames
public class Animation
{
@Element(name = "Name")
public String Name;
@Element(name = "FrameRate")
public int FrameRate;//may need elementarray or list???
@Element(name = "Loop")
public boolean Loop;
@Element(name = "Pingpong")
public boolean Pingpong;
@ElementArray(name = "Frames")
public Frame[] Frames;
public Animation()
{
super();
}
public Animation(String name, int framerate, boolean loop, boolean pingpong, Frame[] frames)
{
this.Name = name;
this.FrameRate = framerate;
this.Loop = loop;
this.Pingpong = pingpong;
this.Frames = frames;
}
}
// The Sprite Texture stores the Sprite Sheet path.fr
public class SpriteTexture
{
// The Sprite Sheet texture file path
@Element(name = "path")
public String Path;
public SpriteTexture()
{
super();
}
public SpriteTexture(String path)
{
this.Path = path;
}
}
// Aniamtion Set contains the Sprite Texture and Animaitons.
@Root(name = "Animations")
public static class XNAAnimationSet
{
// The sprite texture object
@Element(name = "Texture")
public SpriteTexture SpriteTexture;
// The animation array in the Animation Set
@ElementArray(name = "Animation")
public Animation[] Animations;
public XNAAnimationSet()
{
super();
}
public XNAAnimationSet(SpriteTexture spritetexture, Animation[] animations)
{
this.SpriteTexture = spritetexture;
this.Animations = animations;
}
}
// Sprite Animation Manager class
public final static class SpriteAnimationManager
{
private static final String XNAAnimationSet = null;//was static private static
public static int AnimationCount;
// Read the Sprite Sheet Description information from the description xml file
public static XNAAnimationSet Read(String filename) throws Exception
{
XNAAnimationSet animationSet = new XNAAnimationSet();
Serializer serializer = new Persister();
try {
animationSet = serializer.read(XNAAnimationSet.class, filename);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
// Count the animations to Animation Count
AnimationCount = animationSet.Animations.length;
return animationSet;
}
}
}
我一直想看看有什麼正在試圖將類寫入文件中讀取。該文件已創建,但它是空的。
誰能告訴我,如果我正確註解嗎?我究竟做錯了什麼?
'超()'調用超類的構造函數。這是基本的Java,所以我想你在嘗試更復雜的事情之前首先需要刷新一些Java技能。 – Veger
我同意@Veger,你所有的POJO類都是SpriteAnimationManag的內部類,這不會工作。它們應該是單獨的類或至少是靜態的內部類(膨脹的syntaxic選擇)。 – Snicolas
我知道Java和C#很像。該代碼在C#中爲什麼不在Java中工作?你想看到我的C#代碼以供參考嗎? 我學習編程的方式就是在做。此外,我只是一個業餘愛好者,我喜歡學習新事物。我沒有時間去「學習」,我只有時間去做。 –