0

I created a Navigation Drawer in Android Studio. Inside Fragment of Navigation Drawer, I wanted to add a ListView with images and text. But after I running program and clicking on the fragment program crashing with a text "Unfortunately, SerialMania has stopped ". What I'm doing wrong?

package com.example.tabaq.kit;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.tabaq.R;
import com.example.tabaq.activities.MainActivity;
import com.example.tabaq.adapters.AdapterAbout;

public class FragmentAbout extends Fragment {

    SimplelistView SimplelistView;
    String[] titleId;
    String[] subtitleId;
    private MainActivity mainActivity;
    private Toolbar toolbar;

    Integer[] imageId = {
            R.drawable.ic_other_appname,
            R.drawable.ic_other_build,
            R.drawable.ic_other_email,
            R.drawable.ic_other_copyright,
            R.drawable.ic_other_share,
            R.drawable.ic_other_rate,
            R.drawable.ic_other_more

    };

    public FragmentAbout() {
        // Required empty public constructor
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mainActivity = (MainActivity)activity;
    }

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

        toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);

        setupToolbar();

        titleId = getResources().getStringArray(R.array.title);
        subtitleId = getResources().getStringArray(R.array.subtitle);

        AdapterAbout adapter = new AdapterAbout(getActivity(), titleId, subtitleId, imageId);
        SimplelistView = (ListView) rootView.findViewById(R.id.list);
        SimplelistView.setAdapter(adapter);
        SimplelistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 4) {
                    Intent sendInt = new Intent(Intent.ACTION_SEND);
                    sendInt.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
                    sendInt.putExtra(Intent.EXTRA_TEXT, getString(R.string.app_name) + "\n" + getString(R.string.share_text) + "\n" + "https://play.google.com/store/apps/details?id=" + getActivity().getPackageName());
                    sendInt.setType("text/plain");
                    startActivity(Intent.createChooser(sendInt, "Share"));
                }
                if (position == 5) {
                    final String appName = getActivity().getPackageName();
                    try {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appName)));
                    } catch (android.content.ActivityNotFoundException anfe) {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appName)));
                    }
                }
                if (position == 6) {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.play_more_apps))));
                }
            }
        });

        return rootView;
    }

    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.main, menu);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mainActivity.setupNavigationDrawer(toolbar);
    }

    private void setupToolbar(){
        toolbar.setTitle(getString(R.string.drawer_about));
        mainActivity.setSupportActionBar(toolbar);
    }
}

Please help.. I created a Navigation Drawer in Android Studio. Inside Fragment of Navigation Drawer, I wanted to add a ListView with images and text. But after I running program and clicking on the fragment program crashing with a text "Unfortunately, SerialMania has stopped ". What I'm doing wrong?

  • 2
    What is the problem, exactly? – Mike M. Feb 01 '19 at 00:46
  • a problem in fragment about, I want to define image id and title id In fragmentAbout.java – AbdoDregri Feb 01 '19 at 01:06
  • 1
    I don't really understand what that means. Also, I don't see a fragmentAbout, or an AboutFragment, in your question. – Mike M. Feb 01 '19 at 01:08
  • (To be fair, the 1st code block is introduced as *AboutFragment.java*.) – greybeard Feb 01 '19 at 01:17
  • If your app is crashing, then there will be a stack trace from the crash in the logcat. Have a look at [this Stack Overflow post](https://stackoverflow.com/questions/23353173) and [this developer page](https://developer.android.com/studio/debug/am-logcat) for help in finding that. – Mike M. Feb 01 '19 at 02:13

0 Answers0