SmartWatch 2的sendListCountWithContent()引发了ClassCastException

时间:2013-10-19 15:19:47

标签: android sony sony-smartwatch

我试图通过sendListCountWithContent()方法在SmartWatch 2 Control上更新ListView项目内容(使用一个TextView):

public class SmartWatch2Control extends ControlExtension {

    private List<String> accs;

    @Override
    public void onResume() {
        accs = Utils.getAllAccounts();
        showLayout(R.layout.smartwatch2, null);
        sendListCountWithContent(R.id.smartwatch2_list, accs.size(),
            bundlesForList(accs));
        sendListPosition(R.id.smartwatch2_list, 0);
    }

    private Bundle[] bundlesForList(List<String> list) {
        Bundle[] result = new Bundle[list.size()];

        for (int i = 0; i < list.size(); i++) {
            Bundle nameBundle = new Bundle();
            nameBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE,
                R.id.acc_name);
            nameBundle.putString(Control.Intents.EXTRA_TEXT, list.get(i));
            Bundle[] views = new Bundle[] { nameBundle };

            Bundle b = new Bundle();
            b.putInt(Control.Intents.EXTRA_DATA_XML_LAYOUT,
                R.layout.smartwatch2_item);
            b.putInt(Control.Intents.EXTRA_LIST_ITEM_ID, i);
            b.putInt(Control.Intents.EXTRA_LIST_ITEM_POSITION, i);
            b.putParcelableArray(Control.Intents.EXTRA_LAYOUT_DATA, views);

            result[i] = b;
        }

        return result;
    }
}

当我尝试在SmartWatch 2模拟器上启动应用程序时,我得到了例外:

10-19 14:49:17.823: ERROR/AndroidRuntime(8841): FATAL EXCEPTION: main
        java.lang.ClassCastException: android.os.Parcelable[] cannot be cast to android.os.Bundle[]
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.CostanzaListAdapter.<init>(CostanzaListAdapter.java:40)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.renderListView(ControlActivity.java:632)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.access$10(ControlActivity.java:624)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity$8.run(ControlActivity.java:447)
        at android.app.Activity.runOnUiThread(Activity.java:4170)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.onListCount(ControlActivity.java:441)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.handleEvent(ControlActivity.java:264)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.CostanzaActivity$ServiceMessageHandler.handleMessage(CostanzaActivity.java:240)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4575)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
        at dalvik.system.NativeStart.main(Native Method)

link to test project

Sony没有在api方法上提供web javadocs(只有意图)所以我在这里提供一个摘录:

package com.sonyericsson.extras.liveware.extension.util.control;

public abstract class ControlExtension {

<..>

    protected void sendListCountWithContent(int layoutReference, int listCount, Bundle[] bundles) {
        Intent intent = new Intent(Control.Intents.CONTROL_LIST_COUNT_INTENT);
        intent.putExtra(Control.Intents.EXTRA_LAYOUT_REFERENCE, layoutReference);
        intent.putExtra(Control.Intents.EXTRA_LIST_COUNT, listCount);
        intent.putExtra(Control.Intents.EXTRA_LIST_CONTENT, bundles);
        sendToHostApp(intent);
    }

<..>

}

当我调用sendListCountWithContent方法应用程序向主机应用程序(SmartConnect)发送CONTROL_LIST_COUNT_INTENT意图时,主机应用程序将意图重新发送到基于意图附加功能构建布局的模拟器(或连接的SmartWatch2)。抛出一个ClassCastException。

我不确定,但它看起来像是模拟器中的错误。

1 个答案:

答案 0 :(得分:0)

我们知道这个错误,并且已经实施了一个修复程序,该修补程序将在下一版本的Sony Add-on SDK中提供。