简体   繁体   中英

How can I compile fragment and AppCompatActivity in Java?

I am a beginner in coding and I am making an app for a school project. I made a drawer menu using the Android fragment, but now I want to include features under AppCompatActivity in Java class. I cannot compile the fragment with the AppCompatActivity in the Java class. Please see the code below:

public class ProfileFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_about, container, false);
}


public class about extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_about);
}

Hello @aviraj Welcome to the Stackoverflow.

See basically, In order to compile any class which extends Fragment , AppCompatActivity you also need to map these core classes to Android SDK.

If you will just going to put them out in simple text file, it will not going to get the implementation of Fragment , AppCompatActivity from JRE/JDK. Hence, it will not be compile.

Suggest you to go through the basics of Android Development from developer.android.com and you will find step by step guidance about building process of Android App.

Hope it will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM