Tag: exception

多捕获块中的引用类型的exception问题

e的类型为Exception,但在下面的代码中打印Exception1: class Exception1 extends IOException {void info(){}} class Exception2 extends Exception {} class TestMultiCatch { public static void main(String args[]) { try { int a = 10; if (a <= 10) throw new Exception1(); else throw new Exception2(); } catch (Exception1 | Exception2 e) { e.info(); //line 1 error "The method info() is undefined for […]

我为什么得到例外?

请帮忙。 从扫描程序的提示显示到控制台后,我收到此错误: Exception in thread “main” java.util.IllegalFormatPrecisionException: 2 at java.util.Formatter$FormatSpecifier.checkInteger(Unknown Source) at java.util.Formatter$FormatSpecifier.(Unknown Source) at java.util.Formatter.parse(Unknown Source) at java.util.Formatter.format(Unknown Source) at java.io.PrintStream.format(Unknown Source) at java.io.PrintStream.printf(Unknown Source) at Project6.main(Project6.java:56) 问题来自printf吗? 我检查了格式,看起来是对的。 这是程序: import javax.swing.JOptionPane; // allows for message dialog import java.util.Scanner; // allows for Scanner object to be used import java.text.DecimalFormat; // allows for formatting numbers […]

Android XML文件java.lang.nullpointerexception

我正在建立一个全新的Android项目。 这不是我的第一个Android应用程序,所以我更加沮丧无法摆脱这个错误… 我使用XML文件,目前只有3个项目,并且XML选项卡中没有错误: 很简单,耶? 但是,视觉选项卡不会渲染cadremenu drawable(但“喜欢”)…但是cadremenu.png位于drawable文件夹中! 我可以启动应用程序,但只渲染背景…我真的不知道该怎么做… xml文件返回此exception java.lang.NullPointerException at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:598) at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:120) at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:102) at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:233) at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:782) at android.view.View.(View.java:3554) at android.view.View.(View.java:3484) at android.view.ViewGroup.(ViewGroup.java:464) at android.widget.RelativeLayout.(RelativeLayout.java:236) at sun.reflect.GeneratedConstructorAccessor37.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at android.view.LayoutInflater.createView(LayoutInflater.java:594) at android.view.BridgeInflater.onCreateView(BridgeInflater.java:86) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:131) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64) at android.view.LayoutInflater.rInflate(LayoutInflater.java:727) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:373) at […]

本地Tomcat环境无法启动

我正在尝试运行本地Tomcat环境,并且始终遇到以下错误: Can’t load log handler “2localhost.org.apache.juli.FileHandler” java.lang.ClassNotFoundException: 2localhost.org.apache.juli.FileHandler java.lang.ClassNotFoundException: 2localhost.org.apache.juli.FileHandler at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) 我已经在%TOMCAT_HOME%/ bin中确认了’tomcat-juli.jar’的存在。 把头发拉出来。 它几乎消失了……非常感谢您提供的任何帮助。 谢谢! 🙂

为什么我的程序在文件存在时捕获/抛出FileNotFoundException?

Java新手在这里! 我正在编写一个程序来练习读取输入和将输出写入文件。 我已经完成了程序的编码,但是当我运行它时,程序只是捕获并继续FileNotFoundException。 该文件位于程序的源文件夹中,我甚至尝试将其放在与程序相关的每个文件夹中。 我试过了: 声明方法标头中的exception 使用try / catch块围绕相关部分。 以上两者在一起。 这是导致问题的相关代码。 有什么东西突然出现,我错过了吗? public static void main(String[] args) throws FileNotFoundException { Scanner keyboard = new Scanner(System.in); String playerHighestScore = “”, playerLowestScore = “”; int numPlayers = 0, scoreHighest = 0, scoreLowest = 0; System.out.println(“Enter an input file name: “); String inputFileName = keyboard.nextLine(); String outputFileName = […]

在Java中安排例外

我正在开发一个需要从给定URL下载文件的任务,其中一个要求是它可以处理网络故障和exception。 在我的实现中,我有一个DonwloadManager为每个URL分配一个线程,以免被阻塞。 问题是我不知道如何通过代码模拟失败和exception,我尝试使用Quartz作为调度程序和只抛出exception的作业,但据我所知,调度程序在不同的线程上运行,所以这不会完全影响下载线程。 有没有办法在下载线程中模拟exception? 以下是我的更多见解的代码: public class DownloadManager { int allocatedMemory = 0; void validateURLs(String[] urls) { if (urls.length == 0) { throw new IllegalArgumentException(“URLs List is empty”); } } public ArrayList downloadURLs(String[] urls, int memorySize) throws Exception { validateURLs(urls); ExecutorService executor = Executors.newWorkStealingPool(); CompletionService completionService = new ExecutorCompletionService(executor); ArrayList downloadStatus = new ArrayList(); allocatedMemory […]

Java:密码包(加密和解密)。 无效的密钥错误

我正在使用静态方法创建一个类来使用javax.crypto加密和解密消息。 我有2个静态方法,使用ecipher和dcipher来做他们所要做的事情,我需要初始化一些变量(也是静态的)。 但是当我尝试使用它时,我得到了带有ecipher.init(…)参数的InvalidKeyException。 我找不到原因。 这是代码: private static byte[] raw = {-31, 17, 7, -34, 59, -61, -60, -16, 26, 87, -35, 114, 0, -53, 99, -116, -82, -122, 68, 47, -3, -17, -21, -82, -50, 126, 119, -106, -119, -5, 109, 98}; private static SecretKeySpec skeySpec; private static Cipher ecipher; private static Cipher dcipher; static […]

Netbeans FileReader FileNotFound文件在文件夹中时出现exception?

所以问题是我每次尝试在NetBeans或Eclips上加载下面的代码时都会抛出exception,但是当我尝试通过TextMate运行它时一切正常! 我试着把绝对地址,改成文本文件等..没有帮助! 有人可以帮助我或告诉它为什么不能用IDE运行? 谢谢 void loadFile() { try { list = new LinkedList(); FileReader read = new FileReader(“a.txt”); Scanner scan = new Scanner(read); while (scan.hasNextLine()) { String Line = scan.nextLine(); String[] subArray = new String[5]; subArray = Line.split(“,”); int a = Integer.parseInt(subArray[4]); list.add(new Patient(Integer.parseInt(subArray[0]), subArray[1], subArray[2], subArray[3], a)); } } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(null, […]

不可解除的日期例外

我目前正在使用Java编写一些简单的项目,并且我在以下字符串中有日期: String dateString = “Sun 7/14 03:44 AM 2013”; 并希望将此字符串转换为Date对象。 我正在使用以下代码行来做到这一点。 我搜索网站并找到解决方案如何使用DateFormatter执行此操作: DateFormat format = new SimpleDateFormat(“EEE M/dd hh:mm a yyyy”); Date d = format.parse(dateString); 但我可能做错了什么,因为我总是得到例外: Unparseable date: “Sun 7/14 03:44 AM 2013” 这似乎是我正在使用的模式的问题,但尝试了不同的模式,没有任何工作。

在Java中提取用户友好的exception详细信息

我有一个我正在处理的J2EE Web应用程序,当发生exception时,我想获得有关exception的一些基本细节并记录它。 我正在记录的消息应该是非常基本的,这可能对运行Web服务器的人有意义。 使用e.getMessage()是最好的记录吗? 谢谢。