2013-10-19 86 views
1

我试图更新控制通过sendListCountWithContent()方法2 ListView项内容(有一个的TextView)上的SmartWatch:的SmartWatch 2的sendListCountWithContent()抛出ClassCastException异常

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

索尼并没有提供API方法网页的javadoc(仅在帐篷),所以我在这里的摘录:

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方法应用发送CONTROL_LIST_COUNT_INTENT意图到主机应用程序(的SmartConnect),则主机应用程序重新发送意图仿真器(或连接SmartWatch2),其它建立一个基于布局对意向演员。这里抛出一个ClassCastException。

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

回答

0

我们意识到这个错误,并且已经实施了一个修补程序,可以在下一个版本的Sony Add-on SDK中使用。