Programming Android Studio

Asked

Viewed 74 times

0

Error in Second "public class", 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();
    }

}
  • 3

    Classes cannot have equal names being in the same package or file. Try renaming.

  • extends Fragment e extends Appcompatactivity I need to put them in the same class.

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 constraint is that more than one public class can only be declared in the same file if it is Inner class, i.e., if it is an "internal" class of the main public class. Since in your case it’s a class and an Internet class, it’ll work.

NOTE: It is also important to note 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 properly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.