GVKun编程网logo

小程序。java.lang.reflect.InvocationTargetException(小程序开发)

17

如果您想了解小程序。java.lang.reflect.InvocationTargetException和小程序开发的知识,那么本篇文章将是您的不二之选。我们将深入剖析小程序。java.lang.r

如果您想了解小程序。java.lang.reflect.InvocationTargetException小程序开发的知识,那么本篇文章将是您的不二之选。我们将深入剖析小程序。java.lang.reflect.InvocationTargetException的各个方面,并为您解答小程序开发的疑在这篇文章中,我们将为您介绍小程序。java.lang.reflect.InvocationTargetException的相关知识,同时也会详细的解释小程序开发的运用方法,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

小程序。java.lang.reflect.InvocationTargetException(小程序开发)

小程序。java.lang.reflect.InvocationTargetException(小程序开发)

我有使用jna指针类的小程序。小程序代码为:

import com.sun.jna.*;public class Applet1 extends Applet{    public void test() {        try {            Pointer p = new Memory(73);        } catch (Exception e) {        e.printStackTrace();        }    }}

在html代码中,我以这种方式声明了applet:

<applet    codebase=/pki/    code=Applet1.class     archive=/pki/jna-3.2.3.jar    id=Applet1    width=100     height=100 ></applet>

当我通过JavaScript调用document.getElementById(“
Applet1”)。test()时,会出现java.lang.reflect.InvocationTargetException。我无法在Java类端调用e.getCause(),因为applet
try / catch无法捕获错误(我不明白为什么)。但是javascript try / catch捕获此错误。如果移动Pointer p = newMemory(73);线就可以了。问题是这条线。请帮助解决问题。

编辑:如果替换此块:

try {    Pointer p = new Memory(73);} catch (Exception e) {    e.printStackTrace();}

try {    Pointer p = new Memory(73);} catch (Throwable e) {    System.out.println(e.getCause());}

我收到了java.security.AccessControlException:访问被拒绝(已读取java.util.PropertyPermission
jna.boot.library.path)

答案1

小编典典

好的,现在我们来探究问题的根源。(您仍然可以使用printStackTrace-这也应该已经打印的堆栈跟踪cause。)。

  1. 未签名的小程序只能访问有限数量的系统属性-这些jna属性不属于这些属性。

  2. 在未签名的applet中,无论如何您都无法加载本机库,因此无法使用JNA(或JNI)。

  3. 如果您在applet上签名(并告诉插件接受签名),则applet具有使用JNA的必要权利。但是,任何单个运行代码的权利实际上就是称为当前代码的所有方法的权利的交叉点。

从JavaScript调用的Applet方法具有非常有限的权限(因为即使您的浏览器甚至具有这种概念,插件也无法真正检查JavaScript代码是否具有必需的权限)。

您可以通过包装代码的一部分来解决此问题,该代码部分需要在applet的权限下运行AccessController.doPrivileged(...)。但是首先
要确保它不会做任何危险的事情 (对于JNI / JNA来说很容易),即使是从恶意JavaScript代码中调用也是如此。

android中的java.lang.reflect.invocationtargetexception

android中的java.lang.reflect.invocationtargetexception

我遇到了问题,我的xml文件如下

<ImageView
    android:id="@+id/edt_order"
    android:layout_width="50dp"
    android:layout_height="match_parent"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/separator_bottom"
    android:background="#fff"
    android:clickable="true"
    android:onClick="clickHandler"
    android:src="@drawable/edit_button" />

<ImageView
    android:id="@+id/save_change_order_id"
    android:layout_width="100dp"
    android:layout_height="match_parent"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/separator_bottom"
    android:background="#fff"
    android:clickable="true"
    android:visibility="gone"
    android:onClick="clickHandler"
    android:src="@drawable/save_button" />

实际上这是定义自定义alert-dialog的xml的一部分.我希望当我点击第一个ImageView(android:id =“@ id / edt_order”)时,它的可见性变为Invisible而代替这个ImageView setvisible另一个ImageView(android:id =“@ id / save_change_order_id”)

为此,我在java文件中写下以下代码:

