Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用片段替换AppCompatActivity,但不能访问旧类_Java_Android_Android Fragments_Fragment_Appcompatactivity - Fatal编程技术网

Java 用片段替换AppCompatActivity,但不能访问旧类

Java 用片段替换AppCompatActivity,但不能访问旧类,java,android,android-fragments,fragment,appcompatactivity,Java,Android,Android Fragments,Fragment,Appcompatactivity,我试着用这个来创建底部栏 但是,我有一个现有的项目,已经实现的类很少,当我试图按片段更改AppCompatActivity时,我的旧方法/类是无法访问的 旧阶级的例外: public class ChoixFormulaire extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved

我试着用这个来创建底部栏

但是,我有一个现有的项目,已经实现的类很少,当我试图按片段更改AppCompatActivity时,我的旧方法/类是无法访问的

旧阶级的例外:

public class ChoixFormulaire extends Fragment {


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView=inflater.inflate(R.layout.activity_choix_formulaire,container,false);

        return rootView;
    }

    public void formJ(View v){
        Intent i = new Intent(ChoixFormulaire.this,RechercheJournalier.class);
        startActivity(i);
    }
    public void formP(View v){
        Intent i = new Intent(ChoixFormulaire.this,FormulaireRecherche.class);
        startActivity(i);
    }
    public void retourF(View v){
        Intent i = new Intent(ChoixFormulaire.this,RechercheDuJour.class);
        startActivity(i);
    }
但是,堡垒的这一部分:

(ChoixFormulaire.this,RechercheJournalier.class);
(ChoixFormulaire.this,FormulaireRecherche.class);
(ChoixFormulaire.this,RechercheDuJour.class);
我有一个错误:

"Cannot resolve constructor 'Intent(com.appli.cci.ports2a.Recherches.ChoixFormulaire, java.lang.Class<com.appli.cci.ports2a.Recherches.RecherchesJournalier>)'
“无法解析构造函数的意图(com.appli.cci.ports2a.Recherches.ChoixFormulaire,java.lang.Class)”

需要使用父活动或应用程序上下文创建意图。因此,您需要使用片段的父活动上下文

Intent intent = new Intent(getActivity(),MyClass.class);
您需要从第一个活动传递数组,如下所示:-

Bundle bundle=new Bundle();
bundle.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(bundle);
您可以从类似这样的其他活动中获取数组

Bundle bundle=this.getIntent().getExtras();
String[] array=bundle.getStringArray(key);

您没有正确使用上下文检查此项

 public void formJ(View v){
            Intent i = new Intent(getActivity(),RechercheJournalier.class);
            startActivity(i);
        }

您可以使用活动的上下文打开新活动。这项工作做得很好!但是,在我现在拥有的另一个类中:spinnerary2=mA.getspinnerary();Csa=new CustomSpinnerAdapter(this,R.layout.content_spinner,spinnerary2);spin2.setAdapter(Csa);idDefaultStr=mA.getIdSpin();idDefault=Integer.parseInt(idDefaultStr)-1;我在以下位置有一个错误:-mA.getSpinNerray();-mA.getiDSpin()你知道为什么吗?mA是什么?如果你在主活动中定义了数组列表,并试图进入另一个数组列表,这不是获得它的正确方法。这项工作做得很好!但是,在另一个类中,我现在有了:spinnerary2=mA.getspinnerary();Csa=new CustomSpinnerAdapter(this,R.layout.content\u spinner,spinnerary2);spin2.setAdapter(Csa);idDefaultStr=mA.getIdSpin();idDefault=Integer.parseInt(idDefaultStr)-1;我的错误在:-mA.getspinnerray();-mA.getIdSpin()你知道为什么吗?