读书人

DataInputStream异常

发布时间: 2014-01-26 14:34:32 作者: rapoo

DataInputStream异常

package mygame;

import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

public class Screen extends GameCanvas implements Runnable {

private Sprite oRole;
private LayerManager oMap;
private TiledLayer oLayer;
public Screen()
{
super(false);
InitMap("/mygame/tile.png","/mygame/map.dat");
}

private void CreateTiledLayer(String sPathName)
{
try
{
Image oTiles=Image.createImage(sPathName);
oLayer=new TiledLayer(100,100,oTiles,20,20);
}
catch(Exception e)
{
e.printStackTrace();
}
}

public void InitMap(String sPathName,String MapData)
{
CreateTiledLayer(sPathName);
int iRows=oLayer.getHeight()/oLayer.getCellHeight();
int iColumes=oLayer.getWidth()/oLayer.getCellWidth();

int iCells=iRows*iColumes;
InputStream is=null;
is=getClass().getResourceAsStream(MapData);
byte [] ba=new byte[50];
try
{

//////////////////////////////////////////////////////////////////////
int count=is.read(ba); 为什么到这里就不进行下去了
/////////////////////////////////////////////////////////////////////
}
catch(Exception e)
{
e.printStackTrace();
}
for (int i=0;i<iRows;i++)
{
for(int j=0;j<iColumes;j++)
{
try
{
oLayer.setCell(i,j,ba[i*5+j]);
}
catch (Exception e)
{
oLayer.setCell(i,j,0);
}

}//for 1
}//for 2
oMap.append(oLayer);
}

public void run()
{
Graphics g=this.getGraphics();
while (true)
{
oMap.paint(g,0,0);         

读书人网 >Java Exception

热点推荐