observem a mensagem de erro!
2020-01-03 16:37:48.091 27513-27513/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.resource.listfragment, PID: 27513
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.resource.listfragment/com.resource.listfragment.MainActivity}: android.view.InflateException: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.view.InflateException: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #9 in com.resource.listfragment:layout/activity_main: Error inflating class fragment
Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.resource.listfragment.ListProdutosFragments that is not a Fragment
at android.app.Fragment.instantiate(Fragment.java:538)
at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3553)
at android.app.FragmentController.onCreateView(FragmentController.java:104)
at android.app.Activity.onCreateView(Activity.java:6948)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:438)
at android.app.Activity.setContentView(Activity.java:3324)
at com.resource.listfragment.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-01-03 16:37:48.091 27513-27513/? E/AndroidRuntime: Caused by: java.lang.ClassCastException
... 31 more
2020-01-03 16:37:48.110 27513-27513/? I/Process: Sending signal. PID: 27513 SIG: 9
Informa que o erro está nessa classe.
package com.resource.listfragment;
import android.app.Activity;
import android.os.Bundle;
import java.text.NumberFormat;
import java.util.Locale;
public class MainActivity extends Activity implements ListProdutosFragments.OnItemClick {
private static final NumberFormat nf = NumberFormat.getCurrencyInstance(new Locale("pt", "BR"));
private DescProdutosFragments textFrag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textFrag = (DescProdutosFragments) getFragmentManager().findFragmentById(R.id.frag_text);
}
@Override
public void onClick(Alimento alimento) {
textFrag.setText(String.format("O preço do %s é %s", alimento.getNome(), nf.format(alimento.getPreco())));
}
}
Mais precisamente nessa linha.
setContentView(R.layout.activity_main);
Qual seria a sugestão para corrigir o problema?