GVKun编程网logo

Java Error 与 Exception 区别(java error和exception区别)

9

针对JavaError与Exception区别和javaerror和exception区别这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展-java.io.IOException:Creat

针对Java Error 与 Exception 区别java error和exception区别这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展- java.io.IOException: CreateProcess error=2、Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.、DWR 报错:Error: java.lang.SecurityException, Session Error 和 Allocate exception for servlet 问题的解决办法、Error 和 Exception 的区别等相关知识,希望可以帮助到你。

本文目录一览:

Java Error 与 Exception 区别(java error和exception区别)

Java Error 与 Exception 区别(java error和exception区别)

Error类和Exception类的父类都是throwable类,区别是:

Error类一般是指与虚拟机相关的问题,如系统崩溃,虚拟机错误,内存空间不足,方法调用栈溢等。对于这类错误的导致的应用程序中断,仅靠程序本身无法恢复和和预防,遇到这样的错误,建议让程序终止。

Exception类表示程序可以处理的异常,可以捕获且可能恢复。遇到这类异常,应该尽可能处理异常,使程序恢复运行,而不应该随意终止异常。

- java.io.IOException: CreateProcess error=2

- java.io.IOException: CreateProcess error=2

androidStudio这个错误提示很模糊,没有任何有价值的信息,几番百度和google后,偶尔发现了一个git的问题,于是重新安装GIT后并配置AS的GIT后,并重启AS,后来问题解决!!

Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.

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>

我尝试了不同的横幅尺寸.没有帮助.删除广告请求代码可以解决问题,但也会删除广告.
谁有线索?

解决方法

Google移动广告现在通过Google Play Services 4.0提供,但由于Google Play服务不可用而出现此错误.很可能你会在Froyo遇到这个问题,那里有一个可以使用的特殊版本.

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

DWR 报错:Error: java.lang.SecurityException, Session Error 和 Allocate exception for servlet 问题的解决办法

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文件,所以报错了,改为如下配置即可:

[html] view plain copy print ?
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <!DOCTYPEdwrPUBLIC"-//GetAheadLimited//DTDDirectWebRemoting2.0//EN"
  3. "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
  4. <dwr>
  5. <allow>
  6. <createcreator="new"javascript="dwrDate">
  7. <paramname="class"value="java.util.Date"></param>
  8. </create>
  9. </allow>
  10. </dwr>

Error 和 Exception 的区别

Error 和 Exception 的区别

错误和异常的区别 (Error vs Exception) 
今天面试问了这样一个问题,"Error" 和 "Exception" 之间有啥区别?我觉得挺有意思,但是似乎又不能脱口而出。查找了一番资料之后,稍微总结了一下。
1)  error 都是继承自父类 java.lang.Error,而 exception 都继承自 java.lang.Exception.

2)  再看看 JDK 中对于 java.lang.Error 和 java.lang.Exception 的解释。
    java.lang.Error: An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. 即:Error 是 Throwable 的子类,用于标记严重错误。合理的应用程序不应该去 try/catch 这种错误。绝大多数的错误都是非正常的,就根本不该出现的。     java.lang.Exception: The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch. 即 Exception 是 Throwable 的一种形式的子类,用于指示一种合理的程序想去 catch 的条件。即它仅仅是一种程序运行条件,而非严重错误,并且鼓励用户程序去 catch 它。

3)  Error 和 RuntimeException 及其子类都是未检查的异常(unchecked exceptions),而所有其他的 Exception 类都是检查了的异常(checked exceptions).
checked exceptions: 通常是从一个可以恢复的程序中抛出来的,并且最好能够从这种异常中使用程序恢复。比如 FileNotFoundException, ParseException 等。
unchecked exceptions: 通常是如果一切正常的话本不该发生的异常,但是的确发生了。比如 ArrayIndexOutOfBoundException, ClassCastException 等。从语言本身的角度讲,程序不该去 catch 这类异常,虽然能够从诸如 RuntimeException 这样的异常中 catch 并恢复,但是并不鼓励终端程序员这么做,因为完全没要必要。因为这类错误本身就是 bug,应该被修复,出现此类错误时程序就应该立即停止执行。 因此,面对 Errors 和 unchecked exceptions 应该让程序自动终止执行,程序员不该做诸如 try/catch 这样的事情,而是应该查明原因,修改代码逻辑。


关于Java Error 与 Exception 区别java error和exception区别的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于- java.io.IOException: CreateProcess error=2、Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.、DWR 报错:Error: java.lang.SecurityException, Session Error 和 Allocate exception for servlet 问题的解决办法、Error 和 Exception 的区别等相关知识的信息别忘了在本站进行查找喔。

本文标签: