2014-11-29 4 views
0

"Android Game Programming for Dummies"책에서 작업 중이며 예외가 발생합니다. IllegalArgumentException: UnknownBitmapConfiguration. 나는 이것이 행운을 가져올 수있는 것을 도처에서 찾고있었습니다. 나는 프로그래밍에 익숙하지 않아 어떤 도움을 주시면 감사하겠습니다.IllegalArgumentException : UnknownBitmapConfiguration 내 게임이 멈추는 원인은 무엇입니까?

여기 내 WhackAMoleView.java의

 public WhackAMoleView(Context context, AttributeSet attrs){ 
      super(context,attrs); 

      SurfaceHolder holder = getHolder(); 
      holder.addCallback(this); 

      thread = new WhackAMoleThread(holder,context, 
       new Handler(){ 
       @Override 
       public void handleMessage(Message m){ 

       } 
      }); 

      setFocusable(true); 
     } 
     public WhackAMoleThread getThread(){ 
      return thread; 
     } 

     class WhackAMoleThread extends Thread{ 

      public WhackAMoleThread(SurfaceHolder 
       surfaceHolder, Context context, 
        Handler handler){ 
       mySurfaceHolder = surfaceHolder; 
       myContext = context; 
       backgroundImg = 
         BitmapFactory.decodeResource 
         (context.getResources(), R.drawable.title); 
      } 

      @Override 
      public void run(){ 
       while (running){ 
        Canvas c = null; 
        try { 
         c = mySurfaceHolder.lockCanvas(null); 
         synchronized (mySurfaceHolder){ 
          draw(c); 
         } 
        }finally{ 
         if(c != null){ 
          mySurfaceHolder.unlockCanvasAndPost(c); 
         } 
        } 
       } 

     } 
     private void draw (Canvas canvas){ 
      try{ 
      canvas.drawBitmap(backgroundImg,0,0,null); 
      if (!onTitle){ 
       canvas.drawBitmap(mole, mole1x, mole1y,null); 
       canvas.drawBitmap(mole, mole2x, mole2y, null); 
       canvas.drawBitmap(mole, mole3x, mole3y, null); 
       canvas.drawBitmap(mole, mole4x, mole4y, null); 
       canvas.drawBitmap(mole, mole5x, mole5y, null); 
       canvas.drawBitmap(mole, mole6x, mole6y, null); 
       canvas.drawBitmap(mole, mole7x, mole7y, null); 
       canvas.drawBitmap(mask, (int) 50* drawScaleW, 
         (int) 450* drawScaleH, null); 
       canvas.drawBitmap(mask, (int) 150* drawScaleW, 
         (int) 400* drawScaleH,null); 
       canvas.drawBitmap(mask, (int) 250* drawScaleW, 
         (int) 450* drawScaleH,null); 
       canvas.drawBitmap(mask, (int) 350* drawScaleW, 
         (int) 400* drawScaleH, null); 
       canvas.drawBitmap(mask, (int) 450* drawScaleW,        
         (int) 450* drawScaleH, null); 
       canvas.drawBitmap(mask, (int) 550* drawScaleW, 
         (int) 400* drawScaleH,null); 
       canvas.drawBitmap(mask, (int) 650* drawScaleW, 
         (int) 450* drawScaleH, null); 
      } 
      }catch (Exception e){ 
      } 
     } 

     boolean doTouchEvent(MotionEvent event){ 
      synchronized(mySurfaceHolder){ 
       int eventaction = event.getAction(); 
       int X = (int)event.getX(); 
       int Y = (int)event.getY(); 

       switch(eventaction){ 

       case MotionEvent.ACTION_DOWN: 
        break; 

       case MotionEvent.ACTION_MOVE: 
        break; 

       case MotionEvent.ACTION_UP: 
        if(onTitle){ 
         backgroundImg= 
          BitmapFactory.decodeResource 
          (myContext.getResources(), 
          R.drawable.background); 
         backgroundImg = 
          Bitmap.createScaledBitmap 
          (backgroundImg, screenW, screenH, true); 
         mask = BitmapFactory.decodeResource(myContext.getResources(), 
           R.drawable.mask); 
         mole = BitmapFactory.decodeResource(myContext.getResources(), 
           R.drawable.mole); 
         scaleW = (float) screenW/ (float) 
           backgroundOriginW; 
         scaleH = (float) screenH/ (float) 
           backgroundOriginH; 
         mask = Bitmap.createScaledBitmap(mask, (int)(mask.getWidth()*scaleW), (int)(mask.getHeight()*scaleH), true); 
         mole = Bitmap.createScaledBitmap(mole, (int)(mole.getWidth()*scaleW), (int)(mole.getHeight()*scaleH), true); 
         onTitle = false; 
         pickActiveMole(); 
        } 

        break; 

       } 
     } 
      return true; 
     } 
     public void setSurfaceSize(int width, 
       int height){ 
      synchronized (mySurfaceHolder){ 
       screenW = width; 
       screenH = height; 
       backgroundImg = Bitmap.createScaledBitmap(
         backgroundImg, width, 
         height, true); 
       drawScaleW = (float) screenW/800; 
       drawScaleH = (float) screenH/600; 
       mole1x = (int) (55* drawScaleW); 
       mole2x = (int) (155* drawScaleW); 
       mole3x = (int) (255* drawScaleW); 
       mole4x = (int) (355* drawScaleW); 
       mole5x = (int) (455* drawScaleW); 
       mole6x = (int) (555* drawScaleW); 
       mole7x = (int) (655* drawScaleW); 
       mole1y = (int) (475* drawScaleH); 
       mole2y = (int) (425* drawScaleH); 
       mole3y = (int) (475* drawScaleH); 
       mole4y = (int) (425* drawScaleH); 
       mole5y = (int) (475* drawScaleH); 
       mole6y = (int) (425* drawScaleH); 
       mole7y = (int) (475* drawScaleH); 
      } 
     } 
     public void setRunning(boolean b){ 
      running = b; 
     } 
     private void animateMoles(){ 
      if(activeMole == 1){ 
       if(moleRising){ 
        mole1y -= moleRate; 
       }else if (moleSinking){ 
        mole1y += moleRate; 
       } 
       if(mole1y >= (int) (475* drawScaleH) || moleJustHit){ 
        mole1y = (int) (475* drawScaleH); 
        pickActiveMole(); 
       } 
       if(mole1y <= (int) (300* drawScaleH)){ 
        mole1y = (int) (300* drawScaleH); 
        moleRising = false; 
        moleSinking = true; 
       } 
      } 
      if(activeMole == 2){ 
       if(moleRising){ 
        mole2y -= moleRate; 
       }else if (moleSinking){ 
        mole2y += moleRate; 
       } 
       if(mole2y >= (int) (425* drawScaleH) || moleJustHit){ 
        mole2y = (int) (425* drawScaleH); 
        pickActiveMole(); 
       } 
       if(mole2y <= (int) (250* drawScaleH)){ 
        mole2y = (int) (250* drawScaleH); 
        moleRising = false; 
        moleSinking = true; 
       } 
      } 
      if(activeMole == 3){ 
       if(moleRising){ 
        mole3y -= moleRate; 
       }else if (moleSinking){ 
        mole3y += moleRate; 
       } 
       if(mole3y >= (int) (475* drawScaleH) || moleJustHit){ 
        mole3y = (int) (475* drawScaleH); 
        pickActiveMole(); 
       } 
       if(mole3y <= (int) (300* drawScaleH)){ 
        mole3y = (int) (300* drawScaleH); 
        moleRising = false; 
        moleSinking = true; 
       } 
      } 
      if(activeMole == 4){ 
       if(moleRising){ 
        mole4y -= moleRate; 
       }else if (moleSinking){ 
        mole4y += moleRate; 
       } 
       if(mole4y >= (int) (425* drawScaleH) || moleJustHit){ 
        mole4y = (int) (425* drawScaleH); 
        pickActiveMole(); 
       } 
       if(mole4y <= (int) (250* drawScaleH)){ 
        mole4y = (int) (250* drawScaleH); 
        moleRising = false; 
        moleSinking = true; 
       } 
      } 
      if(activeMole == 5){ 
       if(moleRising){ 
        mole5y -= moleRate; 
       }else if (moleSinking){ 
        mole5y += moleRate; 
       } 
       if(mole5y >= (int) (475* drawScaleH) || moleJustHit){ 
        mole5y = (int) (475* drawScaleH); 
        pickActiveMole(); 
       } 
       if(mole5y <= (int) (300* drawScaleH)){ 
        mole5y = (int) (300* drawScaleH); 
        moleRising = false; 
        moleSinking = true; 
       } 
      } 
      if(activeMole == 6){ 
       if(moleRising){ 
        mole6y -= moleRate; 
       }else if (moleSinking){ 
        mole6y += moleRate; 
       } 
       if(mole6y >= (int) (425* drawScaleH) || moleJustHit){ 
        mole6y = (int) (425* drawScaleH); 
        pickActiveMole(); 
       } 
       if(mole6y <= (int) (250* drawScaleH)){ 
        mole6y = (int) (250* drawScaleH); 
        moleRising = false; 
        moleSinking = true; 
       } 
      } 
      if(activeMole == 7){ 
       if(moleRising){ 
        mole7y -= moleRate; 
       }else if (moleSinking){ 
        mole7y += moleRate; 
       } 
       if(mole7y >= (int) (475* drawScaleH) || moleJustHit){ 
        mole7y = (int) (475* drawScaleH); 
        pickActiveMole(); 
       } 
       if(mole7y <= (int) (300* drawScaleH)){ 
        mole7y = (int) (300* drawScaleH); 
        moleRising = false; 
        moleSinking = true; 
       } 
      } 
     } 
     private void pickActiveMole(){ 
      activeMole = new Random().nextInt(7) + 1; 
      moleRising = true; 
      moleSinking = false; 
     } 

    } 
    @Override 
    public boolean onTouchEvent(MotionEvent event){ 
    return thread.doTouchEvent(event); 
    } 
    @Override 
    public void surfaceChanged(SurfaceHolder holder, int 
     format, int width, int height){ 
    thread.setSurfaceSize(width, height); 
    } 

