开发者

getting ClassCastException while creating an object of SlidingTab widget

I have written a simple android application in which an Activity class implements the OnTriggerListener() callback for SlidingTab interface. I have defined the SlidingTab widget in the main.xml file inside the layout folder. The code is followed as

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">

    <!-- (1) incomingCallWidget: the UI displayed while an incoming call is ringing. -->
    <com.android.internal.widget.SlidingTab
        android:id="@+id/incomingCallWidget"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="80dip"
        />

</LinearLayout>

The code of Activity class is followed as

public class Sliding extends Activity implement开发者_运维问答s SlidingTab.OnTriggerListener{
    /** Called when the activity is first created. */

    private SlidingTab mIncomingCallWidget;
    private static final int IN_CALL_WIDGET_TRANSITION_TIME = 250; // in ms

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.incall_touch_ui);

        mIncomingCallWidget = (SlidingTab) findViewById(R.id.incomingCallWidget);
        mIncomingCallWidget.setLeftHintText(R.string.slide_to_divert_hint);
        mIncomingCallWidget.setRightHintText(R.string.slide_to_accept_hint);
        mIncomingCallWidget.setOnTriggerListener((OnTriggerListener) this);
    }

Now I am getting a ClassCastException at the line

mIncomingCallWidget = (SlidingTab) findViewById(R.id.incomingCallWidget);

i.e. while instantiating the object.

Please let me provide helpful information how can I fix this issue.


Your code refers to "R.layout.incall_touch_ui". That would cause Android to look in the file "res/layout/incall_touch_ui.xml", not "res/layout/main.xml".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