【Java 异常分类】教程文章相关的互联网学习教程文章

java-onPostExecute()中的ArrayList空指针异常【代码】

在ArrayList中获取NullPointerException.我正在使用下面的行记录ArrayList的大小,但是我总是得到NPE. 可能是什么原因?Log.d("catArrayList:Size:New", ""+categoryArrayList.size());这是更多代码:protected void onPostExecute(Boolean result) {dialog.cancel(); Log.d("catArrayList:Size", ""+categoryArrayList.size());Log.d("typArrayList:Size", ""+typeArrayList.size());Log.d("serArrayList:Size", "...

java-如何在自定义异常中打印堆栈跟踪?【代码】

我定义了一个自定义异常,如下所示:package source.exception;import org.slf4j.Logger; import org.slf4j.LoggerFactory;public class ValidationException extends Exception {private static final Logger logger = LoggerFactory.getLogger("source.exception.ValidationException");public ValidationException(String message){super(message);ValidationException e = new ValidationException();logger.error("Exception :...

java-如何捕获try-with-resource语句中close方法引发的异常【代码】

我正在阅读有关Java中try-with-resource语句的信息,该语句可用于指定任意数量的资源.try (Resource1 res1 = initialize_code; Resource1 res2 = initialize_code; ...) {statement; }现在,当try块退出时(正常或异常引发异常),将调用所有资源对象的close方法.但是某些关闭方法可能会引发异常.如果close自身抛出异常,在这种情况下会发生什么?解决方法:But some close methods can throw exceptions.是的,他们可以,你是对的.同样,资...

java-不引发测试异常【代码】

我正在创建一个集成测试:@RunWith(CdiRunner.class) @AdditionalClasses({FollowUpActivityRepository.class, SettingsPropertiesProducer.class}) public class FollowUpActivityFeaturesTest {@Inject protected FollowUpActivityService fuaService;@Testpublic void DigitalInputTOFollowUpActivityFIELDS(){ FollowUpActivityDTO dto = new FollowUpActivityDTO();dto.setId("id");dto.setTimestamp(Date.from(Instant.now()...

java-在Spring MVC控制器方法中,添加RedirectAttributes参数会导致“模型的键无值”异常【代码】

我有以下Spring MVC控制器方法:@RequestMapping(value = "/tournament/{id}/set-format", method = RequestMethod.POST) public String processSetTournamentFormat(Model model,@ModelAttribute("formatSettings") FormatSettings formatSettings,@AuthenticationPrincipal UserAccount currentUser,@PathVariable("id") int tournamentId,RedirectAttributes redirectAttributes)throws TournamentAccessDenied, TournamentNotF...

java-在哪里抛出HTTP运行时异常【代码】

假设我有以下运行时异常:@ResponseStatus(HttpStatus.EXPECTATION_FAILED) public class ExpectationsFailedException extends RuntimeException {public ExpectationsFailedException(String message) {super(message);} }我的问题是在服务层中抛出先前的HTTP异常是否可以,还是应该从控制器中抛出该异常:@Service public class UserService {@Autowired...public void addUser(final String email, final String username, fina...

尝试用Java捕获-发生异常时会发生什么?【代码】

我对Java中的try / catch和异常有疑问.我知道这应该是基础知识,但是我想我对这是如何工作的了解有所缺失.给出以下示例代码:String res = "";try {res = methodThatCanThrowException();res = res + ".txt"; } catch (Exception e) {res = "somethingwentwrong.txt"; }return res;我是否保证在try和catch块中都不会设置“ res”?如果在try块中的方法调用中引发了异常,则代码控件将直接转到catch块,对吗?有没有在try和catch块中都...

Java-HTTP状态500-Servlet Spring-Dispatcher的Servlet.init()抛出异常【代码】

我正在学习Spring MVC,当我尝试运行html文件时,它给出错误HTTP状态500-servlet spring-dispatcher抛出Servlet.init()异常 这是我的web.xml<?xml version="1.0" encoding="UTF-8"?>`<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version...

java-Spring Boot Security:使用自定义身份验证过滤器的异常处理【代码】

我正在使用Spring Boot Spring Security(java config).我的问题是旧的,但是我发现的所有信息都已部分过时,并且大部分包含xml-config(很难或什至不可能适应一段时间) 我正在尝试使用令牌(不存储在服务器端)进行无状态身份验证.长话短说-这是JSON Web令牌认证格式的简单模拟.我在默认一个之前使用了两个自定义过滤器: > TokenizedUsernamePasswordAuthenticationFilter,它在之后创建令牌在入口点(“ / myApp /登录”)成功认证> Toke...

java-为什么未使用的活动上传到Play商店时会引发异常?【代码】

我有一个最近上传到Play商店的应用程序,并且启用了Crashlytics.在此应用程序中,有一个名为StartQuizActivity的活动,该活动是在开发过程中创建的,但当前未使用.该活动仍在清单中声明,但在应用程序中没有调用它的意图. 我收到了一份崩溃报告,其中显示了堆栈跟踪,提示设备尝试启动此活动,导致IllegalArgumentException异常,提示未通过意图传递所需的对象:Fatal Exception: java.lang.RuntimeException: Unable to start activityComp...

java-Findbugs contrib:方法从没有历史记录的catch块中抛出替代异常【代码】

fb-contrib抱怨Method throws alternative exception from catch block without history在我的try / catch块之一中. 如何解决?是否有解决此问题的详细说明?解决方法:捕获了原始异常,您的代码引发了另一个异常,而没有在java.lang.Throwable原因中包含原始异常 发现了一些here:This method catches an exception, and throws a different exception, without incorporating theoriginal exception. Doing so hides the original s...

java-Jsoup网站登录抛出未知异常【代码】

I attempt to login to my school’s grade book website to display the HTML with the following code:public class Connect {public static void main(String[] args) {String pageURL = "https://parents.mtsd.k12.nj.us/genesis/parents?tab1=studentdata&action=form";String param1 = "&tab2=gradebook";String param2 = "&tab3=weeklysummary";String param3 = "&studentid=";Scanner input = new Scanner (System.in);Str...

java-Spring中的Bean创建异常【代码】

我正在尝试自动装配在另一个项目中声明的类,但是却遇到了运行时异常,而不是编译时异常.如果我删除了自动装配并使用新实例创建了一个对象,则该实例可以完美运行. 我收到以下错误:ErrorSEVERE: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getThreshold': Injection of autowired dependencies failed; nested exception is org.springframework.beans.fa...

java.lang.reflect.Proxy:巨大的异常堆栈跟踪【代码】

这是一个简单的Java应用程序:import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy;public class Main {interface MyInterface {void myMethod();}public static void main(String[] args) {MyInterface myInterface = (MyInterface) Proxy.newProxyInstance(Main.class.getClassLoader(), new Class[] {MyInterface.class},new InvocationHandler() {@Overridepublic ...

java-为什么在运行异常后Android App自动重启?【代码】

我的应用程序在两个5.0的android系统中运行. 在我的开发中,我有一个未捕获的RuntimeException 遇到例外时,我的应用程序将自动重启, 我不知道为什么我的应用程序会自动重启?即使我调用System.exit(1) 这是带有RuntimException的日志E/AndroidRuntime(23905): FATAL EXCEPTION: main E/AndroidRuntime(23905): Process: com.oosmart.mainapp, PID: 23905 E/AndroidRuntime(23905): android.database.sqlite.SQLiteException: no suc...