@Override public void surfaceCreated(SurfaceHolder holder){ 
    thread.setRunning(true); 
    if(thread.getState() == Thread.State.NEW){ 
     thread.start(); 
    } 
} 
@Override 
public void surfaceDestroyed(SurfaceHolder holder){ 
    thread.setRunning(false); 
} 
} 

내 WhackAMoleActivity

11-29 17:58:51.008: E/InputEventReceiver(21188): Exception dispatching input event. 
11-29 17:58:51.008: E/MessageQueue-JNI(21188): Exception in MessageQueue callback: handleReceiveCallback 
11-29 17:58:51.048: E/MessageQueue-JNI(21188): java.lang.IllegalArgumentException: unknown bitmap configuration 
11-29 17:58:51.048: E/MessageQueue-JNI(21188): at android.graphics.Bitmap.nativeCreate(Native Method) 
11-29 17:58:51.048: E/MessageQueue-JNI(21188): at android.graphics.Bitmap.createBitmap(Bitmap.java:929) 
11-29 17:58:51.048: E/MessageQueue-JNI(21188): at android.graphics.Bitmap.createBitmap(Bitmap.java:902) 
11-29 17:58:51.048: E/MessageQueue-JNI(21188): at android.graphics.Bitmap.createBitmap(Bitmap.java:834) 
11-29 17:58:51.048: E/MessageQueue-JNI(21188): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:710) 
11-29 17:58:51.048: E/MessageQueue-JNI(21188): at com.agpfd.whackamole.WhackAMoleView$WhackAMoleThread.doTouchEvent(WhackAMoleView.java:151) 

