在这篇文章中,我们将为您详细介绍JAVAException和Error的理解的内容,并且讨论关于javaexceptionerror区别的相关问题。此外,我们还会涉及一些关于-java.io.IOEx
在这篇文章中,我们将为您详细介绍JAVA Exception 和 Error 的理解的内容,并且讨论关于java exception error 区别的相关问题。此外,我们还会涉及一些关于- java.io.IOException: CreateProcess error=2、Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.、Caused by: java.io.IOException: CreateProcess error=5, 拒绝访问。、DWR 报错:Error: java.lang.SecurityException, Session Error 和 Allocate exception for servlet 问题的解决办法的知识,以帮助您更全面地了解这个主题。
本文目录一览:- JAVA Exception 和 Error 的理解(java exception error 区别)
- - java.io.IOException: CreateProcess error=2
- Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.
- Caused by: java.io.IOException: CreateProcess error=5, 拒绝访问。
- DWR 报错:Error: java.lang.SecurityException, Session Error 和 Allocate exception for servlet 问题的解决办法
JAVA Exception 和 Error 的理解(java exception error 区别)
结构:
Error类和Exception类都继承自Throwable类。
Error的继承关系:
java.lang.Object > java.lang.Throwable > java.lang.Error
Exception的继承关系:
java.lang.Object > java.lang.Throwable > java.lang.Exception
定义:
Error(错误)表示系统级的错误和程序不必处理的异常,是java运行环境中的内部错误或者硬件问题,比如,内存资源不足等,对于这种错误,程序基本无能为力,除了退出运行外别无选择。
Exception(异常)表示需要捕捉或者需要程序进行处理的异常,它处理的是因为程序设计的瑕疵而引起的问题或者在外的输入等引起的一般性问题,是程序必须处理的。
JAVA 的checked异常和unchecked异常
什么是unchecked异常?即RuntimeException(运行时异常),比如ArrayIndexOutOfBoundException, ClassCastException等,不需要try...catch...或throws 机制去处理的异常,总是由虚拟机接管。这类异常本身就是bug,应该被修复,出现此类错误时程序就应该立即停止执行。 因此,面对Errors和unchecked exceptions应该让程序自动终止执行,程序员不该做诸如try/catch这样的事情,而是应该查明原因,修改代码逻辑。
(附)列举最常用的五种RuntimeException:
ArithmeticException | int a=0; int b= 3/a; |
ClassCastException: | Object x = new Integer(0); System.out.println((String)x); |
IndexOutOfBoundsException ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException |
int [] numbers = { 1, 2, 3 }; int sum = numbers[3]; |
IllegalArgumentException NumberFormatException |
int a = Interger.parseInt("test"); |
NullPointerExceptionextends |
除了RuntimeException,其他继承自java.lang.Exception得异常统称为Checked Exception,比如FileNotFoundException, ParseException等。
对于checked exception这种异常,JAVA编译器强制要求我们必需对出现的这些异常进行catch。
- java.io.IOException: CreateProcess error=2
androidStudio这个错误提示很模糊,没有任何有价值的信息,几番百度和google后,偶尔发现了一个git的问题,于是重新安装GIT后并配置AS的GIT后,并重启AS,后来问题解决!!
Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.
FATAL EXCEPTION: AdWorker #1 java.lang.NoSuchMethodError: java.io.IOException.<init> at com.google.android.gms.internal.g.f(UnkNown Source) at com.google.android.gms.internal.g.b(UnkNown Source) at com.google.android.gms.internal.e.a(UnkNown Source) at com.google.android.gms.internal.e.a(UnkNown Source) at com.google.android.gms.internal.bq.ac(UnkNown Source) at com.google.android.gms.internal.cg$1.run(UnkNown Source) at com.google.android.gms.internal.ch$1.run(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) at java.lang.Thread.run(Thread.java:1096)
除了它与谷歌广告/云服务有关,我不知道它来自哪里.直到昨天我才重现它,我启动了一个10英寸的模拟器并立即看到了问题.删除部分代码后,我认为以下部分是问题所在.
public void onActivityCreated(Bundle savedInstanceState) { ............ AdView adView = (AdView)getActivity().findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice("CED2A4FD2C192C08557081CC37AA9E54") .build(); adView.loadAd(adRequest); }
奇怪的是它只发生在10英寸或更高的设备上.我测试了各种不同的设备/版本.该问题仅发生在10英寸设备或更大的设备上. Android版本并不重要. 2.2或4.4它不断崩溃.
根据我的理解,我没有针对特定设备尺寸的任何不同布局文件夹.
我的广告定义的xml如下所示:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/mainContainer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" android:orientation="vertical" > <LinearLayout android:id="@+id/titleContainer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > </LinearLayout> <com.viewpagerindicator.TabPageIndicator android:id="@+id/indicator"android:layout_width="fill_parent" android:layout_height="wrap_content" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" /> <LinearLayout android:id="@+id/adViewContainer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" > <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto" android:id="@+id/adView" android:layout_width="fill_parent" android:layout_height="wrap_content" ads:adUnitId="@string/adid" ads:adSize="SMART_BANNER" android:gravity="bottom" /> </LinearLayout> </LinearLayout>
我尝试了不同的横幅尺寸.没有帮助.删除广告请求代码可以解决问题,但也会删除广告.
谁有线索?
解决方法
http://developer.android.com/google/play-services/setup.html
Note: Google Play services 4.0.30 (released November 2013) and newer
versions require Android 2.3 or higher. If your app supports Android
2.2,you can continue development with the Google Play services SDK,but must instead install Google Play services for Froyo from the SDK
Manager.
http:// android-developers.blogspot.no/2013/10/google-play-services-40.html
With over 97% of devices Now running Android 2.3 (Gingerbread) or
newer platform versions,we’re dropping support for Froyo from this
release of the Google Play services SDK in order to make it possible
to offer more powerful APIs in the future. That means you will not be
able to utilize these new APIs on devices running Android 2.2 (Froyo).
https://developer.android.com/google/play-services/setup.html#ensure
Important: Because it is hard to anticipate the state of each device,
you must always check for a compatible Google Play services APK before
you access Google Play services features. For many apps,the best time
to check is during the onResume() method of the main activity.
Alernative 1用于在使用AdView之前检查Google Play服务是否可用.
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext(); if(status == ConnectionResult.SUCCESS) { //Success! Do what you want }
Alernative 2是使用GoogleAdMobAdsSdk-6.4.1.jar
Caused by: java.io.IOException: CreateProcess error=5, 拒绝访问。
今天在用java调用按Android ADB时进行执行时发现了一个错误,也就是下面这个错误。
Caused by: java.io.IOException: CreateProcess error=5, 拒绝访问。
我的访问路径是这个
刚开始我以为是权限不够,就去修改文件或者系统的一些权限,然而没什么用,将文件换到别的盘也照样报错,后来查看了很多资料,看到一个令我感到羞愧的答案,其实这个问题不应该犯的
解决:读取的如果是文件夹,就会出此错误,读取文件夹,无论你怎么读,都无法读取,读取的目录后面忘加了文件名!
DWR 报错:Error: java.lang.SecurityException, Session Error 和 Allocate exception for servlet 问题的解决办法
DWR Session Error问题的解决办法
来源于百度文库:http://wenku.baidu.com/link?url=RltL4aB3-To1EDI-mG3K7Vz7LdFWERxdu0Mpw5f29nd59pw_-qUHwB1HGZcRCjfMsUXVbgZeYxaD0JN6_HPz9tay7Z2V6DN5F58dcq8QF37
问题情境再现 使用的Dwr版本2.0
在一台服务器上的不同端口上部署了同样的程序(tomcat5.5.28 80端口,tomcat 5.5.28 8080端口)
使用浏览器先后登陆80,8080端口的程序,都不注销,保持会话状态。
然后浏览器切换到8080的一个使用了DWR ajax功能的页面上,浏览器弹出Session Error的提示。
但是,如果切换到80端口的程序上,同样进入到一个使用了dwr ajax技术的页面上,没有Session Error的提 示。
问题诊断:
初步怀疑浏览器的问题。
检查浏览器的cookie中的jsessionid的值。因为我们知道,Http协议本身是无状态的,服务器标识同一次会话的过程就是借助于cookie中的某个值或者通过url重写的方式来实现。这也是jsp程序的session原理。
检查发现:cookie中存在2个sessionid项,sessionid的值不同。
因为站点地址相同,url也相同(除了端口不同外),因此,浏览器“误”认为是同一个程序,把缓存的cookie项都发送回了服务器。
然后再观测ajax请求的值,即http post或get的参数值如下: callCount=1
page=/web/initRolePermission.action
httpSessionId=3F5F7D7C14D40667FF126DC6F9038EE5 scriptSessionId=5B2B53E512648E78C92393E052589CA3859 c0-scriptName=adminRolePerAction c0-methodName=findPermission c0-id=0
c0-param0=string:181 batchId=0
在这里,务必注意
httpSessionId=3F5F7D7C14D40667FF126DC6F9038EE5,
实际上,一般情况下,httpSessionId和cookie中的jsession值是相同的。
至于dwr组件中,为什么要加上httpSessionId,这是因为dwr开发团队考虑到了跨站攻击问题。因此,通过验证dwr ajax请求中的httpSessionId值, 来防止跨站攻击。
在重现,诊断问题过程中,发现Session Error的信息是来自dwr ajax请求的响应中,抛出的异常是java.lang.SecurityException,因此可以怀疑这个错误信息是源于dwr源代码中的。
用Eclipse打开下载到的dwr源代码。搜索Session Error的信息,然后在org.directwebremoting.dwrp.Batch 类中找到了,其部分代码如下: /**
* Check that this request is not subject to a CSRF attack * @param request The original browser's request
* @param sessionCookieName "JSESSIONID" unless it has been overridden */
private void checkNotCsrfAttack(HttpServletRequest request,String sessionCookieName) {
// A check to see that this isn't a csrf attack
// http://en.wikipedia.org/wiki/Cross-site_request_forgery // http://www.tux.org/~peterw/csrf.txt if (request.isRequestedSessionIdValid() && request.isRequestedSessionIdFromCookie()) {
String headerSessionId = request.getRequestedSessionId(); if (headerSessionId.length() > 0) {
String bodySessionId = getHttpSessionId();
// normal case; if same session cookie is supplied by DWR and // in HTTP header then all is ok
if (headerSessionId.equals(bodySessionId)) { return; }
// Weblogic adds creation time to the end of the incoming
// session cookie string (even for request.getRequestedSessionId()). // Use the raw cookie instead
Cookie[] cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
if (cookie.getName().equals(sessionCookieName) && cookie.getValue().equals(bodySessionId)) { return; } }
// Otherwise error
log.error("A request has been denied as a potential CSRF attack."); throw new SecurityException("Session Error"); } } }
仔细分析这段代码,即使在上述问题情境环境中,也不会出现Session Error的错误。 然后反编译正在使用的dwr类文件,找到batch类,代码却不同,代码如下: private void checkNotCsrfAttack(HttpServletRequest request) {
if(request.isRequestedSessionIdValid() && request.isRequestedSessionIdFromCookie()) {
String headerSessionId = request.getRequestedSessionId(); if(headerSessionId.length() > 0) {
String bodySessionId = getHttpSessionId(); if(!bodySessionId.startsWith(headerSessionId)) throw new SecurityException("Session Error"); } } }
该代码没有考虑到cookie中出现多个jsession的情况。
到此,问题就发现并解决。
由于dwr低版本的bug引起的,升级dwr版本即解决此问题。 可能,读者还有一个疑问:为什么该问题只出现在8080端口上。
检查发现:80端口的cookie项(就是80端口产生的jsessionid出现在cookie项的最前面),
这样在80端口上的程序访问中,dwr ajax请求中的httpSessionId和cookie项最前面的jsessionid值相同,在80端口上,就自然不会出现session error错误。
三、
严重: Allocate exception for servlet dwr
org.xml.sax.SAXException: Failed to resolve: arg0=-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN arg1=http://getahead.org/dwr/dwr30.dtd
这是因为添加的jar包是2.0版本的,但是却引用了3.0的dtd文件,所以报错了,改为如下配置即可:
- <?xmlversion="1.0"encoding="UTF-8"?>
- <!DOCTYPEdwrPUBLIC"-//GetAheadLimited//DTDDirectWebRemoting2.0//EN"
- "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
- <dwr>
- <allow>
- <createcreator="new"javascript="dwrDate">
- <paramname="class"value="java.util.Date"></param>
- </create>
- </allow>
- </dwr>
今天关于JAVA Exception 和 Error 的理解和java exception error 区别的讲解已经结束,谢谢您的阅读,如果想了解更多关于- java.io.IOException: CreateProcess error=2、Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.、Caused by: java.io.IOException: CreateProcess error=5, 拒绝访问。、DWR 报错:Error: java.lang.SecurityException, Session Error 和 Allocate exception for servlet 问题的解决办法的相关知识,请在本站搜索。
本文标签: