0

我知道这个问题已经在这个论坛上发布过很多次了。我已经检查了我的 Manifest xml 文件,并且已经为此工作了几天。我已经在 Manifest xml 中声明了我的 Activity,但仍然出现此错误。如何摆脱这个运行时错误?

日志猫:

08-05 22:24:25.037: E/AndroidRuntime(1912): FATAL EXCEPTION: main
08-05 22:24:25.037: E/AndroidRuntime(1912): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.powersourceinternational.main/com.zooz.android.lib.CheckoutActivity}: java.lang.ClassCastException: com.carouseldemo.main.ZooZInvoice
08-05 22:24:25.037: E/AndroidRuntime(1912):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at android.app.ActivityThread.access$1500(ActivityThread.java:132)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at android.os.Looper.loop(Looper.java:150)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at android.app.ActivityThread.main(ActivityThread.java:4263)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at java.lang.reflect.Method.invokeNative(Native Method)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at java.lang.reflect.Method.invoke(Method.java:507)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at dalvik.system.NativeStart.main(Native Method)
08-05 22:24:25.037: E/AndroidRuntime(1912): Caused by: java.lang.ClassCastException: com.carouseldemo.main.ZooZInvoice
08-05 22:24:25.037: E/AndroidRuntime(1912):     at com.zooz.android.lib.CheckoutActivity.onCreate(Unknown Source)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
08-05 22:24:25.037: E/AndroidRuntime(1912):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
08-05 22:24:25.037: E/AndroidRuntime(1912):     ... 11 more

班级:

 package com.carouseldemo.main;

import java.io.Serializable;

public class ZooZInvoice implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * 
     */


    public void addItem(String string, int i, double d, int j, String string2,
            String string3) {
        // TODO Auto-generated method stub

    }

    public void setInvoiceNumber(String string) {
        // TODO Auto-generated method stub

    }

    public void setInvoiceAdditionalDetails(String string) {
        // TODO Auto-generated method stub

    }

}

清单 XML:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.powersourceinternational.main"
      android:versionCode="4"
      android:versionName="1.3"
      >
      <uses-permission android:name ="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" android:screenOrientation="portrait"/>
    <application android:icon="@drawable/iconapp4" android:label="@string/app_name">

        <activity android:name="com.paypal.android.MEP.PayPalActivity"

android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="keyboardHidden|orientation|screenSize"/>  
<activity android:name=".ZooZInvoice" android:label="@string/app_name"/>
        <activity android:name="com.zooz.android.lib.CheckoutActivity"
android:theme="@android:style/Theme.Translucent"
android:configChanges="keyboardHidden|orientation|screenSize"/>
        <activity android:name="com.carouseldemo.main.Manu"> 

            </activity>
        <activity android:name="com.carouseldemo.main.Splash" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden" >



            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.carouseldemo.main.MainActivity" android:screenOrientation="portrait"/>
    </application>
</manifest> 

主要活动中的结帐活动代码:

public void onCheckoutClick(View v) {
        // create new intent CheckoutActivity
        Intent intent = new Intent(this, CheckoutActivity.class);
        // supply app-key on the intent
        intent.putExtra(CheckoutActivity.ZOOZ_APP_KEY, "key");
        // supply transaction details (amount, currency)
        intent.putExtra(CheckoutActivity.ZOOZ_AMOUNT, 500.00);

        intent.putExtra(CheckoutActivity.ZOOZ_CURRENCY_CODE, "USD");
        // supply environment mode (sandbox or production)
        intent.putExtra(CheckoutActivity.ZOOZ_IS_SANDBOX, true);

        ZooZInvoice invoice = new ZooZInvoice();
        invoice.addItem("item1", 1, 0.5, 0, "1", "good choice!");
        invoice.addItem("item2", 1, 3, 0, "2", "additional details for item 2");
        invoice.addItem("item3", 1, 2, 0, "3", "additional details for item 3");
        invoice.addItem("item4", 1, 8, 0, "4", "additional details for item 4");
        invoice.setInvoiceNumber("5512-FA");
        invoice.setInvoiceAdditionalDetails("Power Ups for user 12345");
        intent.putExtra(CheckoutActivity.ZOOZ_INVOICE, invoice);

        startActivityForResult(intent, ZooZ_Activity_ID);

    }

我已经尝试将清单中的活动声明为 com.carouseldemo.main.ZooZInvoice 和 com.powersourceinternational.main.ZooZInvoice (即使路径方式是第一个,com.carouseldemo.main.ZooZInvoice

我怎样才能摆脱这个错误?

我用来编写此代码的原始参考指南:https ://app.zooz.com/portal/PortalController?cmd=resources

它是 PDF 格式的,代码在第 20 页的底部。

4

1 回答 1

0

方法中的错误com.zooz.android.lib.CheckoutActivity.onCreate。它尝试将ZooZInvoice类的对象转换为其他类。您将类的对象ZooZInvoice作为参数传递CheckoutActivity.ZOOZ_INVOICE。在库的文档中检查它预期的类型,并使您的类ZooZInvoice继承自该类型或使用预期的类型。

编辑:您应该使用ZooZInvoice库中的类,而不是您自己的同名类。

于 2013-08-06T03:18:43.733 回答