어떤 도움을 크게 감상 할 수

public class WhackAMoleActivity extends Activity{ 

    private static final int TOGGLE_SOUND = 1; 
    private boolean soundEnabled = true; 

    private WhackAMoleView myWhackAMoleView; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags 
      (WindowManager.LayoutParams.FLAG_FULLSCREEN, 
      WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.whackamole_layout); 
     myWhackAMoleView = (WhackAMoleView) 
      findViewById(R.id.mole); 
     myWhackAMoleView.setKeepScreenOn(true); 
    } 
    public boolean onCreateOptionsMenu(Menu menu){ 
     MenuItem toggleSound = menu.add(0, TOGGLE_SOUND, 
      0,"Toggle Sound"); 
     return true; 
    } 
    public boolean onOptionsItemSelected(MenuItem item){ 
     switch (item.getItemId()){ 
     case TOGGLE_SOUND: 
      String soundEnabledText = "Sound On"; 
      if(soundEnabled){ 
       soundEnabled=false; 
       soundEnabledText="Sound Off"; 
      }else{ 
       soundEnabled = true; 
      } 
      Toast.makeText(this, soundEnabledText, Toast.LENGTH_SHORT).show(); 
      break; 
     } 
     return false; 
    } 
} 

그리고 오류 메시지 ..., 감사합니다 :)

+0

'WhackAMoleView'의 151 번째 줄은 무엇입니까? – stkent

+0

mask = Bitmap.createScaledBitmap (마스크, (int) (마스크 .getWidth() * scaleW), (int) (마스크 .getHeight() * scaleH), true); (mole.getHeight() * scaleH), true); 그들은 DoTouchEvent() –

+0

내부에있어 151 번과 152 번 줄을 주석 처리하면 충돌이 발생하지 않습니다. 그러나 나는 그들에게 무엇이 잘못되었는지 알 수 없었다. 또한 오류에 대한 더 많은 줄이 있지만 처음 몇 줄에 문제가있을 것이라고 생각하는 게시 줄을 몇 줄인지 확신 할 수 없었습니다. –

답변

0

이봐, 난 그냥 WhackAMoleThread 생성자 내부 ... 그것을 알아 냈어 내가 선을 수행하려고 할 때 나는 그렇게

BackgroundOriginW 

    BackgroundOriginH 

의 값을 선언하지

scaleW = (float) screenW/ (float) 
          backgroundOriginW; 

scaleH = (float) screenH/ (float) 
          backgroundOriginH; 

그들이받은 적이 값의가 필요

또한 내 잘못으로, 내 변명 선언을 게시하지 않았기 때문에 여러분을 보여주기가 어려웠을 것입니다. ...

도움을 주셔서 감사합니다. 감사합니다.

관련 문제