android - 三星 android 应用程序内代码不起作用

标签 android in-app

1 添加了 1 个 jar API 文件。这是示例代码的其余部分

我是从http://innovator.samsungmobile.com/cms/cnts/knowledge.detail.view.do?platformId=1&cntsId=9986&nacode=下载的

我收到错误:

06-01 18:22:31.900: E/AndroidRuntime(24713): java.lang.RuntimeException: 无法实例化 Activity ComponentInfo{com.samsungapps.plasma.plasmatester/com.samsungapps.plasma.plasmaster.PlasmaTesterActivity}: java.lang.ClassNotFoundException: com.samsungapps.plasma.plasmatester.PlasmaTesterActivity 在加载程序 dalvik.system.PathClassLoader[/data/app/com.samsungapps.plasma.plasmatester-1.apk]

    public class PlasmaTesterActivity extends Activity implements PlasmaListener {
    private class ItemInformationListAdapter extends
            ArrayAdapter<ItemInformation> {

        public ItemInformationListAdapter(Context context,
                int textViewResourceId, ArrayList<ItemInformation> objects) {
            super(context, textViewResourceId, objects);

            __itemInformationList = objects;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater inflater = PlasmaTesterActivity.this
                        .getLayoutInflater();
                v = inflater.inflate(R.layout.row, null);
            }

            final ItemInformation pi = __itemInformationList.get(position);
            if (pi != null) {
                TextView tv1 = (TextView) v.findViewById(R.id.textView1);
                tv1.setText(pi.getItemName());
                TextView tv2 = (TextView) v.findViewById(R.id.textView2);
                tv2.setText(getPriceStringWithCurrencyUnit(pi));
                TextView tv3 = (TextView) v.findViewById(R.id.textView3);
                tv3.setText(pi.getItemDescription());
                Button b = (Button) v.findViewById(R.id.button1);
                b.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        __plasma.requestPurchaseItem(__transactionId++,
                                pi.getItemId());
                    }
                });
            }

            return v;
        }

        private ArrayList<ItemInformation> __itemInformationList = null;
    }

    private class PurchasedItemInformationListAdapter extends
            ArrayAdapter<PurchasedItemInformation> {

        public PurchasedItemInformationListAdapter(Context context,
                int textViewResourceId,
                ArrayList<PurchasedItemInformation> objects) {
            super(context, textViewResourceId, objects);

            __purchasedItemInformationList = objects;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater inflater = PlasmaTesterActivity.this
                        .getLayoutInflater();
                v = inflater.inflate(R.layout.row, null);
            }

            final PurchasedItemInformation pi = __purchasedItemInformationList
                    .get(position);
            if (pi != null) {
                TextView tv1 = (TextView) v.findViewById(R.id.textView1);
                tv1.setText(pi.getItemName());
                TextView tv2 = (TextView) v.findViewById(R.id.textView2);
                tv2.setText(getPriceStringWithCurrencyUnit(pi));
                TextView tv3 = (TextView) v.findViewById(R.id.textView3);
                tv3.setText(pi.getPaymentId());

                Button b = (Button) v.findViewById(R.id.button1);
                b.setVisibility(View.GONE);
            }

            return v;
        }

        private ArrayList<PurchasedItemInformation> __purchasedItemInformationList = null;
    }

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

        __plasma = new Plasma(__ITEM_GROUP_ID, this);
        __plasma.setPlasmaListener(this);
        __plasma.setDeveloperFlag(1);

        ArrayList<ItemInformation> itemInformationList = new ArrayList<ItemInformation>();
        __itemInformationListAdapter = new ItemInformationListAdapter(this,
                R.layout.row, itemInformationList);

        ArrayList<PurchasedItemInformation> purchasedItemInformationList = new ArrayList<PurchasedItemInformation>();
        __purchasedItemInformationListAdapter = new PurchasedItemInformationListAdapter(
                this, R.layout.row, purchasedItemInformationList);

        ListView itemList = (ListView) findViewById(R.id.listView1);
        itemList.setAdapter(__itemInformationListAdapter);

        ListView purchaseList = (ListView) findViewById(R.id.listView2);
        purchaseList.setAdapter(__purchasedItemInformationListAdapter);

        Button getItemListButton = (Button) findViewById(R.id.button1);
        getItemListButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                __plasma.requestItemInformationList(__transactionId++, 1,
                        __ITEM_LIST_REQUEST_COUNT);
            }
        });

        Button getPurchaseListButton = (Button) findViewById(R.id.button2);
        getPurchaseListButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                __plasma.requestPurchasedItemInformationList(__transactionId++,
                        1, __ITEM_LIST_REQUEST_COUNT);
            }
        });
    }

    @Override
    public void onItemInformationListReceived(int transactionId,
            int statusCode, ArrayList<ItemInformation> itemInformationList) {
        switch (statusCode) {
        case Plasma.STATUS_CODE_SUCCESS:
            __itemInformationListAdapter.clear();
            for (int i = 0; i < itemInformationList.size(); i++) {
                ItemInformation itemInformation = itemInformationList.get(i);
                __itemInformationListAdapter.add(itemInformation);
            }
            __itemInformationListAdapter.notifyDataSetChanged();
            break;
        default:
            String errorMessage = "Failed to retrieve the item list";
            showErrorDialog(statusCode, errorMessage);
            break;
        }
    }

    @Override
    public void onPurchasedItemInformationListReceived(int transactionId,
            int statusCode,
            ArrayList<PurchasedItemInformation> purchasedItemInformationList) {
        switch (statusCode) {
        case Plasma.STATUS_CODE_SUCCESS:
            __purchasedItemInformationListAdapter.clear();
            for (int i = 0; i < purchasedItemInformationList.size(); i++) {
                PurchasedItemInformation purchasedItemInformation = purchasedItemInformationList
                        .get(i);
                __purchasedItemInformationListAdapter
                        .add(purchasedItemInformation);
            }
            __purchasedItemInformationListAdapter.notifyDataSetChanged();
            break;
        default:
            String errorMessage = "Failed to retrieve the purchase list";
            showErrorDialog(statusCode, errorMessage);
            break;
        }
    }

    @Override
    public void onPurchaseItemFinished(int transactionId, int statusCode,
            PurchasedItemInformation purchasedItemInformation) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);

        switch (statusCode) {
        case Plasma.STATUS_CODE_SUCCESS:
            StringBuilder purchasedItemInformationStringBuilder = new StringBuilder();
            purchasedItemInformationStringBuilder.append("Item name: ");
            purchasedItemInformationStringBuilder
                    .append(purchasedItemInformation.getItemName());
            purchasedItemInformationStringBuilder.append(__CR_LF);
            purchasedItemInformationStringBuilder.append("Item ID: ");
            purchasedItemInformationStringBuilder
                    .append(purchasedItemInformation.getItemId());
            purchasedItemInformationStringBuilder.append(__CR_LF);
            purchasedItemInformationStringBuilder.append("Payment ID: ");
            purchasedItemInformationStringBuilder
                    .append(purchasedItemInformation.getPaymentId());
            purchasedItemInformationStringBuilder.append(__CR_LF);
            purchasedItemInformationStringBuilder.append("Purchase date: ");
            purchasedItemInformationStringBuilder
                    .append(purchasedItemInformation.getPurchaseDate());

            purchasedItemInformationStringBuilder.append(__CR_LF);
            purchasedItemInformationStringBuilder.append("Price: ");
            purchasedItemInformationStringBuilder
                    .append(getPriceStringWithCurrencyUnit(purchasedItemInformation));

            alertDialogBuilder.setTitle("Purchase information");
            alertDialogBuilder.setMessage(purchasedItemInformationStringBuilder
                    .toString());
            alertDialogBuilder.show();
            break;
        case Plasma.STATUS_CODE_CANCEL:
            break;
        default:
            String errorMessage = "Failed to purchase the item";
            showErrorDialog(statusCode, errorMessage);
            break;
        }
    }

    private void showErrorDialog(int errorCode, String errorMessage) {
        String errorMessageWithCode = String.format("%s (%d)", errorMessage,
                errorCode);

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle("Error");
        alertDialogBuilder.setMessage(errorMessageWithCode);
        alertDialogBuilder.show();
    }

    private String getPriceStringWithCurrencyUnit(
            ItemInformation itemInformation) {
        String priceStringFormatString = null;
        if (itemInformation.getCurrencyUnitHasPenny()) {
            priceStringFormatString = "%.2f";
        } else {
            priceStringFormatString = "%.0f";
        }

        String priceString = String.format(priceStringFormatString,
                itemInformation.getItemPrice());

        StringBuffer priceStringWithCurrencyUnitBuffer = new StringBuffer();
        if (itemInformation.getCurrencyUnitPrecedes()) {
            priceStringWithCurrencyUnitBuffer.append(itemInformation
                    .getCurrencyUnit());
            priceStringWithCurrencyUnitBuffer.append(priceString);
        } else {
            priceStringWithCurrencyUnitBuffer.append(priceString);
            priceStringWithCurrencyUnitBuffer.append(itemInformation
                    .getCurrencyUnit());
        }

        return priceStringWithCurrencyUnitBuffer.toString();
    }

    private ItemInformationListAdapter __itemInformationListAdapter = null;
    private PurchasedItemInformationListAdapter __purchasedItemInformationListAdapter = null;
    private int __transactionId = 0;
    private Plasma __plasma = null;

    private static final String __ITEM_GROUP_ID = "100000008752";
    private static final int __ITEM_LIST_REQUEST_COUNT = 15;
    private static final String __CR_LF = "\n";
}

和 list 文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.samsungapps.plasma.plasmatester" android:versionCode="1"
    android:versionName="1.5">
    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".PlasmaTesterActivity" android:label="@string/app_name"
            android:configChanges="orientation|keyboardHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

最佳答案

您是否将 jar 放在您的 libs 文件夹中? (你说你添加了它但不是在哪里/如何)。

他们最近更改了要求,他们现在需要进入我上面提到的 libs 文件夹。

关于android - 三星 android 应用程序内代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10851332/

相关文章:

java - 应用程序生成 UUID?

java - Android:如何在选择特定月份和工作日后获取该月的所有日期?

android - 创建自定义 View ,如车轮组件

从 csv 文件导入 Android 应用内商品

flutter - 使用 Flutters 应用内购买插件检查订阅有效性?

android - 在 OpenGL 中卸载顶点缓冲区

android - 是否可以在 ChromeBook 上安装 Android Studio?

带有 PhoneGap Build 的 iOS 10.3 应用内评级(或评论)——如何?

安卓应用内支付安全问题

ios - 如何处理未完成的iOS应用内购买消耗品?