public void clickHandler(View v) {

    if (v.getId() == R.id.edt_order) {                                  
        System.out.println(" edit buton click");                    
        System.out.println("Click my Order");
        img_v_save_change_order_var.setVisibility(ImageView.VISIBLE);
        img_btn_edit_order_var.setVisibility(ImageView.INVISIBLE);
        int jcount = 0;   
        // save_change_order_id   
        jcount = countjournals();             
        System.out.println("jcount = " + jcount);              

        if (jcount < 1) {             
            alertShow();   
        } else {
            intiliazeOrderListDialog();                           
        }
    }               
}

但我得到的例外情况如下:

01-09 06:12:14.550: D/AndroidRuntime(1981): Shutting down VM
 01-09 06:12:14.550: W/dalvikvm(1981): threadid=1: thread exiting with uncaught exception (group=0xb3ab3b90)
 01-09 06:12:14.730: E/AndroidRuntime(1981): FATAL EXCEPTION: main
 01-09 06:12:14.730: E/AndroidRuntime(1981): Process: com.example.demoekot,PID: 1981
 01-09 06:12:14.730: E/AndroidRuntime(1981): java.lang.IllegalStateException: Could not execute method of the activity
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at android.view.View$1.onClick(View.java:3814)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at android.view.View.performClick(View.java:4424)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at android.view.View$PerformClick.run(View.java:18383)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at android.os.Handler.handleCallback(Handler.java:733)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at android.os.Handler.dispatchMessage(Handler.java:95)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at android.os.Looper.loop(Looper.java:137)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at android.app.ActivityThread.main(ActivityThread.java:4998)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at java.lang.reflect.Method.invokeNative(Native Method)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at java.lang.reflect.Method.invoke(Method.java:515)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at dalvik.system.NativeStart.main(Native Method)
 01-09 06:12:14.730: E/AndroidRuntime(1981): Caused by: java.lang.reflect.InvocationTargetException
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at java.lang.reflect.Method.invokeNative(Native Method)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at java.lang.reflect.Method.invoke(Method.java:515)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at android.view.View$1.onClick(View.java:3809)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    ... 11 more
 01-09 06:12:14.730: E/AndroidRuntime(1981): Caused by: java.lang.NullPointerException
 01-09 06:12:14.730: E/AndroidRuntime(1981):    at com.example.demoekot.MainScreen.clickHandler(MainScreen.java:428)
 01-09 06:12:14.730: E/AndroidRuntime(1981):    ... 14 more

为什么我得到这个例外?

解决方法

我认为这是主要课堂的形象宣言的问题.

applet中的java.lang.reflect.invocationtargetexception错误

applet中的java.lang.reflect.invocationtargetexception错误

我的应用程序作为一个应用程序运行时没有错误,但是作为一个applet引发了以下错误:

java.lang.reflect.invocationtargetexception

