Android Studio Programming

0

Second public class error, what can I do ???

If anyone knows please say.

Thank you.

package com.example.hsantos_98.artofthefire;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

public class ThirdFragment extends Fragment {

View myView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    myView = inflater.inflate(R.layout.third_layout, container, false);
    return myView;
}

public class ThirdFragment extends AppCompatActivity { 
    Animation fade_in, fade_out;
    ViewFlipper viewFlipper;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        viewFlipper = (ViewFlipper)  this.findViewById(R.id.bckgrndViewFlipper1);
        fade_in = AnimationUtils.loadAnimation(this,
                android.R.anim.fade_in);
        fade_out = AnimationUtils.loadAnimation(this,
                android.R.anim.fade_out);
        viewFlipper.setInAnimation(fade_in);
        viewFlipper.setOutAnimation(fade_out);

        viewFlipper.setAutoStart(true);
        viewFlipper.setFlipInterval(5000);
        viewFlipper.startFlipping();
    }

}
    
asked by anonymous 19.02.2017 / 18:27

1 answer

0

Java does not allow two classes in the same package to have the same name. What you should do is rename one of them. Another restriction is that more than one public class can only be declared in the same file if it is an inner class, that is, if it is an "internal" class the main public class. As in your case it is a class and an inner class, it will work.

NOTE: It is also important to stress that it does not make sense to give the same name to something that has different behaviors (Fragment and AppCompatActivity). That way, I suggest you review the purpose of each class to name them appropriately.

    
20.02.2017 / 12:35