朋友,当我尝试在我的应用中使用setPixel(x,y,color)时,它会返回NullPointerException并停止工作。这是我的代码。请帮我摆脱错误。提前致谢
decode=(Button)findViewById(R.id.button1);
decode.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
try
{
Bitmap result = BitmapFactory.decodeFile(filePath);
int x=result.getPixel(10, 10);
int pixelAlpha= Color.alpha(x);
int red = 65;// represent character A
int green= Color.green(x);
int blue= Color.blue(x);
int newPixel=Color.argb(pixelAlpha,red,green,blue);
result.setPixel(10, 10, newPixel);
ImageView myNewImage=(ImageView)findViewById(R.id.imageView2);
myNewImage.setImageBitmap(result);
}
catch(Exception exc)
{
Toast.makeText(getBaseContext(), "Exception : "+exc, Toast.LENGTH_LONG).show();
}
}
});
答案 0 :(得分:2)
看起来Bitmap result = BitmapFactory.decodeFile(filePath);
无法正确解码您的filePath。确保结果不为null且filePath正确。