我在使用URLImage的屏幕中显示了2张图片。在某些设备中,例如华为(MARSHMALLOW),它会产生零点异常,即。
发生内部应用程序错误: java.lang.nullPointerException:尝试调用虚方法' int android.graphics.Bitmap.getWidth()'在null对象引用上。
然而,在模拟器或三星设备中从未出现过问题。
EncodedImage placeholder = (EncodedImage) res.getImage("home_car.png");
placeholder = (EncodedImage) placeholder.scaledEncoded((Display.getInstance().getDisplayWidth() / 3), -1);
EncodedImage logoPlaceholder = (EncodedImage) res.getImage("carLogo.jpg");
String carImagePreferences = Preferences.get(AllUrl.carImage, "");
String modelLogoPreferences = Preferences.get(AllUrl.modelLogo, "");
Label vehicleNameLabel = new Label();
if (!"".equals(modelLogoPreferences)) {
vehicleNameLabel.setIcon(URLImage.createToStorage(logoPlaceholder, modelLogoPreferences, AllUrl.baseUrlCarModel
+ Preferences.get(AllUrl.modelLogo, null), URLImage.RESIZE_SCALE));
} else {
vehicleNameLabel.setIcon(logoPlaceholder);
}
Label homeCarLabel = new Label();
if (!"".equals(carImagePreferences)) {
homeCarLabel.setIcon(URLImage.createToStorage(placeholder, carImagePreferences, AllUrl.baseUrlCarModel
+ Preferences.get(AllUrl.carImage, null), URLImage.RESIZE_SCALE));
} else {
homeCarLabel.setIcon(placeholder);
}
错误日志:
03-28 22:34:05.429 22121-22135 / com.bbeck.myProject D / skia:--- decoder-> decode返回false 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject D / Nehhpa:[EDT] 0:2:25,856 - 例外:java.lang.IllegalArgumentException - 为给定的图像数据创建图像失败:211148 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:java.lang.IllegalArgumentException:为给定的图像数据创建图像失败:211148 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Image.createImage(Image.java:655) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.EncodedImage.getInternal(EncodedImage.java:366) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.EncodedImage.getInternalImpl(EncodedImage.java:341) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.EncodedImage.getWidth(EncodedImage.java:512) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.URLImage $ 2.adaptImage(URLImage.java:103) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.URLImage $ DownloadCompleted.actionPerformed(URLImage.java:239) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.URLImage $ 4.onSucess(URLImage.java:302) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.URLImage $ 4.onSucess(URLImage.java:298) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.util.CallbackDispatcher.run(CallbackDispatcher.java:53) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Display.processSerialCalls(Display.java:1129) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Display.edtLoopImpl(Display.java:1073) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Display.mainEDTLoop(Display.java:961) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.impl.CodenameOneThread $ 1.run(CodenameOneThread.java:60) 03-28 22:34:05.429 22121-22135 / com.bbeck.myProject W / System.err:at java.lang.Thread.run(Thread.java:818) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject D / skia:--- decoder-> decode返回false 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject D / Nehhpa:[EDT] 0:2:25,887 - 异常:java.lang.NullPointerException - 尝试调用虚拟方法' int android。 graphics.Bitmap.getWidth()'在null对象引用上 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:java.lang.NullPointerException:尝试调用虚方法' int android.graphics.Bitmap.getWidth()&# 39;在null对象引用上 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:748) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.impl.android.AndroidImplementation.scale(AndroidImplementation.java:1735) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Image.scale(Image.java:1008) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Image.scaledImpl(Image.java:954) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Image.scaled(Image.java:919) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.impl.android.AndroidImplementation $ 33.save(AndroidImplementation.java:6617) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.EncodedImage.scaledEncoded(EncodedImage.java:627) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.URLImage $ 2.adaptImage(URLImage.java:104) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.URLImage $ DownloadCompleted.actionPerformed(URLImage.java:239) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.URLImage $ 4.onSucess(URLImage.java:302) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.URLImage $ 4.onSucess(URLImage.java:298) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.util.CallbackDispatcher.run(CallbackDispatcher.java:53) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Display.processSerialCalls(Display.java:1129) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Display.edtLoopImpl(Display.java:1073) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.Display.mainEDTLoop(Display.java:961) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at com.codename1.impl.CodenameOneThread $ 1.run(CodenameOneThread.java:60) 03-28 22:34:05.459 22121-22135 / com.bbeck.myProject W / System.err:at java.lang.Thread.run(Thread.java:818)
答案 0 :(得分:0)
当服务器返回图像的无效数据但未返回正确的HTTP错误代码时,会发生这种情况。因此,如果您的服务器返回损坏的图像,例如一个带有200个响应代码的HTML页面(或30x响应之后)然后我们认为它是图像并尝试下载/加载它。
我们会尝试为此案例添加更好的处理方式,以便将来再次尝试下载。但这并不理想,因此您需要跟踪此图像。
我建议使用网络管理器查看请求/响应中出现的问题。