这是我第一次尝试将应用程序用作applet,因此我可能做错了一些,但这是我的主要课程:

 package main;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.GridLayout;import javax.swing.JApplet;import javax.swing.JFrame;public class MainGame extends JApplet {    private static final long serialVersionUID = 1L;    public static final String NAME = "Physics - Projectile Motion Example";    public static final int HEIGHT = 160;    public static final int WIDTH = HEIGHT * 16 / 9;    public static final int SCALE = 4;    private long reportedFramerate;    long framerate = 1000 / 60;    // time the frame began    long frameStart;    // number of frames counted this second    long frameCount = 0;    // time elapsed during one frame    long elapsedTime;    // accumulates elapsed time over multiple frames    long totalElapsedTime = 0;    // the actual calculated framerate reported    public MainGame() {        run();    }    public void run() {        JFrame frame = new JFrame(MainGame.NAME);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.setLayout(new BorderLayout());        OptionsPanel options = new OptionsPanel();        GamePanel game = new GamePanel(options);        frame.setSize(new Dimension ( WIDTH * SCALE, HEIGHT * SCALE ));        frame.add(game, BorderLayout.CENTER);        frame.add(options, BorderLayout.SOUTH);        frame.setLocationRelativeTo(null);        frame.setResizable(false);        frame.setVisible(true);        while(true) {            frameStart = System.currentTimeMillis();            if(options.isStartGame() == true) {                game.run();            }            else {                game.reset();            }            // calculate the time it took to render the frame            elapsedTime = System.currentTimeMillis() - frameStart;            // sync the framerate            try {                // make sure framerate milliseconds have passed this frame                if (elapsedTime < framerate) {                    Thread.sleep(framerate - elapsedTime);                } else {                    // don''t starve the garbage collector                    Thread.sleep(5);                }            } catch (InterruptedException e) {                break;            }            ++frameCount;            totalElapsedTime += (System.currentTimeMillis() - frameStart);            if (totalElapsedTime > 1000) {                reportedFramerate = (long) ((double) frameCount                        / (double) totalElapsedTime * 1000.0);                // show the framerate in the applet status window                //System.out.println("fps: " + reportedFramerate);                // repaint();                frameCount = 0;                totalElapsedTime = 0;                //System.out.println(reportedFramerate);            }        }    }    public void init() {        new MainGame();    }    public void start() {        System.out.println("started");    }    public void stop() {        System.out.println("Stopped");    }    public void destroy() {    }    public static void main(String[] args) {        new MainGame();    }}

对象的HTML:

<p><object type="application/x-java-applet"    name="physics" width="360" height="320">    <param name="code" value="main.MainGame.class" />    <param name="archive" value="physics.jar" />    <param name="scriptable" value="true" />    <param name="mayscript" value="true" />    <param name="file" value="/report_files/1-1272041330710YAIwK" /></object></p>

查看自己的错误的示例页面:http :
//fogest.com/java_example/

答案1

小编典典

完整的堆栈跟踪为:

Java Plug-in 10.21.2.11Using JRE version 1.7.0_21-b11 Java HotSpot(TM) Client VMUser home directory = C:\Users\Andrew----------------------------------------------------c:   clear console window...0-5: set trace level to <n>----------------------------------------------------Trace level set to 5: all ... completed.security: blacklist: hasBeenModifiedSince 1370282598700 (we have 1366432497929)security: blacklist: hasBeenModifiedSince 1366432497958 (we have 1366432497929)network: Created version ID: 1.7.0.21network: Created version ID: 1.7.0.21basic: exception: java.lang.reflect.InvocationTargetException.java.lang.RuntimeException: java.lang.reflect.InvocationTargetException    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.runOnEDTAndWait(Unknown Source)    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)    at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)    at java.lang.Thread.run(Unknown Source)Caused by: java.lang.reflect.InvocationTargetException    at com.sun.deploy.uitoolkit.impl.awt.OldPluginAWTUtil.invokeAndWait(Unknown Source)    ... 5 moreCaused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0")    at java.security.AccessControlContext.checkPermission(Unknown Source)    at java.security.AccessController.checkPermission(Unknown Source)    at java.lang.SecurityManager.checkPermission(Unknown Source)    at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)    at java.lang.SecurityManager.checkExit(Unknown Source)    at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)    at main.MainGame.run(MainGame.java:36)    at main.MainGame.<init>(MainGame.java:31)    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)    at java.lang.reflect.Constructor.newInstance(Unknown Source)    at java.lang.Class.newInstance0(Unknown Source)    at java.lang.Class.newInstance(Unknown Source)    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)    at java.awt.event.InvocationEvent.dispatch(Unknown Source)    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)    at java.awt.EventQueue.access$200(Unknown Source)    at java.awt.EventQueue$3.run(Unknown Source)    at java.awt.EventQueue$3.run(Unknown Source)    at java.security.AccessController.doPrivileged(Native Method)    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)    at java.awt.EventQueue$4.run(Unknown Source)    at java.awt.EventQueue$4.run(Unknown Source)    at java.security.AccessController.doPrivileged(Native Method)    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)    at java.awt.EventQueue.dispatchEvent(Unknown Source)    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)    at java.awt.EventDispatchThread.run(Unknown Source)basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter@1f312f0security: Reset deny session certificate storesecurity: blacklist: hasBeenModifiedSince 1366740392097 (we have 1366432497929)security: blacklist: hasBeenModifiedSince 1369035157319 (we have 1366432497929)network: CleanupThread used 6369043 usbasic: PluginMain.unregisterApplet: 1 from mananger sun.plugin2.applet.Applet2Manager@1823290network: Checking for update at: https://javadl-esd-secure.oracle.com/update/baseline.versionnetwork: Checking for update at: https://javadl-esd-secure.oracle.com/update/blacklisted.certsnetwork: Checking for update at: https://javadl-esd-secure.oracle.com/update/blacklistsecurity: JSS is not configurednetwork: Connecting https://javadl-esd-secure.oracle.com/update/baseline.version with proxy=DIRECTnetwork: Connecting https://javadl-esd-secure.oracle.com/update/blacklisted.certs with proxy=DIRECTnetwork: Connecting https://javadl-esd-secure.oracle.com/update/blacklist with proxy=DIRECTnetwork: Connecting http://javadl-esd-secure.oracle.com:443/ with proxy=DIRECTnetwork: Connecting http://javadl-esd-secure.oracle.com:443/ with proxy=DIRECTnetwork: Connecting http://javadl-esd-secure.oracle.com:443/ with proxy=DIRECTsecurity: Loading Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacertssecurity: Loaded Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacertssecurity: Loading SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacertssecurity: Loaded SSL Root CA certificates from C:\Program Files (x86)\Java\jre7\lib\security\cacertssecurity: Loading certificates from Deployment session certificate storesecurity: Loaded certificates from Deployment session certificate storesecurity: Loading certificates from Deployment session certificate storesecurity: Loaded certificates from Deployment session certificate storesecurity: Loading certificates from Deployment session certificate storesecurity: Loaded certificates from Deployment session certificate storenetwork: Cookie service is not available - use cache to determine "Cookie"network: Cookie service is not available - use cache to determine "Cookie"network: Cookie service is not available - use cache to determine "Cookie"

