运行时错误英寸×+宽度必须< = bitmap.width()"在某些设备上 [英] Runtime error "x + width must be <= bitmap.width()" on some devices

查看:112
本文介绍了运行时错误英寸×+宽度必须< = bitmap.width()"在某些设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建基本上创建了一个基于Rects和字形菜单中的程序。出于某种原因,这个code工作在模拟器上和我的朋友的手机,但它并没有对我的工作。我开始相信,也许我的手机太旧(即彗星系列)。然而,像任何好的手机应用开发,我想我的应用程序在任何类型的android手机的工作,所以我在寻找这个问题相当彻底。我得到一个错误说:


  

致:java.lang.IllegalArgumentException异常:X +宽度必须< = bitmap.width()


我使用位图的唯一地方是在我的字形类张贴在这里:

 包文本;进口的java.util.HashMap;
进口的java.util.Map;进口android.graphics.Bitmap;
进口android.graphics.Canvas;公共类字形{私人位图位图;私人地图<性格,位图>字形=新的HashMap<性格,位图>(62);私人诠释宽度;
私人诠释高度;私人的char [] charactersL =新的char [] {'A','B','C','D','E','F','G','H','我','J' ,'K','L','M','N','O','p','q','R','S','T','U','v',' W','X','Y','Z'};
私人的char [] charactersU =新的char [] {'A','B','C','D','E','F','G','H','我','J' ,K,L,M,'N','O','P','Q','R','S','T','U','V',' W','X','Y','Z'};
私人的char []号码=新的char [] {'1','2','3','4','5','6','7','8','9','0' };公众诠释的getWidth(){
    返回宽度;
}公众诠释的getHeight(){
    返回高度;
}公共字形(位图位图){
    超();
    this.bitmap =位图;
    this.width = 12;
    this.height = 18;    的for(int i = 0; I< 26;我++){
        glyphs.put(charactersL [I],Bitmap.createBitmap(位图,0 +(我*宽度),0,宽度,高度));
    }    的for(int i = 0; I< 26;我++){
        glyphs.put(charactersU [I],Bitmap.createBitmap(位图,0 +(我*宽度),24,宽度,高度));
    }    对(INT I = 0; I&小于10;我++){
        glyphs.put(数字[I],Bitmap.createBitmap(位图,0 +(我*宽度),48,宽度,高度));
    }
}公共位图getBitmap(){
    返回位图;
}公共drawString之无效(帆布油画,字符串文字,诠释的x,int y)对{
    如果(帆布== NULL){
        //返回标签
    }
    的for(int i = 0; I< text.length();我++){
        字符ch = text.charAt(ⅰ);
        如果(glyphs.get(CH)!= NULL){
            canvas.drawBitmap(glyphs.get(CH),X +(I *宽),Y,NULL);
        }
    }
}
}

不过,这一方案适用于其他手机完美的罚款。我不知道是什么原因它崩溃了我的旧POS手机。


解决方案

  1. 检查你的手机的Andr​​oid版本和那些你的朋友。

  2. 您会发现您的code,它导致错误的路线。

  3. 把这里不仅错误消息本身,而是整个堆栈。

  4. 对于未来,安装在Eclipse中的Andr​​oid源$ C ​​$ CS。所以你会发现完全是,那里的错误发生。它帮助很多了解。

I'm creating a program that essentially creates a menu based on Rects and glyphs. For some reason this code works on the emulator AND my friends phone, but it doesn't work on mine. I'm starting to believe perhaps my phone is too old (being a comet series). However, like any good phone app dev, I want my app to work on any type of android phone, so I'm looking into this issue quite thoroughly. I get an error saying:

Caused by: java.lang.IllegalArgumentException: x + width must be <= bitmap.width()

The only place I use bitmap is in my glyphs class posted here:

package text;

import java.util.HashMap;
import java.util.Map;

import android.graphics.Bitmap;
import android.graphics.Canvas;

public class Glyphs {

private Bitmap bitmap;

private Map<Character, Bitmap> glyphs = new HashMap<Character, Bitmap>(62);

private int width;
private int height;

private char[] charactersL = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
private char[] charactersU = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
private char[] numbers = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };

public int getWidth(){
    return width;
}

public int getHeight(){
    return height;
}

public Glyphs(Bitmap bitmap){
    super();
    this.bitmap = bitmap;
    this.width = 12;
    this.height = 18;

    for(int i = 0; i < 26; i++){
        glyphs.put(charactersL[i], Bitmap.createBitmap(bitmap, 0 + (i * width), 0, width, height));
    }

    for(int i = 0; i < 26; i++){
        glyphs.put(charactersU[i], Bitmap.createBitmap(bitmap, 0 + (i * width), 24, width, height));
    }

    for(int i = 0; i < 10; i++){
        glyphs.put(numbers[i], Bitmap.createBitmap(bitmap, 0 + (i * width), 48, width, height));
    }
}

public Bitmap getBitmap(){
    return bitmap;
}

public void drawString(Canvas canvas, String text, int x, int y){
    if(canvas == null){
        //return a tag
    }
    for(int i = 0; i < text.length(); i++){
        Character ch = text.charAt(i);
        if(glyphs.get(ch) != null){
            canvas.drawBitmap(glyphs.get(ch), x + (i * width), y, null);
        }
    }
}
}

However, this program works perfectly fine on other phones. I'm not exactly sure why it crashes on my old pos phone.

解决方案

  1. Check the Android versions of your phone and those of your friends.
  2. You should find the line of your code that is causing the error.
  3. Put here not only the error message itself, but the whole stack.
  4. For future, install on Eclipse the Android source codes. So you'll find exactly, where the error happens. It helps much to understand.

这篇关于运行时错误英寸×+宽度必须&LT; = bitmap.width()&QUOT;在某些设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