GVKun编程网logo

java反射中 java.lang.IllegalAccessException: can not access a member of class with modifiers "public"

39

最近很多小伙伴都在问java反射中java.lang.IllegalAccessException:cannotaccessamemberofclasswithmodifiers"public"这两个

最近很多小伙伴都在问java反射中 java.lang.IllegalAccessException: can not access a member of class with modifiers "public"这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展android java.lang.IllegalStateException: System services not available to Activities before onCreate、Android报java.lang.IllegalAccessException: access to class n、Caused by: java.lang.ClassCastException: class java.lang.Double cannot be cast to class org.apach...、Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has be...等相关知识,下面开始了哦!

本文目录一览:

java反射中 java.lang.IllegalAccessException: can not access a member of class with modifiers

java反射中 java.lang.IllegalAccessException: can not access a member of class with modifiers "public"

解决办法

method.setAccessible(true);

android java.lang.IllegalStateException: System services not available to Activities before onCreate

android java.lang.IllegalStateException: System services not available to Activities before onCreate

java.lang.IllegalStateException: System services not available to Activities before onCreate()
出现这种情况一般是因为 通过使用new关键字实例化Activity类,这样是错误的。因为Activity是系统通过ActivityManagerService创建管理的。 new之后,创建了对象,但没有创建这个Activity,要知道Activity的对象和在Android中真正表示的东西,不是一样的。 对象创建完成后,需要系统对其进行一系列的init和管理。在这个创建的过程中,会回调Acitivity中的onCreate方法,这个方法调用之后,才能说明Activity是创建完成了。
     所以就不能使用new关键字实例化Activity对象,要通过startActivity的方式,实例化这个Activity对象。


原文链接: http://blog.csdn.net/centralperk/article/details/7496877

Android报java.lang.IllegalAccessException: access to class n

Android报java.lang.IllegalAccessException: access to class n

06-27 04:48:02.123: ERROR/AndroidRuntime(787): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.android.surfacetest/net.android.surfacetest.MainActivity}: java.lang.IllegalAccessException: access to class not al

06-27 04:48:02.123: ERROR/AndroidRuntime(787): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.android.surfacetest/net.android.surfacetest.MainActivity}: java.lang.IllegalAccessException: access to class not allowed
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at android.os.Looper.loop(Looper.java:123)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at java.lang.reflect.Method.invokeNative(Native Method)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at java.lang.reflect.Method.invoke(Method.java:507)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at dalvik.system.NativeStart.main(Native Method)
06-27 04:48:02.123: ERROR/AndroidRuntime(787): Caused by: java.lang.IllegalAccessException: access to class not allowed
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at java.lang.Class.newInstanceImpl(Native Method)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at java.lang.Class.newInstance(Class.java:1409)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-27 04:48:02.123: ERROR/AndroidRuntime(787):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)

Android出现以上是错误日志信息

原因1:Activity没有注册

原因2:包名不匹配

原因3:类不是public的,在报错类的定义前加public即可。

其中原因1和3是最常见的

Caused by: java.lang.ClassCastException: class java.lang.Double cannot be cast to class org.apach...

Caused by: java.lang.ClassCastException: class java.lang.Double cannot be cast to class org.apach...

错误:

Caused by: java.lang.ClassCastException: class java.lang.Double cannot be cast to class org.apache.hadoop.io.WritableComparable (java.lang.Double is in module java.base of loader ''bootstrap''; org.apache.hadoop.io.WritableComparable is in unnamed module of loader ''app'')

 

 

 原因:

          在写Comparator时方法写错了,还导错了包

         

 

     解决:  应该改为

         

           导入这两个包

           

 

 

Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has be...

Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has be...

Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has been stopped already. Could not load [org.jboss.netty.util.internal.ByteBufferUtil]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1319)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1176)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1137)
    ... 8 more
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.jboss.netty.util.internal.ByteBufferUtil]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1329)
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1317)
    ... 10 more
java.lang.NoClassDefFoundError: org/jboss/netty/util/internal/ByteBufferUtil
    at org.jboss.netty.channel.socket.nio.SocketSendBufferPool.releaseExternalResources(SocketSendBufferPool.java:380)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:91)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Exception in thread "NettyServerWorker-thread-3" java.lang.NoClassDefFoundError: org/jboss/netty/util/internal/ByteBufferUtil
    at org.jboss.netty.channel.socket.nio.SocketSendBufferPool.releaseExternalResources(SocketSendBufferPool.java:380)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:91)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Exception in thread "NettyServerWorker-thread-4" java.lang.NoClassDefFoundError: org/jboss/netty/util/internal/ByteBufferUtil
    at org.jboss.netty.channel.socket.nio.SocketSendBufferPool.releaseExternalResources(SocketSendBufferPool.java:380)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:91)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Exception in thread "NettyServerWorker-thread-5" java.lang.NoClassDefFoundError: org/jboss/netty/util/internal/ByteBufferUtil
    at org.jboss.netty.channel.socket.nio.SocketSendBufferPool.releaseExternalResources(SocketSendBufferPool.java:380)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:91)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Exception: java.lang.NoClassDefFoundError thrown from the UncaughtExceptionHandler in thread "RMI TCP Connection(3)-127.0.0.1-EventThread"

这个异常主要是在关闭 tomcat 的时候进行出现的一个异常.

翻译:非法访问:这个 web 应用程序实例已经被停止了。无法加载 [org.jboss.netty.util.internal.ByteBufferUtil]。为了调试目的,抛出了下面的堆栈跟踪,并尝试终止导致非法访问的线程。

  在使用 tomcat 启动项目运行时,总是会出现这个错误,碎舞不影响项目运行但是看着还是不舒服,一大堆错误提示.

  原因:我遇到的这个是在 tomcat 关闭的时候,因为之前的 tomcat 中的线程还没有完全关闭,新启动的 tomcat 就会报这个异常,不过并不影响使用,只是跳出来这个异常挺烦人的,但是只能忍着,我也从网上百度了几种方法,但是并不管用.

下面介绍两种最常用的方法:

解决办法:

方法 1:修改 tomcat 目录下的 context.xml, 找到 <Context> 标签,把 reloadble 的属性值设为:reloadable="false",即 < Context reloadable="false">。

找到修改后,好像没有怎么报错了,但是很快又发现似乎没有什么效果,依旧会出现错误提示。

方法 2:将 tomcat 的 server.xml 中的 Context 的 reloadable 设成 false。比如:<Context path="/expert" docBase="expert" debug="0" reloadable="false">

在 server.xml 中并没有找到 context 的配置信息,所以干脆就把 “<Context path="/expert" docBase="expert" debug="0" reloadable="false"></Context>” 加在了 server 标签内部,至今没有出现问题。

今天关于java反射中 java.lang.IllegalAccessException: can not access a member of class with modifiers "public"的讲解已经结束,谢谢您的阅读,如果想了解更多关于android java.lang.IllegalStateException: System services not available to Activities before onCreate、Android报java.lang.IllegalAccessException: access to class n、Caused by: java.lang.ClassCastException: class java.lang.Double cannot be cast to class org.apach...、Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has be...的相关知识,请在本站搜索。

本文标签: