测试执行期间MobileFirst Test Workbench ClassCastException

时间:2015-04-21 15:58:13

标签: android ibm-mobilefirst mobilefirst-mtw

MobileFirst Test Workbench 8.7(包含在MobileFirst Platform 7.0中) 经测试的设备:android 4.4.2 经过测试的app:原生应用程序 Android SDK工具:23.0.2 Android SDK平台工具:20 Android SDK Build-tools:19.1

在测试执行期间,在listView元素上单击事件后报告以下异常。 录制测试用例时未报告此错误。

Exception thrown: ClassCastException: android.widget.ListView cannot be cast to android.widget.RelativeLayout
  at com.xx.yy.CatalNavFragment.onItemClick(CatalNavFragment.java:267)
  at android.widget.AdapterView.performItemClick(AdapterView.java:308)
  at android.widget.AbsListView.performItemClick(AbsListView.java:1478)
  at com.ibm.rational.test.mobile.android.runtime.playback.engine.actions.Action_itemclickposition.performAction(Action_itemclickposition.java:40)
  at com.ibm.rational.test.mobile.android.runtime.playback.engine.actions.Action.performAction(Action.java:101)
  at com.ibm.rational.test.mobile.android.runtime.playback.engine.ATestStep$1.run(ATestStep.java:502)
  at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5356)
  at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(Native Method)

引发异常的代码:

 @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {

        ContentValues niveau = (ContentValues) catalNavAdapter
                .getItem(position);

        id_niveau = niveau.getAsString(CatalProvider.KEY_ID);
        Long niveau_usg = niveau.getAsLong(CatalProvider.KEY_NIVEAU);
        RelativeLayout rlyt = (RelativeLayout) view; //!! EXCEPTION IS RAISED HERE
        TextView txtLibelle = (TextView) rlyt.getChildAt(0);
        Bundle i = new Bundle();
        if (niveau_usg > 0) {
            String subcategory = txtLibelle.getText().toString();
            CatalProdFragment CPF = new CatalProdFragment();
            i.putString("id_niveau", id_niveau);
            i.putLong("niveau_usg", niveau_usg);
            i.putString("subcategory", subcategory);
            i.putString("category", extras.getString("category"));
            CPF.setArguments(i);
            TabHolderFragmentActivity.getMainScreenActivity().pushFragments(parentTab, CPF, CPF
                    .getClass().getSimpleName(), true, true);
        } else {
            CatalNavFragment CNF = new CatalNavFragment();
            i.putString("id_niveau", id_niveau);
            i.putString("category", catalNavAdapter.getData().get(position)
                    .getAsString("libelle"));// category);
            CNF.setArguments(i);
            TabHolderFragmentActivity.getMainScreenActivity().pushFragments(parentTab, CNF, CNF
                    .getClass().getSimpleName(), true, true);
        }
        setExitPageBoolean(false);
    }

ListView布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/catalpage"
    android:background="@color/greybg" >

    <include
        android:id="@+id/include_conatiner"
        layout="@layout/produits_container" />

    <TextView
        android:id="@+id/catal_list_title"
        style="@style/screenHeader"
        android:layout_below="@id/include_conatiner"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="5dp"
        android:gravity="center_vertical"
        android:text="@string/produits_header"
        android:visibility="gone" />

    <ListView
        android:id="@android:id/list"
        style="@style/catal_list"
        android:layout_below="@+id/catal_list_title" />

    <TextView
        android:id="@id/android:empty"
        style="@style/texte.error"
        android:layout_below="@+id/catal_list_title" />

</RelativeLayout>

Listview项目布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rlyt_cat_nav_item"
    style="@style/catal_list_item" >

    <TextView
        android:id="@+id/catal_nav_libelle"
        style="@style/texte.titre.center"
        android:layout_width="wrap_content"
        android:layout_marginLeft="5dp"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/catal_nav_count_libelle"
        style="@style/texte_parent_right"
        android:padding="5dp"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/catal_nav_id_niveau"
        style="@style/hidden" />

</RelativeLayout>

感谢您的帮助

马修

1 个答案:

答案 0 :(得分:0)

问题来自rtw 8.7及更早版本中的一个小错误 (简而言之,传递给监听器的一些参数是错误的。位置正常,视图不是) 联系我们对8.7修补程序的支持,或等待包含它的8.7.0.1(应该很快就会提供)

Jerome Bozier 高级软件工程师 IMB RTW mobile for android