简体   繁体   English

获取非法访问错误

[英]Getting IllegalAccessError

When i am using this code it gives error:当我使用此代码时,它会给出错误:

2011-08-10 13:18:13.368::WARN: EXCEPTION 2011-08-10 13:18:13.368::警告:异常
java.lang.IllegalAccessError: tried to access method org.mortbay.util.Utf8StringBuffer.(I)V from class org.mortbay.jetty.HttpURI java.lang.IllegalAccessError: 试图从 class org.mortbay.jetty.HttpURI 访问方法 org.mortbay.util.Utf8StringBuffer.(I)V

Code:代码:

package com.google.api.client.sample.docs.v3;

import com.google.api.client.auth.oauth.OAuthCredentialsResponse;
import com.google.api.client.auth.oauth.OAuthHmacSigner;
import com.google.api.client.auth.oauth.OAuthParameters;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthAuthorizeTemporaryTokenUrl;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthGetAccessToken;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthGetTemporaryToken;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.sample.docs.v3.model.DocsUrl;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.net.URI;

public class Auth {

    private static final String APP_NAME ="Google Documents List Data API Java Client Sample";

    private static OAuthHmacSigner signer;

    private static OAuthCredentialsResponse credentials;

    static void authorize(HttpTransport transport) throws Exception {
        // callback server
        LoginCallbackServer callbackServer = null;
        String verifier = null;
        String tempToken = null;
        try {

            callbackServer = new LoginCallbackServer();
            callbackServer.start();
            // temporary token
            GoogleOAuthGetTemporaryToken temporaryToken =new GoogleOAuthGetTemporaryToken();
            signer = new OAuthHmacSigner();
            signer.clientSharedSecret = "anonymous";
            temporaryToken.signer = signer;
            temporaryToken.consumerKey = "in.gappsdemo.in";
            //temporaryToken.scope ="https://apps-apis.google.com/a/feeds/user/";
            temporaryToken.scope = DocsUrl.ROOT_URL;
            temporaryToken.displayName = APP_NAME;
            temporaryToken.callback = callbackServer.getCallbackUrl();
            System.out.println("temporaryToken.callback: "+temporaryToken.callback);
            OAuthCredentialsResponse tempCredentials = temporaryToken.execute();
            signer.tokenSharedSecret = tempCredentials.tokenSecret;
            System.out.println("signer.tokenSharedSecret: " + signer.tokenSharedSecret);
            // authorization URL
            GoogleOAuthAuthorizeTemporaryTokenUrl authorizeUrl =new GoogleOAuthAuthorizeTemporaryTokenUrl();
            authorizeUrl.temporaryToken = tempToken = tempCredentials.token;
            String authorizationUrl = authorizeUrl.build();
            System.out.println("Go to this authorizationUrl: " + authorizationUrl);
            // launch in browser
            boolean browsed = false;
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if (desktop.isSupported(Action.BROWSE)) {
                    System.out.println("In if browsed condition:");
                    desktop.browse(URI.create(authorizationUrl));
                    browsed = true;
                }
            }
            if (!browsed) {
                String browser = "google-chrome";
                Runtime.getRuntime().exec(new String[] {browser, authorizationUrl});
                System.out.println("In if !browsed condition1:");
            }
            System.out.println("tempToken: "+tempToken);
            verifier = callbackServer.waitForVerifier(tempToken);
            System.out.println("GoogleOAuthGetAccessToken: ");
        } finally {
            System.out.println("server Stop:");
            if (callbackServer != null) {
                System.out.println("server Stop:");
                callbackServer.stop();
            }
        }
        System.out.println("GoogleOAuthGetAccessToken: ");
        GoogleOAuthGetAccessToken accessToken = new GoogleOAuthGetAccessToken();
        accessToken.temporaryToken = tempToken;
        accessToken.signer = signer;
        accessToken.consumerKey = "in.gappsdemo.in";
        accessToken.verifier = verifier;
        credentials = accessToken.execute();
        signer.tokenSharedSecret = credentials.tokenSecret;
        System.out.println("signer.tokenSharedSecret: ");
        createOAuthParameters().signRequestsUsingAuthorizationHeader(transport);
    }

    static void revoke() {
        if (credentials != null) {
            try {
                GoogleOAuthGetAccessToken.revokeAccessToken(createOAuthParameters());
            } catch (Exception e) {
                e.printStackTrace(System.err);
            }
        }
    }

    private static OAuthParameters createOAuthParameters() {
        OAuthParameters authorizer = new OAuthParameters();
        authorizer.consumerKey = "in.gappsdemo.in";
        authorizer.signer = signer;
        authorizer.token = credentials.token;
        return authorizer;
    }
}

Here are two potentially related , posts .这里有两个可能相关帖子 Notice you're getting an Error, not an Exception, so that is interesting.请注意,您收到的是错误,而不是异常,所以这很有趣。 You might try running your JVM with -verbose to see where each class is getting loaded from, to see if maybe you're compiling with one class/jar, but accidentally running with another.您可以尝试使用 -verbose 运行 JVM 以查看每个 class 是从哪里加载的,以查看您是否正在使用一个类/jar 进行编译,但不小心与另一个类/jar 一起运行。

Also notice from the error that the packages are slightly different "org.mortbay.util" vs. "org.mortbay.jetty", so the UTF8StringBuffer constructor would need to be more visible.另请注意,包与“org.mortbay.util”与“org.mortbay.jetty”略有不同,因此 UTF8StringBuffer 构造函数需要更加可见。 But again, normally a compiler would catch that.但同样,通常编译器会捕捉到这一点。

I realize this isn't a full answer, to be sure, but at least a couple places to start looking.我意识到这不是一个完整的答案,可以肯定的是,但至少有几个地方可以开始寻找。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Kryo序列化任意Java对象(获取IllegalAccessError) - Serializing an arbitrary Java object with Kryo (getting IllegalAccessError) 在线程“主” java.lang.IllegalAccessError中获取错误异常: - Getting Error Exception in thread “main” java.lang.IllegalAccessError: IllegalAccessError和代理 - IllegalAccessError and proxy 我一直在获取java.lang.IllegalAccessError。 我还是无法解决这个问题 - I keep on getting java.lang.IllegalAccessError. I cannot fix this anyway possible 无法创建 .jar 文件。 使用 gradle 时出错,尤其是 ./gradlew build。 获取 java.lang.IllegalAccessError - Unable to create .jar file. Error while working with gradle, particularly ./gradlew build. getting java.lang.IllegalAccessError 两个java文件。 使用主要方法运行类时尝试访问其他文件中的方法时出现 IllegalAccessError - Two java files. Getting IllegalAccessError when running class with main method trying to access a method from the other file @Around上的IllegalAccessError-Aspectj - IllegalAccessError on @Around - Aspectj 解决IllegalAccessError - Working around IllegalAccessError IllegalAccessError 与 RenderScript 支持库 - IllegalAccessError with RenderScript Support library IllegalAccessError:类无法访问方法 - IllegalAccessError: Method is inaccessible to class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM