Problem Android App dev tut 32

+2 John Smith · February 27, 2015
Hello , hat is wrong with the code? When i launch the project i get force close from emulator.

DummyContent
package com.grid.masterflow.dummy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Helper class for providing sample content for user interfaces created by
 * Android template wizards.
 *
 * TODO: Replace all uses of this class before publishing your app.
 */
public class DummyContent {

    /**
     * An array of sample (dummy) items.
     */
    public static List ITEMS = new ArrayList();

    /**
     * A map of sample (dummy) items, by ID.
     */
    public static Map ITEM_MAP = new HashMap();

    static {
        // Add 3 sample items.
        addItem(new DummyItem("1", "Youtube","https://www.youtube.com/"));
        addItem(new DummyItem("2", "Fillist","http://filelist.ro/"));
        addItem(new DummyItem("3", "Theneboston","https://www.thenewboston.com/"));
    }

    private static void addItem(DummyItem item) {
        ITEMS.add(item);
        ITEM_MAP.put(item.id, item);
    }

    /**
     * A dummy item representing a piece of content.
     */
    public static class DummyItem {
        public String id;
        public String item_name;
        public String url;

        public DummyItem(String id, String item_name,String url) {
            this.id = id;
            this.item_name = item_name;
            this.url = url;
        }

        @Override
        public String toString() {
            return item_name;
        }
    }
}

WebpageDetailFragment :
package com.grid.masterflow;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;


import com.grid.masterflow.dummy.DummyContent;

/**
 * A fragment representing a single Webpage detail screen.
 * This fragment is either contained in a {@link WebpageListActivity}
 * in two-pane mode (on tablets) or a {@link WebpageDetailActivity}
 * on handsets.
 */
public class WebpageDetailFragment extends Fragment {
    /**
     * The fragment argument representing the item ID that this fragment
     * represents.
     */
    public static final String ARG_ITEM_ID = "item_id";

    /**
     * The dummy content this fragment is presenting.
     */
    private DummyContent.DummyItem mItem;

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public WebpageDetailFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getArguments().containsKey(ARG_ITEM_ID)) {
            // Load the dummy content specified by the fragment
            // arguments. In a real-world scenario, use a Loader
            // to load content from a content provider.
            mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_webpage_detail, container, false);

        // Show the dummy content as text in a TextView.
        if (mItem != null) {
            ((WebView)rootView.findViewById(R.id.detail_area)).loadUrl(mItem.url);
        }

        return rootView;
    }
}



fragment_webpage_detail.xml



<?xml version="1.0" encoding="utf-8" ?>
    <WebView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/detail_area"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    />




Post a Reply

Replies

Oldest  Newest  Rating
+1 Spikeedoo G · March 3, 2015
I am sorry this might not be it....but looking at your code compared to my working code the only thing I saw different was:

In DummyContent.java:
You have
public static List ITEMS = new ArrayList();


I have
public static List<DummyItem> ITEMS = new ArrayList<DummyItem>();


And

You have

public static Map ITEM_MAP = new HashMap();

I have

public static Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();

I hope this can help!  If not, I am sorry.  I am new to helping people with code :)
  • 1

Java / Android Development

107,173 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator