I decided to try adding licenses to the application. Followed this instruction: link to instruction

I did everything as it was written, but here’s the 5th point of the instruction, it still does not work. Writes:

mistake

Error: Cannot resolve method 'show (android.app.FragmentManager, java.lang.String)'

It does not work to solve the problem. The instruction of the beginning of 2016. Maybe in the 2018th you need to write something different?

Question: how to write so that errors do not occur?

UPD1:

If you replace getFragmentManager() with getSupportFragmentManager() , then this situation occurs: mistake

Error: Cannot resolve method 'getSupportFragmentManager ()'

UPD2:

In LicensesDialogFragment:

 import android.app.AlertDialog; import android.app.Dialog; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.DialogFragment; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.webkit.WebView; public class LicensesDialogFragment extends DialogFragment { public static LicensesDialogFragment newInstance() { return new LicensesDialogFragment(); } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { WebView view = (WebView) LayoutInflater.from(getActivity()).inflate(R.layout.dialog_license, null); view.loadUrl("file:///android_asset/open_source_licenses.html"); return new AlertDialog.Builder(getActivity(), R.style.Theme_AppCompat_Light_Dialog_Alert) .setTitle(getString(R.string.action_licenses)) .setView(view) .setPositiveButton(android.R.string.ok, null) .create(); } } 

In Activity with a button:

 import android.app.Activity; import android.app.AlertDialog; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.DialogFragment; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class InformationActivity extends Activity { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.app_information); Button ShowLicensesBtn = (Button)findViewById(R.id.btn_licensesID); ShowLicensesBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { displayLicensesDialogFragment(); } }); } private void displayLicensesDialogFragment() { LicensesDialogFragment dialog = LicensesDialogFragment.newInstance(); dialog.show(getFragmentManager(), "LicensesDialog"); } @Override public void onBackPressed() { Intent StartMainActivityIntent = new Intent(InformationActivity.this, MainActivity.class); startActivity(StartMainActivityIntent); finish(); } } 
  • getFragmentManager() you got a getFragmentManager() method? Judging by the error code is not. - user218976 1:31 pm
  • @Anamnian Hmm ... No. And how to announce it? Something in the manual was nothing written about it. - Michael
  • Where is your displayLicensesDialogFragment () method? in the activation file? - RomanK.
  • one
    Activate from AppCompatActivity. - Yura Ivanov
  • one
    InformationActivity extends AppCompatActivity - Yura Ivanov

1 answer 1

Instead of getFragmentManager use the getFragmentManager manager, getSupportFragmentManager .

UPD:

public class InformationActivity extends Activity replace with public class InformationActivity extends AppCompatActivity

  • getSupportFragmentManager stood out in red writes: Cannot resolve method 'getSupportFragmentManager ()' - Michael
  • 2
    Check import in LicensesDialogFragment class: must be import android.support.v4.app.DialogFragment. You probably imported import android.app.DialogFragment (not from a support) - RomanK.
  • Imported everything you can, including: import android.support.v4.app.FragmentActivity; , import android.support.v4.app.FragmentManager; and import android.support.v4.app.DialogFragment; - Michael
  • one
    public class LicensesDialogFragment extends DialogFragment And also check that the activation is inherited from the support caliper - RomanK.
  • 2
    Replace public class InformationActivity extends Activity with public class InformationActivity extends AppCompatActivity - RomanK.