2015-09-14 37 views
1

我正在研究一個簡單的紀錄片應用程序,並且我想實現第一次運行的appIntro。 我剛剛在GIT上創建了以下代碼,但在將片段類傳遞給addSlide方法時,AS給了我「Error Expected」的錯誤。 我試圖項目清潔和重建LOG所示的錯誤是這樣的:將片段類傳遞給addSlide方法時的預期表達式

錯誤:(19,18)誤差:無法找到符號變量ScreenSlidePageFragment 錯誤:(20,18)誤差:無法找到符號可變滑件 錯誤:(21,18)錯誤:無法找到符號變量滑件3 錯誤:(22,18)錯誤:無法找到符號變量slide4

這裏是我的AppIntro類:

import android.graphics.Color; 
import android.os.Bundle; 

import com.github.paolorotolo.appintro.AppIntro; 
import com.github.paolorotolo.appintro.AppIntroFragment; 

    /** 
     * Created by ASUS on 9/14/2015. 
    */ 
public class MyIntro extends AppIntro { 
    // Please DO NOT override onCreate. Use init 
    @Override 
    public void init(Bundle savedInstanceState) { 

    // Add your slide's fragments here 
    // AppIntro will automatically generate the dots indicator and buttons. 
    addSlide(ScreenSlidePageFragment); 
    addSlide(slide2); 
    addSlide(slide3); 
    addSlide(slide4); 


    // Instead of fragments, you can also use our default slide 
    // Just set a title, description, background and image. AppIntro will do the rest 
// addSlide(AppIntroFragment.newInstance("dansjoo","hello stdents","/drawable/introback1.png", "black")); 

    // OPTIONAL METHODS 
    // Override bar/separator color 
    setBarColor(Color.parseColor("#3F51B5")); 
    setSeparatorColor(Color.parseColor("#2196F3")); 
    setFlowAnimation(); 

    // Hide Skip/Done button 
    showSkipButton(false); 
    showDoneButton(false); 

    // Turn vibration on and set intensity 
    // NOTE: you will probably need to ask VIBRATE permesssion in Manifest 
    setVibrate(true); 
    setVibrateIntensity(30); 
} 



@Override 
public void onSkipPressed() { 
    // Do something when users tap on Skip button. 
} 

@Override 
public void onDonePressed() { 
    // Do something when users tap on Done button. 
}} 

而且這裏是一個我的片段類:

  package com.google.myapplication02; 

    import android.app.Fragment; 
    import android.os.Bundle; 
    import android.view.LayoutInflater; 
    import android.view.View; 
    import android.view.ViewGroup; 

     /** 
     * Created by ASUS on 9/12/2015. 
     */ 
     public class ScreenSlidePageFragment extends Fragment { 
public View onCreateView(LayoutInflater infaltor,ViewGroup container,Bundle savedInstanceState) 
{ 
    ViewGroup rootView = (ViewGroup)infaltor.inflate(R.layout.intro1,container,false); 
    return rootView; 
}} 

我在XML文件或其他類中沒有錯誤 誰能告訴我我的代碼有什麼問題?

回答

0

我認爲有什麼不對,你必須在addSlide(ScreenSlidePageFragment)中調用它們之前創建片段的實例;

public class MyIntro extends AppIntro { 

Appintro1 appIntro1 = new Appintro1(); 
Appintro2 appIntro2 = new Appintro2(); 
ScreenSlidePageFragment appIntro3 = new ScreenSlidePageFragment(); 

@Override 
public void init(Bundle savedInstanceState) { 
addSlide(appIntro1); 
addSlide(appIntro2) 
addSlide(appIntro3); 
} 
.... 
}