noclassdeferror的内部类MyLicenseCheckerCallback [英] noclassdeferror for inner class MyLicenseCheckerCallback

查看:173
本文介绍了noclassdeferror的内部类MyLicenseCheckerCallback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着做<一个href=\"http://www.droidforums.net/forum/android-app-developers/69899-market-license-easy-implementation-protect-your-apps.html\"相对=nofollow>本教程
但不断收到此错误:


  

14 08-21:12:49.599:E / AndroidRuntime(714):
  java.lang.NoClassDefFoundError的:
  com.akiraapps.LicenseCheck $ MyLicenseCheckerCallback


 进口android.app.Activity;
进口android.app.AlertDialog;
进口android.app.Dialog;
进口android.content.DialogInterface;
进口android.content.Intent;
进口android.net.Uri;
进口android.os.Bundle;
进口android.os.Handler;
进口android.provider.Settings.Secure;
进口android.view.View;
进口android.view.Window;
进口android.widget.Button;
进口android.widget.TextView;进口com.google.android.vending.licensing.AESObfuscator;
进口com.google.android.vending.licensing.LicenseChecker;
进口com.google.android.vending.licensing.LicenseCheckerCallback;
进口com.google.android.vending.licensing.Policy;
进口com.google.android.vending.licensing.ServerManagedPolicy;
公共类LicenseCheck延伸活动{    私有静态最后弦乐BASE64_PUBLIC_KEY =无;    私有静态最后一个字节[] = SALT新的字节[] {}无;    私人TextView的mStatusText;
    私人按钮mCheckLicenseButton;    私人LicenseCheckerCallback mLicenseCheckerCallback;
    私人LicenseChecker mChecker;
    // UI线程的处理程序。
    私人处理器mHandler;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        的setContentView(R.layout.main);        mStatusText =(的TextView)findViewById(R.id.status_text);
        mCheckLicenseButton =(按钮)findViewById(R.id.check_license_button);
        mCheckLicenseButton.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(查看视图){
                doCheck();
            }
        });        mHandler =新的处理程序();        //尝试在这里使用更多的数据。 ANDROID_ID是攻击的一个点。
        字符串的DeviceID = Secure.getString(getContentResolver(),Secure.ANDROID_ID);        当它完成//库调用此。
        mLicenseCheckerCallback =新MyLicenseCheckerCallback();
        //构造一个政策LicenseChecker。
        mChecker =新LicenseChecker(
            对此,新ServerManagedPolicy(这一点,
                新AESObfuscator(SALT,getPackageName(),DEVICEID))
            BASE64_PUBLIC_KEY);
        doCheck();
    }    保护对话框onCreateDialog(INT ID){
        最终布尔bRetry = ID = = 1;
        返回新AlertDialog.Builder(本)
            .setTitle(R.string.unlicensed_dialog_title)
            .setMessage(?bRetry R.string.unlicensed_dialog_retry_body:R.string.unlicensed_dialog_body)
            .setPositiveButton(bRetry R.string.retry_button:R.string.buy_button,新DialogInterface.OnClickListener(){
                布尔mRetry = bRetry;
                公共无效的onClick(DialogInterface对话,诠释它){
                    如果(mRetry){
                        doCheck();
                    }其他{
                        意图marketIntent =新意图(Intent.ACTION_VIEW,Uri.parse(
                                http://market.android.com/details?id=+ getPackageName()));
                            startActivity(marketIntent);
                    }
                }
            })
            .setNegativeButton(R.string.quit_button,新DialogInterface.OnClickListener(){
                公共无效的onClick(DialogInterface对话,诠释它){
                    完();
                }
            })。创建();
    }    私人无效doCheck(){
        mCheckLicenseButton.setEnabled(假);
        setProgressBarIndeterminateVisibility(真);
        mStatusText.setText(R.string.checking_license);
        mChecker.checkAccess(mLicenseCheckerCallback);
    }    私人无效displayResult(最后弦乐结果){
        mHandler.post(新的Runnable(){
            公共无效的run(){
                mStatusText.setText(结果);
                setProgressBarIndeterminateVisibility(假);
                mCheckLicenseButton.setEnabled(真);
            }
        });
    }    私人无效displayDialog(最终布尔showRetry){
        mHandler.post(新的Runnable(){
            公共无效的run(){
                setProgressBarIndeterminateVisibility(假);
                的ShowDialog(showRetry?1:0);
                mCheckLicenseButton.setEnabled(真);
            }
        });
    }    私有类MyLicenseCheckerCallback实现LicenseCheckerCallback {
        公共无效允许(INT policyReason){
            的System.out.println(允许);
            如果(isFinishing()){
                //如果活动是整理不更新UI。
                返回;
            }
            //应该允许用户访问。
            displayResult(的getString(R.string.allow));
        }        公共无效dontAllow(INT policyReason){
            的System.out.println(dontAllow);
            如果(isFinishing()){
                //如果活动是整理不更新UI。
                返回;
            }
            displayResult(的getString(R.string.dont_allow));
            //不应该允许访问。在大多数情况下,应用程序应该承担
            //用户具有访问权限,除非遇到这一点。如果是这样,
            //应用程序应该通知自己的无牌方式用户
            //然后要么关闭应用程序或用户限制到
            //限制的功能集。
            //在这个例子中,我们显示一个对话框,将用户带到市场。
            //如果缺少许可证的原因在于,该服务是
            //不可用或有另外一个问题,我们显示一个
            //重试对话框,不同的消息按钮。
            displayDialog(policyReason == Policy.RETRY);
        }        公共无效的ApplicationError(INT错误code){
            的System.out.println(的ApplicationError);
            如果(isFinishing()){
                //如果活动是整理不更新UI。
                返回;
            }
            //这是说开发商犯了一个错误的一种礼貌的方式
            //在设置或调用许可证检查程序库。
            //请检查错误code和修复错误。
            字符串结果=的String.format(的getString(R.string.application_error),错误code);
            displayResult(结果);
        }
    }    @覆盖
    保护无效的onDestroy(){
        super.onDestroy();
        mChecker.onDestroy();
    }}

我按照教程设置LVL作为库项目,这些进口似乎是ok了。

为什么我得到这个错误?它为什么不能找到内部类?如果我点击右键并说节目定义,它跳转到内部类。


解决方案

所以这 SO答案是什么固定它
我创建了一个名为libs文件夹,并从coppied中包括许可包与经理下载库项目的library.jar文件

我不明白是每这个答案这应该对我来说已经完成
当我使用ADT 20.0.3

基本上它归结为是我直接从Android的下载并卡住了试图找出什么是错了几个小时的例子,这似乎是这个步骤应该是在自述/帮助文档或IM做得不对

如果您知道这是为什么,答案,以及如何做的更好,请回答回答和不适改变你的。

Im trying to do this tutorial But keep getting this error:

08-21 14:12:49.599: E/AndroidRuntime(714): java.lang.NoClassDefFoundError: com.akiraapps.LicenseCheck$MyLicenseCheckerCallback

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings.Secure;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.Policy;
import com.google.android.vending.licensing.ServerManagedPolicy;


public class LicenseCheck extends Activity {

    private static final String BASE64_PUBLIC_KEY = "no";

    private static final byte[] SALT = new byte[] { no};

    private TextView mStatusText;
    private Button mCheckLicenseButton;

    private LicenseCheckerCallback mLicenseCheckerCallback;
    private LicenseChecker mChecker;
    // A handler on the UI thread.
    private Handler mHandler;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.main);

        mStatusText = (TextView) findViewById(R.id.status_text);
        mCheckLicenseButton = (Button) findViewById(R.id.check_license_button);
        mCheckLicenseButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                doCheck();
            }
        });

        mHandler = new Handler();

        // Try to use more data here. ANDROID_ID is a single point of attack.
        String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

        // Library calls this when it's done.
        mLicenseCheckerCallback = new MyLicenseCheckerCallback();
        // Construct the LicenseChecker with a policy.
        mChecker = new LicenseChecker(
            this, new ServerManagedPolicy(this,
                new AESObfuscator(SALT, getPackageName(), deviceId)),
            BASE64_PUBLIC_KEY);
        doCheck();
    }

    protected Dialog onCreateDialog(int id) {
        final boolean bRetry = id == 1;
        return new AlertDialog.Builder(this)
            .setTitle(R.string.unlicensed_dialog_title)
            .setMessage(bRetry ? R.string.unlicensed_dialog_retry_body : R.string.unlicensed_dialog_body)
            .setPositiveButton(bRetry ? R.string.retry_button : R.string.buy_button, new DialogInterface.OnClickListener() {
                boolean mRetry = bRetry;
                public void onClick(DialogInterface dialog, int which) {
                    if ( mRetry ) {
                        doCheck();
                    } else {
                        Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "http://market.android.com/details?id=" + getPackageName()));
                            startActivity(marketIntent);                        
                    }
                }
            })
            .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            }).create();
    }

    private void doCheck() {
        mCheckLicenseButton.setEnabled(false);
        setProgressBarIndeterminateVisibility(true);
        mStatusText.setText(R.string.checking_license);
        mChecker.checkAccess(mLicenseCheckerCallback);
    }

    private void displayResult(final String result) {
        mHandler.post(new Runnable() {
            public void run() {
                mStatusText.setText(result);
                setProgressBarIndeterminateVisibility(false);
                mCheckLicenseButton.setEnabled(true);
            }
        });
    }

    private void displayDialog(final boolean showRetry) {
        mHandler.post(new Runnable() {
            public void run() {
                setProgressBarIndeterminateVisibility(false);
                showDialog(showRetry ? 1 : 0);
                mCheckLicenseButton.setEnabled(true);
            }
        });
    }    

    private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
        public void allow(int policyReason) {
            System.out.println("Allow");
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // Should allow user access.
            displayResult(getString(R.string.allow));
        }

        public void dontAllow(int policyReason) {
            System.out.println("dontAllow");
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            displayResult(getString(R.string.dont_allow));
            // Should not allow access. In most cases, the app should assume
            // the user has access unless it encounters this. If it does,
            // the app should inform the user of their unlicensed ways
            // and then either shut down the app or limit the user to a
            // restricted set of features.
            // In this example, we show a dialog that takes the user to Market.
            // If the reason for the lack of license is that the service is
            // unavailable or there is another problem, we display a
            // retry button on the dialog and a different message.
            displayDialog(policyReason == Policy.RETRY);
        }

        public void applicationError(int errorCode) {
            System.out.println("applicationError");
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // This is a polite way of saying the developer made a mistake
            // while setting up or calling the license checker library.
            // Please examine the error code and fix the error.
            String result = String.format(getString(R.string.application_error), errorCode);
            displayResult(result);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mChecker.onDestroy();
    }

}

I follow the tutorial for setting up LVL as a library project and those imports seem to be ok.

Why do I get this error? Why can it not find the inner class? If I right click and say show definition it jumps to the inner class.

解决方案

So this SO Answer is what fixed it I created a folder called libs and coppied the library.jar file from the library project included in the licensing package downloaded with the manager

What I dont understand is per this answer this should have been done for me As I am using ADT 20.0.3

Basically it comes down to an example that I downloaded directly from android and got stuck for a few hours trying to figure out what was wrong and this seems like this step should have been in the readme/help docs OR Im doing something wrong.

If you know why this is the answer and how to do it better please answer and Ill change the answer to yours.

这篇关于noclassdeferror的内部类MyLicenseCheckerCallback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