1

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: Unable to instantiate activity ComponentInfo{com.samsungapps.plasma.plasmatester/com.samsungapps.plasma.plasmatester.PlasmaTesterActivity}: java.lang.ClassNotFoundException: com.samsungapps.plasma.plasmatester.PlasmaTesterActivity in loader 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";
}

和清单文件

<?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>
4

1 回答 1

1

你把罐子放在你的libs文件夹里了吗?(您说您添加了它,但没有添加它的位置/方式)。

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

于 2012-06-01T13:42:40.623 回答