in Education by
I have the following codes in my android application: main.xml : <?xml version="1.0" encoding="utf-8"?> fragmenta.xml : <?xml version="1.0" encoding="utf-8"?> FragmentA.java : package com.hugo.test; //some imports here public class FragmentA extends Fragment { /** Called when the activity is first created. */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //super.onCreate(savedInstanceState); //setContentView(R.layout.main); return inflater.inflate(R.layout.fragmenta, container, false); } } FragmentActivity.java : package com.hugo.test; //some imports here public class FragmentActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } The layout of the activity should display "activity" and the fragment should display "helloA". When I run my project I only see "activity", so it seems to me that the fragment is ignored at all. The error I see is : 12-19 09:01:05.370: E/AndroidRuntime(1352): FATAL EXCEPTION: main 12-19 09:01:05.370: E/AndroidRuntime(1352): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hugo.test/com.hugo.test.FragmentActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1751) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.ActivityThread.access$1500(ActivityThread.java:122) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.os.Handler.dispatchMessage(Handler.java:99) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.os.Looper.loop(Looper.java:132) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.ActivityThread.main(ActivityThread.java:4028) 12-19 09:01:05.370: E/AndroidRuntime(1352): at java.lang.reflect.Method.invokeNative(Native Method) 12-19 09:01:05.370: E/AndroidRuntime(1352): at java.lang.reflect.Method.invoke(Method.java:491) 12-19 09:01:05.370: E/AndroidRuntime(1352): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844) 12-19 09:01:05.370: E/AndroidRuntime(1352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 12-19 09:01:05.370: E/AndroidRuntime(1352): at dalvik.system.NativeStart.main(Native Method) 12-19 09:01:05.370: E/AndroidRuntime(1352): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class fragment 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.view.LayoutInflater.rInflate(LayoutInflater.java:724) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.view.LayoutInflater.inflate(LayoutInflater.java:479) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.view.LayoutInflater.inflate(LayoutInflater.java:391) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.view.LayoutInflater.inflate(LayoutInflater.java:347) 12-19 09:01:05.370: E/AndroidRuntime(1352): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:245) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.Activity.setContentView(Activity.java:1780) 12-19 09:01:05.370: E/AndroidRuntime(1352): at com.hugo.test.FragmentActivity.onCreate(FragmentActivity.java:11) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715) 12-19 09:01:05.370: E/AndroidRuntime(1352): ... 11 more 12-19 09:01:05.370: E/AndroidRuntime(1352): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.hugo.test.fragmenta: make sure class name exists, is public, and has an empty constructor that is public 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.Fragment.instantiate(Fragment.java:500) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.Fragment.instantiate(Fragment.java:468) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.Activity.onCreateView(Activity.java:4132) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:664) 12-19 09:01:05.370: E/AndroidRuntime(1352): ... 20 more 12-19 09:01:05.370: E/AndroidRuntime(1352): Caused by: java.lang.ClassNotFoundException: com.hugo.test.fragmenta in loader dalvik.system.PathClassLoader[/data/app/com.jochen.test-1.apk] 12-19 09:01:05.370: E/AndroidRuntime(1352): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251) 12-19 09:01:05.370: E/AndroidRuntime(1352): at java.lang.ClassLoader.loadClass(ClassLoader.java:540) 12-19 09:01:05.370: E/AndroidRuntime(1352): at java.lang.ClassLoader.loadClass(ClassLoader.java:500) 12-19 09:01:05.370: E/AndroidRuntime(1352): at android.app.Fragment.instantiate(Fragment.java:490) 12-19 09:01:05.370: E/AndroidRuntime(1352): ... 23 more Because of that error I added a constructor to FragmentA.java public FragmentA() { } This error is not gone, the fragment still doesn't show up, same behavior as before. Anyone an idea? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
It was due to the 0dp I haven't seen that when I copied that part from the Android page.

Related questions

0 votes
    I am trying to inflate one of my fragments. However, the fragment does not show up in the autosuggest ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I have a main activity which contains the action bar with 3 menu buttons in it. I then have a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    What is fragment in android?...
asked Jan 14, 2021 in Technology by JackTerrance
0 votes
0 votes
    One hundred identical coins, each with probability p, of showing up heads are tossed once. If `0 A. 1/2 B. 51 ... /101 D. none of these Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    I am trying to look at a cone in 3D, for which I used gluLookAt. I draw a cone in the middle ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I am trying to look at a cone in 3D, for which I used gluLookAt. I draw a cone in the middle ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I have deployed a Django project on Ubuntu 16.04 with Nginx and Gunicorn. I have gotten everything, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    Hi I'm having some issues showing lists in my embed correctly. I'm trying to get my roles to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I am trying to implement the Hateoas using spring boot. In my UserController class i have used the below ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Every now and then, variables just stop showing up in the Workspace pane. who and whos show that there ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    You are working with the following XSD fragment. What does it say about the element? element has child elements which can appear in any order...
asked Mar 10, 2023 in Technology by JackTerrance
...