2013-07-22 89 views
1

當我嘗試測試我的應用程序時,突然出現意外的異常,我不知道原因,請幫助我找到該錯誤。 (錯誤是:could not find class "com.example.MyPagerAdapter「)運行時間Exceptiom:找不到類

這是我第二次活動代碼

:此應用程序只是測試輕掃在我只是從MyPagerAdapter類中定義的適配器,然後定義ViewPager這樣

ViewPager myPager = (ViewPager) findViewById(R.id.home_pannels_pager); 

然後設置在適配器和當前項= 0

package com.example.tstswipe; 

import android.content.Context; 
import android.content.Intent; 
import android.os.Parcelable; 
import android.support.v4.view.PagerAdapter; 
import android.support.v4.view.ViewPager; 
import android.view.View; 
import android.webkit.WebView.FindListener; 
import android.widget.Button; 
import android.widget.LinearLayout; 
import android.widget.TextView; 

public class MyPagerAdapter extends PagerAdapter { 

    // State number of pages 
    public int getCount() { 
     return 5; 
    } 

    // Set each screen's content 
    public Object instantiateItem(View container, int position) { 
     Context context = container.getContext(); 
     LinearLayout layout = new LinearLayout(context); 
     // Add elements 
     TextView textItem = new TextView(context); 


     Button buttonItem = new Button(context); 
     buttonItem.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent("com.phone"); 
       // myFancyMethod(v); 
      } 
     }); 


     switch (position) { 
     case 0: 
      textItem.setText("First Screen"); 
      break; 
     case 1: 
      textItem.setText("Second Screen"); 
      break; 
     case 2: 
      textItem.setText("Third Screen"); 
      break; 


     case 3: 
     textItem.setText("Fourth Screen"); 
     break; 
     case 4: 
     textItem.setText("Fifth Screen"); 
     break; 
    } 
    layout.addView(textItem); 
    ((ViewPager) container).addView(layout, 0); // This is the line I added 
    return layout; 
} 
public void destroyItem(View arg0, int arg1, Object arg2) { 
    ((ViewPager) arg0).removeView((View) arg2); 
} 
public boolean isViewFromObject(View arg0, Object arg1) { 
    return arg0 == ((View) arg1); 
} 
public Parcelable saveState() { 
    return null; 
} 

}

+1

請發佈您logcat消息和活動代碼 –

+0

您是否將第二個活動添加到清單? –

+0

Logcat?什麼命令導致這個問題?碼? –

回答

0

您聲明錯誤爲could not find class "com.example.MyPagerAdapter",但您發佈的類的完全限定名稱爲com.example.tstswipe.MyPagerAdapter

+0

對不起,這是我的錯誤錯誤是找不到類com.example.tstswipe.MyPagerAdapter。 –

+0

這正是我在logcat中發現java.lang.RuntimeException:無法啓動活動ComponentInfo {com.example.tstswipe/com.example.tstswipe.MainActivity}:android.view.InflateException:二進制XML文件行#7:錯誤膨脹類android.support.v4.view.ViewPager –

相關問題