2014-05-19 3 views
0

내 코드가 잘못된 요소를 형 변환하려고 시도하여 ClassCastException이 발생합니다. 당신이 전에 본/제안이 있으십니까?ViewPager를 사용하는 ClassCastException

활동

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.activity_clue); 

    cluesUnlocked = getIntent().getIntExtra(NUMBER_OF_CLUES_UNLOCKED, 4); 
    MyAdapter mAdapter = new MyAdapter(getSupportFragmentManager()); 
    ViewPager mPager = (ViewPager) findViewById(R.id.vp_clues); // LINE 34 - ERROR 
    mPager.setAdapter(mAdapter); 

    CirclePageIndicator mIndicator = (CirclePageIndicator)findViewById(R.id.indicator); 
    mIndicator.setViewPager(mPager); 

    //We set this on the indicator, NOT the pager 
    mIndicator.setOnPageChangeListener(new MyOnPageChangeListener()); 
} 

activity_clue.xml

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/container" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
tools:context="com.mgd.theexplorer.ClueActivity" 
android:baselineAligned="false" 
tools:ignore="MergeRootFrame"> 

    <com.viewpagerindicator.CirclePageIndicator 
     android:id="@+id/indicator" 
     android:padding="10dip" 
     android:layout_height="25dip" 
     android:layout_width="fill_parent" /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/vp_clues" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
</android.support.v4.view.ViewPager> 


</LinearLayout> 

스택 트레이스

05-19 12 : 35 : 30.439 : E/AndroidRuntime (25,489) : 원인 by : java.lang.ClassCastException : com.viewpagerindicator.CirclePageIndicator를 으로 캐스팅 할 수 없습니다. android.support.v4.view.ViewPager 05-19 12 : 35 : 30.439 : E/AndroidRuntime (25489) : com.mgd. 코드 (ViewPager) findViewById(R.id.vp_clues);가 실제로 CirclePageIndicator입니다 생각 ClassCastException이 발생하는 이유 theexplorer.ClueActivity.onCreate (ClueActivity.java:34)

는 이해가 안 돼요.

정보에 대한

: CirclePageIndicator는 다음 라이브러리의 일부입니다

+1

깨끗한 프로젝트와 r un – Manishika

+1

나는 이것을 전에 시도했지만, 트릭을 한 것으로 보인다. upvote/accepted 대답을 원한다면 이것을 대답으로 추가하십시오. – Harry

+0

@Harry 질문 해 주셔서 감사합니다. – cammando

답변

4

이 시도 : 프로젝트를 다시

  • 가 구축

    1. 깨끗하고 실행 프로젝트를

    는 희망 도와주세요

  • +0

    이 단계를 시도해 보았습니다. 내 버그를 해결하는 데 정말로 도움이되었습니다. 감사합니다. Manishika –

    관련 문제