수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

실행이 안됩니다....

새난

2023.04.01

Exception in thread main java.lang.NullPointerException
at javax.swing.ImageIcon.init(Unknown Source)
at Board.init(Board.java:51)
at CoinStacker.init(CoinStacker.java:7)
at CoinStacker.main(CoinStacker.java:18)
이클립스로 돌렸는데이러한 오류가뜨네요 죄송하지만 왜그런지하고
실행하는법좀 알려주시면 감사하겠습니다 ㅠ ㅠ
참고로 메모장에 해서 프롬프트로도 돌려봤는데 클래스까지만 생성되고 실행하면 저오류가 뜨네요
초보자 한명 구제해 주세요 ㅠ ㅠ
CoinStacker.java (The entry point)import javax.swing.JFrame;public class CoinStacker extends JFrame implements Commons
{
public CoinStacker()
{
add( new Board() );
setTitle(Coin Stacker);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(Commons.WIDTH, Commons.HEIGHT + 32);
setLocationRelativeTo(null);
setResizable(false);
setVisible(true);
}

public static void main(String[] args)
{
new CoinStacker();
}
}Commons.javapublic interface Commons
{
public final int WIDTH = 200;
public final int HEIGHT = 300;
}Board.javaimport java.awt.Image;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.Rectangle;
import java.awt.BasicStroke;import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;import java.util.Timer;
import java.util.TimerTask;
import java.util.ArrayList;import javax.swing.ImageIcon;
import javax.swing.JPanel;public class Board extends JPanel implements Commons
{
private ArrayListCoin coins;
private int coinCount;
private int risk;
private Timer timer;
private Image arrow;
private Rectangle surface;
private boolean ingame;

private int arrowPos;
private boolean moveArrow;
private int arrowDir;

private final int MAX_COIN = 14;
private final int SNAP_TO_GRID = 5;
private final int Tal int TIPPING_POINT = 25;
private final int RISK_BAR_WIDTH = 20;
private final int RISK_BAR_MAX_HEIGHT = 200;
private final int ARROW_HEIGHT = 40; public Board()
{
addKeyListener(new TAdapter());
setFocusable(true);

coins = new ArrayListCoin();

ImageIcon ic
= new ImageIcon(this.getClass().getResource(arrow.png));
arrow = ic.getImage();

surface = new Rectangle(0, Commons.HEIGHT - ARROW_HEIGHT, 200, 40);

setDoubleBuffered(true);
timer = new Timer();
timer.scheduleAtFixedRate(new ScheduleTask(), 1000, 10);
}

public void addNotify()
{
super.addNotify();
gameInit();
}

public void gameInit()
{
risk = 0;
arrowPos = Commons.WIDTH / 2;
coinCount = 0;
ingame = true;
moveArrow = false;
arrowDir = -1;

coins.add(new Coin( Commons.WIDTH / 2 ));
coinCount++;
}

public void paint(Graphics g)
{
super.paint(g);

Graphics2D g2d = (Graphics2D)g;

RenderingHints rh =
new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHints(rh);

g2d.setFont(new Font(Arial, Font.PLAIN, 15));
g2d.drawString(# of coins: + coinCount, 10, 15);

g2d.drawString(Risk, 163, 55);
graphRisk(g2d);

if(ingame) {
g2d.setColor(Color.green);
g2d.fill(surface);
g2d.setColor(new Color(194, 255, 227));
g2d.fill(new Rectangle((Commons.WIDTH - arrow.getWidth(null)) / 2,
Commons.HEIGHT - ARROW_HEIGHT,
arrow.getWidth(null), arrow.getHeight(null)));

for(int i = 0; i coins.size(); i++) {
Coin m = coins.get(i);

g2d.drawImage(m.getImage(), m.getX(),
m.getY(), m.getWidth(),
m.getHeight(), this);
}
g2d.drawImage(arrow, arrowPos - arrow.getWidth(null) / 2,
Commons.HEIGHT - ARROW_HEIGHT,
arrow.getWidth(null), arrow.getHeight(null), this);
} else {
String message = Game Over;

Font big = new Font(Arial, Font.BOLD, 25);
FontMetrics metr = this.getFontMetrics(big);

g2d.setColor(Color.BLACK);
g2d.setFont(big);
g2d.drawString(message,
(Commons.WIDTH - metr.stringWidth(message)) / 2,
Commons.HEIGHT / 2);

g2d.setColor(Color.black);
g2d.setFont(new Font(Arial, Font.PLAIN, 12));
g2d.drawString(Hyunsu \Philip\ Cho, 10, 265);
g2d.drawString(Edmonds-Woodway High School, 10, 280);
g2d.drawString(noblepylon@gmail.com, 10, 295);
}

Toolkit.getDefaultToolkit().sync();
g.dispose();
}

public void addCoin()
{
// Move the arrow to the nearest fives.
long t = Math.round((double)arrowPos / SNAP_TO_GRID);
arrowPos = (int)t * SNAP_TO_GRID;

Coin newCoin = new Coin(arrowPos);
coins.add(newCoin);

moveArrow = false;

calculateRisk(newCoin);
if(coins.size() == MAX_COIN) clearScreen();

coinCount++;
// Decrease coinCount by 1 right before the game ends
// because the last coin does not count.
if(ingame && risk = 100) coinCount--;
}

public void clearScreen()
{
timer.cancel();
// Remove all the coins except the last coin.
Coin newCoin =
new Coin(coins.get(coins.size() - 1).getPos());
coins.clear();

coins.add(newCoin);
while(!moveArrow) {
newCoin.move();
collisionCheck();
}

timer = new Timer();
timer.scheduleAtFixedRate(new ScheduleTask(), 1000, 10);
}

public void collisionCheck()
{
Coin newCoin = coins.get(coins.size() - 1);

if(newCoin.getRect().intersects(surface)) {
newCoin.stop();
moveArrow = true;
}
&
for(int i = 0; i coins.size() - 1; i++) {
Coin t = coins.get(i);
if(newCoin.getRect().intersects(t.getRect())) {
newCoin.stop();
moveArrow = true;
}
}

// End the game *after* the last coin hits the ground
if(moveArrow & risk = 100) ingame = false;
}

public void calculateRisk(Coin lastCoin)
{
int diff = lastCoin.getPos() - Commons.WIDTH / 2;
// Measure how much the arrow is away from the center.
if(diff 0) diff *= -1;

if(diff = TIPPING_POINT) risk = 100;
else risk += diff;

if(risk 100) risk = 100;
}

public void graphRisk(Graphics2D g2d)
{
int barHeight = risk * RISK_BAR_MAX_HEIGHT / 100;

g2d.setColor(Color.white);
g2d.fill(new Rectangle(Commons.WIDTH - RISK_BAR_WIDTH,
Commons.HEIGHT - ARROW_HEIGHT - RISK_BAR_MAX_HEIGHT,
RISK_BAR_WIDTH, RISK_BAR_MAX_HEIGHT));

g2d.setColor(Color.red);
g2d.fill(new Rectangle(Commons.WIDTH - RISK_BAR_WIDTH,
Commons.HEIGHT - ARROW_HEIGHT - barHeight,
RISK_BAR_WIDTH, barHeight));
}

private class TAdapter extends KeyAdapter
{
public void keyReleased(KeyEvent e)
{
int key = e.getKeyCode();

if(key == KeyEvent.VK_SPACE) {
if(moveArrow && ingame) addCoin();
}
}

public void keyPressed(KeyEvent e)
{
int key = e.getKeyCode();

if(key == KeyEvent.VK_SPACE) {}
}
}

class ScheduleTask extends TimerTask
{
public void run()
{
if(moveArrow) {
if(arrowDir == -1) arrowPos -= 1;
if(arrowDir == 1) arrowPos += 1;

if(arrowPos = 0) arrowDir = 1;
if(arrowPos = Commons.WIDTH) arrowDir = -1;
}

for(int i = 0; i coins.size(); i++) {
Coin c = coins.get(i);
c.move();
}/ssp; }

collisionCheck();
repaint();
}
}
}Coin.javaimport java.awt.Rectangle;
import java.awt.Image;import javax.swing.ImageIcon;public class Coin
{
private int x, y;
private int dy;
private int width, height;
private Image image; public Coin(int x)
{
ImageIcon ic
= new ImageIcon(this.getClass().getResource(coin.png));
image = ic.getImage();

width = image.getWidth(null);
height = image.getHeight(null);

this.x = x - width / 2;
y = 0;
dy = 2;
}

public Image getImage()
{
return image;
}

public int getX()
{
return x;
}

public int getPos()
pan
{
return x + width / 2;
}

public int getY()
{
return y;
}

public int getWidth()
{
return width;
}

public int getHeight()
{
return height;
}

public Rectangle getRect()
{
return new Rectangle(x, y,
image.getWidth(null), image.getHeight(null));
}

public void move()
{
y += dy;
}

public void stop()
{
dy = 0;
}
}코드 전부 올려서 죄송합니다.. ㅠ ㅠ

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2701748 아이피 변경 부분이요... 날애 2025-07-17
2701665 자바스크립트 // 왜 if 두개를 쓰면 오류가 나죠? (2) 글리슨 2025-07-16
2701636 모바일웹 게시판 만들기 조언좀 부탁드려요 ㅜㅜ (2) 정훈 2025-07-16
2701610 [질문] AS3 액션으로 스테이지 사이즈를 조절할 수 있는 방법이 있을까요? (1) 앵겨쪼 2025-07-15
2701556 input text에 한글을 default 하려면.. (3) 히나 2025-07-15
2701528 apmsetup 접속이.... (5) 곰돌이 2025-07-15
2701506 암호를 *로 (6) 도도한 2025-07-14
2701475 배열최대값 찾기인데; 소스좀 해석해주세요; Orange 2025-07-14
2701397 세로 100% 푸터부분이 바닥에 안붙어요(세로 100% 되는 소스를 썼거든요) 꽃겨울 2025-07-13
2701369 [긴급]로드해온 swf가 갑자기 사라지는 현상..(익스10) (2) 곰돌이 2025-07-13
2701340 [c++]학교 과제 질문이요...... (3) 기쁨해 2025-07-13
2701311 구글 뉴스검색최적화 작업은 누구의 영역인가요? 많은 조언 부탁드려요! 리나 2025-07-13
2701285 아이폰이나 안드로이드 폰 인터넷으로 볼때 배꽃 2025-07-12
2701230 테마 설정하면 밑에 뜨는 글 삭제 (1) 창의적 2025-07-12
2701177 css적용이 안되요~ (6) 다니엘 2025-07-11
2701151 사이트작업시 inputbox 가 readonly 형태표시 어떻게 하시나요? (1) 찬내 2025-07-11
2701123 간단한 select 질문입니다 (3) 천사의눈물 2025-07-11
2701061 비베질문.. 똘끼 2025-07-10
2701034 메일폼 내 script 삽입가능한 방법 없을까요.. (2) 마음새 2025-07-10
2701008 분명히 버튼을 만들었는데 액션이 안걸립니다. (3) 재찬 2025-07-10
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com