Tag: 例外

如何提前了解OutOfMemory或StackOverflow错误

在Java中,有没有办法知道StackOverflow错误或OutOfMemoryexception可能很快发生? 如果一个能够以编程方式获取内存使用情况统计信息,并且如果提前知道在OutOfMemoryexception之前需要使用多少内存,则OutOfMemoryexception可能更容易捕获。 但这些价值是否可知? 对于StackOverflow错误,有没有办法获得递归深度,以及如何知道递归深度的哪个值会导致错误发生? 通过提前知道这些错误是否会发生,我觉得我可以更优雅地恢复应用程序,而不是看着它崩溃。

Java,特定于类的exception与标准exception

我一直在更新现有的库以抛出exception,以帮助改善使用该库的人员的调试。 起初,我认为我会定义特定于每个类的exception,但事实certificate,大多数exception只是现有运行时exception的扩展(例如, FooNegativeIntArgumentException extends IllegalArgumentException , FooNullBarException extends NullPointerException )和特定消息。 定义新例外与使用现有例外的权衡有何不同? 有没有任何惯例/最佳做法? 此外,鉴于需要向后兼容性,大多数(如果不是全部)这些exception都是运行时exception。

最常见的已检查和未检查的Javaexception?

据我所知,如果没有逐个查找API文档,就无法找出方法抛出的exception。 由于这是不可取的,我想反转研究并询问您在处理时遇到的最常见的exception和运行时exception: 铸件 数组 Vector,ArrayList,HashMap等 IO(文件类,流,filter,……) 对象序列化 线程(wait(),sleep()等) 或任何被认为是“基本Java”的东西 我意识到这可能是主观和无聊的,但这是一个class级测试,我真的不知道更好。

在java中设置exception原因

我可以看到捕获exception,我可以打印e.getCause() ,虽然它总是为null 。 我是否需要将其设置在某个地方,或者是否缺少将原因设置为null?

Junit测试用例exception

public class TipException extends Exception { private final Object mSource; private final Object mObjectInError; private final Throwable mCause; public TipException(Object source, Object objectInError, Throwable cause, String message) { super(message); this.mSource = source; this.mObjectInError = objectInError; this.mCause = cause; } } 我需要为这个有更多方法的简单exception类编写Junit测试用例。 但由于我是Junit的新手,Idk如何在这里传递一些exception对象。 任何帮助将不胜感激。

Java,使用扫描程序,exception

有人能告诉我我做错了什么,这部分代码应该扫描餐馆的名称,菜单名称和菜单项的名称及其价格,但它给了我一些例外,它似乎完全跳过了第一个扫描,只需跳到第二个,理想情况下它应扫描1个包含1个菜单的餐厅,其中包含2个菜单项及其名称和价格 String newRestaurant, newMenu; String[] newMenuItem = { “”, “” }; double[] price = {0.0, 0.0}; int x = 0; System.out.println(“—————————————“); System.out.println(“CREATE A RESTAURANT, MENUS, and MENU ITEMS:”); System.out.println(“Please input the name of the new Restaurant:”); newRestaurant = scan.nextLine(); System.out.println(“What is the name of the Menu you wish to create (type ‘none’, if you are […]

Java编程exception

谁能帮我? 我不明白这个例外: Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 9 at java.lang.String.charAt(Unknown Source) at charPerLine.main(charPerLine.java:13) 这是负责的代码: import java.util.*; public class charPerLine { public static void main(String[] args)throws StringIndexOutOfBoundsException { Scanner sc=new Scanner(System.in); System.out.print(“Type any name:”); String s=sc.next(); int j= s.length()+1; for(int i=0;i<=j;i++){ System.out.println(s.charAt(i)); } } }

Junit 4.12问题测试exception

我有一个简单的方法试图获取一些文件。 我想测试文件何时不存在,这就是我的问题开始的地方。 测试一直在失败。 方法类似于: public Configuration populateConfigs(Configuration config) throws UnRetriableException { try { …. } catch (IOException | ConfigurationException e) { log.error(” getConfiguration : “, e); throw new UnRetriableException(e); } throw new UnRetriableException(“problem getting config files.”); } 在我的测试中,我尝试了两个单独的解决方 使用SO解决方案中建议的新样式 @Rule public ExpectedException exception = ExpectedException.none(); @Test public void testPopulateConfigurationMissing() throws Exception { exception.expect(UnRetriableException.class); DefaultConfigHandler configurationFactory […]

Android- java.lang.IllegalArgumentException

我已经看过这个问题 。 但无法弄清楚问题是什么。 我在我的ImageSyncReciever类中使用BackgroundMail在后台发送电子邮件。 但是当发送电子邮件时,我的应用程序崩溃,同时给我以下错误 致命exception:主要过程:com.thumbsol.accuratemobileassetsmanagament,PID:7480 java.lang.IllegalArgumentException:View = com.android.internal.policy.impl.PhoneWindow $ DecorView {300e55de VE …. R ….. I 。 在android.view.WindowManagerImpl的android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:353)的android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:434)上没有附加到窗口管理器的0,0-0,0}。在android.app.Dialog.dismissDialog(Dialog.java:382)的android.app.Dialog.dismiss(Dialog.java:365)中删除ViewImmediate(WindowManagerImpl.java:116),位于com.creativityapps.gmailbackgroundlibrary.BackgroundMail $ SendEmailTask​​.onPostExecute (BackgroundMail.java:302)at com.creativityapps.gmailbackgroundlibrary.BackgroundMail $ SendEmailTask​​.onPostExecute(BackgroundMail.java:265)at android.os.AsyncTask.finish(AsyncTask.java:636)at android.os.AsyncTask.access $ 500 (AsyncTask.java:177)在android.os.Loper.loop(Looper。)的android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:653)android.os.Handler.dispatchMessage(Handler.java:111)。 java:194)在android.app.ActivityThread.main(ActivityThread.java:5660)at java.lang.reflect.Method.invoke(Native Method)at j com.android.internal.os.ZygoteInit.main中的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:963)中的ava.lang.reflect.Method.invoke(Method.java:372) ZygoteInit.java:758) 以下是我发送电子邮件的代码 if (response.body().getStatus().equals(“OK”)) { snapManager.updateSnapStatus(AssetsManagementContract.SnapEntry.COLUMN_SITE_SNAP, snap.getSnapName(), Constants.SNAP_SYNCED); Intent broadcastSyc = new Intent(); broadcastSyc.setAction(Common.GetSyncImageAction()); broadcastSyc.putExtra(“STATUS”, true); […]

获取exceptionOutofMemoryError

我有人在我的应用程序上加载一堆图像时出错,我不知道是什么导致它。 这是他得到的错误。 LINE 135位于底部。 我在想他手机上的内存不足。 他正在使用2010年制作的Desire HD。这种方法的作用是从服务器获取图像并将其保存在哈希映射中。 随着它显示在屏幕上。 关于如何防止这个OUTMEMORYERROR的任何想法? 我正在考虑设置一个计数器,如果有超过20个图像,则清除哈希映射。 logcat的: java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:200) at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) at java.util.concurrent.FutureTask.setException(FutureTask.java:125) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) at java.lang.Thread.run(Thread.java:1019) Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) at android.graphics.drawable.Drawable.createFromStream(Drawable.java:657) at com.codalata.craigslistchecker.GETTHEIMAGE$ITask.doInBackground(GETTHEIMAGE.java:135) […]