나는 이것이 내가 만든 가장 정확한 제목이라고 느낀다. Java로 카드 게임을 만들고 모든 카드 통계를 스프레드 시트에로드했습니다. 스프레드 시트를 읽고 JXL API를 사용하여 스프레드 시트의 해당 셀에서 각 카드의 통계를 가져 와서 데크 개체에 저장하면 모든 것이 실제로 잘 작동하지만 문자열을 사용하려고하면 getImage() 반환, null 포인터를 가져오고 이유를 알아낼 수 없습니다. 나는 관련성이 있다고 생각되는 모든 것을 게시 할 것이고, 더 많은 것이 필요한지 알려주시기 바랍니다.디렉토리에서 문자열을 사용하여 Excel에서 이미지를 바꾼다.
첫 번째 부분은 스프레드 시트를로드하고 데이터를 Deck 개체에 연결하는 LoadCards 클래스의 것입니다. 참고 사항 : 나는 그것이 작동하는지 아닌지를 확인하기위한 시험으로 여기 한 번만 시도합니다. 마지막 줄은 다음과 같습니다 갑판 생성자에 대한 개체를 빌드를
public class LoadCards
{
public Deck LoadCards()
{
Workbook cardList = null;
try
{
cardList = Workbook.getWorkbook(new File("C:\\DC Card Game\\src\\DCCardGame\\resources\\CardList.xls"));
}
catch (IOException e)
{
String message = "The file titled CardList.xls was not found.";
String title = "File Not Found";
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
} catch (BiffException ex)
{
String message = "File must have an extension of .xls";
String title = "Incompatible CardList File";
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
}
Sheet typeSheet = cardList.getSheet(0);
Sheet equipmentSheet = cardList.getSheet(1);
String equipmentType = typeSheet.getCell(0,1).getContents();
Deck testCard= new Deck(equipmentSheet.getCell(0, 1).getContents(),equipmentType,Integer.parseInt(equipmentSheet.getCell(2,1).getContents()),Integer.parseInt(equipmentSheet.getCell(3,1).getContents()),Integer.parseInt(equipmentSheet.getCell(4,1).getContents()),equipmentSheet.getCell(5,1).getContents());
return testCard;
:
public Deck(String cardName, String type, int cost, int value, int power, String image)
{
super();
}
그리고 갑판 모든 적절한 게터가/세터가 카드를 확장합니다. 내 폼 클래스에서
public Card(String cardName, String type, int cost, int value, int power, String image)
{
this.cardName = cardName;
this.type = type;
this.cost = cost;
this.value = value;
this.power = power;
this.image = image;
}
이 나는 이미지가 작동하는지 테스트하기 위해 사용하고 내 코드입니다 (힌트 :. 그렇지 않은) 그것은
LoadCards test = new LoadCards();
test.LoadCards();
ImageIcon testImage = new ImageIcon(getClass().getResource(test.LoadCards().getImage()));
extraLineupSlot1.setIcon(testImage);
내가 그림을 필요는 NullPointerException에게 던지는 유지 어떻게하면 이것을 교정하여 디렉토리를 나타내는 스프레드 시트에서 문자열을 호출 할 수 있으며, 디렉토리는 Deck/Card 객체의 이미지 속성에 저장됩니다. 그런 다음 해당 속성을 호출하고 연관된 아이콘을 변경할 수 있습니다. 내가 만든 여러 JLabels.
'System.out.println'은 무엇을 말합니까? – MadProgrammer
어떤 식으로 사용하면됩니까? 이해할 수 있을지 모르겠다. 편집 : 만약 내가 System.out.println (test.LoadCards(). getImage()); 나는 또한 널을 얻는다. – lfernandes
약간의'System.out.println' 문을 넣어 XML 파일에서 값을 읽었는지, 값을 설정하고 있는지, 그리고 이미지를로드하려고 할 때, 경로/이름은 당신이 무엇을 기대하는지입니다 – MadProgrammer