尝试在一个名为 load 的类中加载纹理,该类包含其他一些资产加载和显示
后来在另一个类中尝试通过创建类加载的对象来使用相同的纹理求解框
public class load{
@Override
public void show() {
try {
XmlReader reader = new XmlReader();
Element element = reader.parse(Gdx.files.internal(
"data/loadassets.xml").read());.....
Element help = element.getChildByName("help");...
solvebox = new Texture(
Gdx.files.internal("data/" + help.get("box")));
}
...
}
现在在另一个类中创建了一个 obj 并尝试绘制它......
class correct{
....
@Override
public void render(float delta) {
load obj=new load();
batch.begin();
batch.draw(obj.solvebox, ((w / 2) - (w / 15f)), (h / 3));
batch.end();
...
}
NullPointerException
但它在这个位置显示一个,我希望使用类加载的对象第二次绘制它
> 09-06 16:56:04.910: E/AndroidRuntime(30523): FATAL EXCEPTION: GLThread
> 26856
> 09-06 16:56:04.910: E/AndroidRuntime(30523): java.lang.NullPointerException
> 09-06 16:56:04.910: E/AndroidRuntime(30523): at com.badlogic.gdx.graphics.g2d.SpriteBatch.renderMesh(SpriteBatch.java:1042)
> 09-06 16:56:04.910: E/AndroidRuntime(30523): at com.badlogic.gdx.graphics.g2d.SpriteBatch.end(SpriteBatch.java:267)
> **
>
> > 09-06 16:56:04.910: E/AndroidRuntime(30523): at
> > com.invntn.screens.CorrectScreen.render(CorrectScreen.java:86)
>
> **
> 09-06 16:56:04.910: E/AndroidRuntime(30523): at com.badlogic.gdx.Game.render(Game.java:46)
> 09-06 16:56:04.910: E/AndroidRuntime(30523): at com.invntn.trycolor.TryColor.render(TryColor.java:42)
> 09-06 16:56:04.910: E/AndroidRuntime(30523): at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:457)
> 09-06 16:56:04.910: E/AndroidRuntime(30523): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
> 09-06 16:56:04.910: E/AndroidRuntime(30523): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)