将片段类传递给addSlide方法时所期望的表达式

时间:2015-09-14 06:13:25

标签: java android git android-fragments

我正在制作一个简单的纪录片应用程序,我想在第一次运行时实现appIntro。 我刚刚在GIT上创建了下面的代码,但是在将片段类传递给addSlide方法时,AS给出了错误“Expression Expected”。 我尝试清理项目并重建LOG中显示的错误:

错误:(19,18)错误:找不到符号变量ScreenSlidePageFragment 错误:(20,18)错误:找不到符号变量slide2 错误:(21,18)错误:找不到符号变量slide3 错误:(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文件或其他类中没有错误 谁能告诉我我的代码有什么问题?

1 个答案:

答案 0 :(得分: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);
}
....
}