重要的部分是:

Caused by: java.security.AccessControlException: access denied   ("java.lang.RuntimePermission" "exitVM.0")

原因是:

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

甚至没有一个受信任的applet也不能(或者至少应该尝试)退出JVM。

Exception in thread “main“ java.io.IOException: java.lang.reflect.InvocationTargetException

Exception in thread “main“ java.io.IOException: java.lang.reflect.InvocationTargetException

关于使用HBase-1.3.1版本 API  运行时出现  Exception in thread "main" java.io.IOException: java.lang.reflect.InvocationTargetException 异常的原因和解决方案


一 现象

二 原因 

HBase-1.3.1版本和JDK版本不匹配,可以使用JDK1.7或者JDK1.8

 

三 解决办法:改JDK版本 

        (0)安装JDK1.8或者JDK1.7版本,要记得安装路径,等一下要用,比如我的安装路径是:

        (1)点击Window下的Preferences

        (2)添加JDK1.8或者JDK1.7的根目录

        (3)添加JDK1.8或者JDK1.7

              a)

               b) 点击Directory找到你刚刚JDK的安装目录

              c)上一步完整之后,点击Apply and Close

        (4)修改当前项目的jdk

              a)

              b) 

              c)

 

              d)

 

              e)选择JDK1.8或者JDK1.7

 

              f)最后点击Apply and Close ,然后重新运行程序就没问题啦!!! 

hibernate bean 的 toJSon JSONException: java.lang.reflect.InvocationTargetException

hibernate bean 的 toJSon JSONException: java.lang.reflect.InvocationTargetException

将hibernate的 对象 使用 转换成json 对象的时候报错

JSONException: java.lang.reflect.InvocationTargetException

从错误异常,完全看不出是什么原因。

网上查询,一般都说是 时间 date 类型 转换的时候报错的。

那么我使用 

JsonConfig cfg = new JsonConfig(); 
        String[] excludes = { "date"};

都过滤掉 date 的字段属性,还是报错了。

只是有一个奇怪的地方,就是 新增和编辑的时候没有问题。只是在 其他地方引用这个对象的时候, 然后转换json的时候就报错了。

也是有点奇怪。

 

参考 https://blog.csdn.net/ye1992/article/details/17436765#reply

   String[] excludes = 加上了 "handler", "hibernateLazyInitializer" 

JsonConfig cfg = new JsonConfig();
        String[] excludes = {   "handler", "hibernateLazyInitializer" };

就解决了这个问题。  估计是 因为 

只是在 其他地方引用这个对象的时候,可能是因为hibernate 懒加载出的对象,因此出了点其他的问题吧。

 

 

 

 

 

 

关于小程序。java.lang.reflect.InvocationTargetException小程序开发的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于android中的java.lang.reflect.invocationtargetexception、applet中的java.lang.reflect.invocationtargetexception错误、Exception in thread “main“ java.io.IOException: java.lang.reflect.InvocationTargetException、hibernate bean 的 toJSon JSONException: java.lang.reflect.InvocationTargetException等相关知识的信息别忘了在本站进行查找喔。

本文标签: