0

I have a main class to which I want to add two fragments. For now, I have coded only one fragment so I decided to test it out. However, I get exceptions in log cat as below:

08-02 13:07:24.541: E/Trace(952): error opening trace file: No such file or directory (2)
08-02 13:07:27.641: E/AndroidRuntime(952): FATAL EXCEPTION: main
08-02 13:07:27.641: E/AndroidRuntime(952): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tqafragments/com.example.tqafragments.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.os.Looper.loop(Looper.java:137)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.ActivityThread.main(ActivityThread.java:5041)
08-02 13:07:27.641: E/AndroidRuntime(952):  at java.lang.reflect.Method.invokeNative(Native Method)
08-02 13:07:27.641: E/AndroidRuntime(952):  at java.lang.reflect.Method.invoke(Method.java:511)
08-02 13:07:27.641: E/AndroidRuntime(952):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-02 13:07:27.641: E/AndroidRuntime(952):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-02 13:07:27.641: E/AndroidRuntime(952):  at dalvik.system.NativeStart.main(Native Method)
08-02 13:07:27.641: E/AndroidRuntime(952): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-02 13:07:27.641: E/AndroidRuntime(952):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.Activity.setContentView(Activity.java:1881)
08-02 13:07:27.641: E/AndroidRuntime(952):  at com.example.tqafragments.MainActivity.onCreate(MainActivity.java:13)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.Activity.performCreate(Activity.java:5104)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-02 13:07:27.641: E/AndroidRuntime(952):  ... 11 more
08-02 13:07:27.641: E/AndroidRuntime(952): Caused by: android.app.SuperNotCalledException: Fragment FeedFragment{40d076d0 #0 id=0x7f080003} did not call through to super.onCreate()
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.Fragment.performCreate(Fragment.java:1675)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:854)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1137)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.app.Activity.onCreateView(Activity.java:4717)
08-02 13:07:27.641: E/AndroidRuntime(952):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
08-02 13:07:27.641: E/AndroidRuntime(952):  ... 21 more  


There is not a lot in my main activity apart from setContentView.
The main.xml has a fragment tag which points to FeedFragment
Here is the FeedFragment class:
package com.example.tqafragments;

import java.util.Vector;

import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListView;

/**
 * FeedFragment
 * @author 
 *
 */
public class FeedFragment extends Fragment{
    Vector<Feed> feeds = null; 

    @Override
    public void onCreate(Bundle savedInstanceState){
        // nothing to initialize.
    }
//------------------------------------------------------------------------------
    @Override 
    public View onCreateView(LayoutInflater inflater, 
            ViewGroup container, 
            Bundle savedInstanceState){
        return inflater.inflate(R.layout.feed_fragment, container, false); // inflate the fragment layout
    }
//------------------------------------------------------------------------------
    @Override 
    public void onStart(){
        new AsyncFeedRetriever().execute(new FeedProcessor()); // get the RSS feeds
        // Add itemClickListener for ExpandableListView
        // in other fragment as the other fragment
        // is not yet inflated. Will result in a NPE here.
    }
//------------------------------------------------------------------------------
    /**
     * AsyncRetriever
     * @author 
     *
     */
    class AsyncFeedRetriever extends AsyncTask<FeedProcessor,Void,FeedProcessor>{
        ProgressDialog pDialog = null;
//------------------------------------------------------------------------------    
        @Override
        protected void onPreExecute(){
            pDialog = new ProgressDialog(getActivity()); // display dialog box
            pDialog.setMessage(getActivity().getResources().getText(R.string.loading));
            pDialog.show();
        }
//------------------------------------------------------------------------------
        @Override
        protected FeedProcessor doInBackground(FeedProcessor... arg0) {
            FeedProcessor p = arg0[0];
            p.processFeed(); // get the feeds, actually, from the URL.
            return p;
        }
//------------------------------------------------------------------------------
        @Override
        protected void onPostExecute(FeedProcessor p){
            pDialog.dismiss();
            ExpandableListView list = (ExpandableListView) getActivity().findViewById(R.id.expandingList);

            if(p.errorOccured == false){
                feeds = p.getFeeds(); // populate the list
                ArrayAdapter<Feed> adapter = new ArrayAdapter<Feed>(
                        getActivity(), 
                        R.layout.list_row, 
                        R.id.row,
                        feeds);
                list.setAdapter(adapter);
            }else{
                // nothing
            }
        }
//------------------------------------------------------------------------------
    }
}   


feed_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ExpandableListView android:id="@+id/expandingList" 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

    </ExpandableListView>
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:gravity="center"
        android:background="#FF808080">
        <Button android:id="@+id/refresh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="@string/refresh_str"/>"
    </LinearLayout>

</LinearLayout>

Can someone please help me solve this?

An SO User
  • 24,612
  • 35
  • 133
  • 221

1 Answers1

1

The error : Caused by: android.app.SuperNotCalledException: Fragment FeedFragment{40d076d0 #0 id=0x7f080003} did not call through to super.onCreate() says you are missing the super.onCreate in your onCreate method:

public class FeedFragment extends Fragment{
Vector<Feed> feeds = null; 

@Override
public void onCreate(Bundle savedInstanceState){
    // you need this line here!
    super.onCreate(savedInstanceState);

}
petey
  • 16,914
  • 6
  • 65
  • 97
  • according to the logs..this is the root cause of your issue. If more errors still happen let us know what those are. – petey Aug 02 '13 at 13:15
  • I dont like to dirty the question by posting extra-long stack traces. Is pastebin a better option? :) – An SO User Aug 02 '13 at 13:17
  • nah...stacktraces are always helpful. Pastebin links don't get indexed by SO searches so in the long run its not helpful to others having the same issue (when they search by similar stacktrace causes) – petey Aug 02 '13 at 13:18
  • Ok, I tried your suggestion but the stack trace still says `Caused by: android.app.SuperNotCalledException:` – An SO User Aug 02 '13 at 13:19
  • can you add the feed_fragment.xml to the question? – petey Aug 02 '13 at 13:35
  • Alright, posted :) Let me know if something else is needed :) – An SO User Aug 02 '13 at 13:45
  • No, no more `and 21 more`. Just the `Caused by: android.app.SuperNotCalledException: Fragment FeedFragment{40d076d0 #0 id=0x7f080003} did not call through to super.onCreate()` – An SO User Aug 02 '13 at 14:12