Unable to load fragment from other fragment












1















When trying to load a fragment coming from another fragment layout my application stops.



When looking at the logcat I get this error:



android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flow/com.example.flow.displayClasses.GroupScreens.HomeGroupFragment}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2005)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
at android.app.Activity.startActivityForResult(Activity.java:4586)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:881)
at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:995)
at android.support.v4.app.Fragment.startActivity(Fragment.java:1084)
at android.support.v4.app.Fragment.startActivity(Fragment.java:1073)
at com.example.flow.displayClasses.GroupScreens.GroupsFragment$1.onItemClick(GroupsFragment.java:170)
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
at android.widget.AbsListView.performItemClick(AbsListView.java:1159)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3136)
at android.widget.AbsListView$3.run(AbsListView.java:4052)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)


My fragment from where I come:



package com.example.flow.displayClasses.GroupScreens;




import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.example.flow.R;
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import android.content.Intent;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.flow.classes.Friends;
import com.example.flow.classes.Group;
import com.example.flow.classes.User;
import com.example.flow.displayClasses.FriendsScreen.FriendsFragment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.view.MenuItem;
import android.support.annotation.Nullable;
import android.widget.Toast;


public class GroupsFragment extends Fragment {

private final String TAG = this.getClass().getSimpleName();

private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;

ArrayList<Group> groups = new ArrayList<Group>();


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

public static GroupsFragment newInstance(String param1, String param2) {
GroupsFragment fragment = new GroupsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}


}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View RootView = inflater.inflate(R.layout.fragment_groups, container, false);

// Hardcoded for testing
User u1 = new User("Bram", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u2 = new User("Bram1", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u3 = new User("Bram2", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u4 = new User("Bram3", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u5 = new User("Bram4", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u6 = new User("Bram5", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u7 = new User("Bram6", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u8 = new User("Bram7", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u9 = new User("Bram8", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u10 = new User("Bram9", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u11 = new User("Bram10", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u12 = new User("Bram11", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u13 = new User("Bram12", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u14 = new User("Bram13", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u15 = new User("Bram14", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u16 = new User("Bram15", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u17 = new User("Bram16", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u18 = new User("Bram17", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");

ArrayList<User> ug1 = new ArrayList<User>();

ug1.add(u1);
ug1.add(u2);
ug1.add(u3);

ArrayList<User> ug2 = new ArrayList<User>();

ug2.add(u4);
ug2.add(u5);
ug2.add(u6);
//Collections.addAll(ug1, u4, u5, u6);

ArrayList<User> ug3 = new ArrayList<User>();
ug3.add(u1);
ug3.add(u7);
ug3.add(u8);
ug3.add(u9);

//Collections.addAll(ug1, u7, u8, u9);

ArrayList<User> ug4 = new ArrayList<User>();
Collections.addAll(ug1, u10, u11, u12);

ArrayList<User> ug5 = new ArrayList<User>();
Collections.addAll(ug1, u13, u14, u15);

ArrayList<User> ug6 = new ArrayList<User>();
Collections.addAll(ug1, u14, u5, u6);

ArrayList<User> ug7 = new ArrayList<User>();
Collections.addAll(ug1, u4, u10, u6, u18, u17);

ArrayList<User> ug8 = new ArrayList<User>();
Collections.addAll(ug1, u4, u5, u6);

Group g1 = new Group(1, ug1, u1, "budies", u1, "date", true);
Group g8 = new Group(2, ug1, u1, "budies", u1, "date", false);
Group g9 = new Group(3, ug1, u1, "budies", u1, "date", true);
Group g10 = new Group(4, ug1, u1, "budies", u1, "date", false);
Group g11 = new Group(5, ug1, u1, "budies", u1, "date", true);
Group g12 = new Group(6, ug1, u1, "budies", u1, "date", false);
Group g13 = new Group(7, ug1, u1, "budies", u1, "date", false);
Group g14 = new Group(8, ug1, u1, "budies", u1, "date", false);
Group g15 = new Group(9, ug1, u1, "budies", u1, "date", true);
Group g16 = new Group(10, ug1, u1, "budies", u1, "date", true);
Group g17 = new Group(11, ug1, u1, "budies", u1, "date", true);
Group g18 = new Group(12, ug1, u1, "budies", u1, "date", false);


Collections.addAll(groups, g1, g8, g9, g10, g11, g12, g13, g14, g15, g16, g17, g18);

ListView list = (ListView)RootView.findViewById(R.id.listView);
CustomAdapter adapter = new CustomAdapter();
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getActivity().getApplicationContext(), HomeGroupFragment.class);
intent.putExtra("group", groups.get(position));

startActivity(intent);
}
});

return RootView;

}


class CustomAdapter extends BaseAdapter {

int index;

@Override
public int getCount() {
return groups.size();
}

@Override
public Object getItem(int position) {
return position;
}

@Override
public long getItemId(int id) {
return id ;
}

public View getView(int i, View view, ViewGroup viewgroup) {

if (groups.get(i).isPrepaid()) {
view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null);
} else {
view = getLayoutInflater().inflate(R.layout.groups_layout, null);
}


TextView textView = view.findViewById(R.id.Groupname);
ImageView image = view.findViewById(R.id.member);
String t = groups.get(i).getName();
textView.setText(t);

return view;
}
}
}


The fragment that won't load:



package com.example.flow.displayClasses.GroupScreens;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import android.widget.Toast;

import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.example.flow.Home;
import com.example.flow.R;
import com.example.flow.classes.Group;
import com.example.flow.classes.GroupExpense;
import com.example.flow.classes.UserExpense;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;

public class HomeGroupFragment extends Fragment {

private final String TAG = this.getClass().getSimpleName();

private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;

ArrayList<GroupExpense> expense = new ArrayList<GroupExpense>();


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

public static HomeGroupFragment newInstance(String param1, String param2) {
HomeGroupFragment fragment = new HomeGroupFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

Group group;
boolean status;

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

super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}

}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View RootView = inflater.inflate(R.layout.fragment_group, container, false);
/*
super.onCreate(savedInstanceState);
getActivity().setContentView(R.layout.fragment_group);
ConstraintLayout layout =getActivity().findViewById(R.id.groupLayout);
status = true;*/

//harcoded

UserExpense ux = new UserExpense(group.getUsers().get(2), 5.3);
UserExpense ux1 = new UserExpense(group.getUsers().get(3), 6.91);

ArrayList<UserExpense> uxs = new ArrayList<UserExpense>();
Collections.addAll(uxs, ux, ux1);

GroupExpense ex = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex1 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex2 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex3 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex4 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex5 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex6 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex7 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex8 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex9 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex10 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex11 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex12 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex13 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex14 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex15 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);


Collections.addAll(expense, ex, ex1, ex2, ex3, ex4, ex5, ex6, ex7, ex8, ex9, ex10, ex11, ex12, ex13, ex14, ex15);

Intent intent = getActivity().getIntent();
group = Objects.requireNonNull(intent.getExtras()).getParcelable("group");

int id = intent.getIntExtra("group", -1);

TextView t = getActivity().findViewById(R.id.Groupname);
t.setText(group.getName());
t.setId(group.getGroupId());

setLayout();

return RootView;
}

public void changeToMember(View view)
{
Button member =getActivity().findViewById(R.id.member);
Button history =getActivity().findViewById(R.id.history);

if (status) {
member.setBackgroundResource(R.drawable.bottom_border_selected);
member.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
member.setTypeface(null, Typeface.BOLD);
member.setTextColor(Color.parseColor("#4799E8"));

history.setBackgroundResource(R.drawable.bottom_border);
history.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
history.setTypeface(null, Typeface.NORMAL);
history.setTextColor(Color.parseColor("#000000"));


status = false;
setLayout();
}
}

public void changeToHistory(View view)
{
Button member = getActivity().findViewById(R.id.member);
Button history =getActivity().findViewById(R.id.history);

if (!status) {
member.setBackgroundResource(R.drawable.bottom_border);
member.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
member.setTypeface(null, Typeface.NORMAL);
member.setTextColor(Color.parseColor("#000000"));

history.setBackgroundResource(R.drawable.bottom_border_selected);
history.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
history.setTypeface(null, Typeface.BOLD);
history.setTextColor(Color.parseColor("#4799E8"));
status = true;
setLayout();
}
}

public void setLayout()
{
ListView list = getActivity().findViewById(R.id.expenseList);
CustomAdapter ad = new CustomAdapter();
list.setAdapter(ad);

list.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
if (status) {
Intent intent = new Intent(getActivity().getApplicationContext(), GroupExpenseFragment.class);
intent.putExtra("expense", expense.get(position));
startActivity(intent);
} else {
Intent intent = new Intent(getActivity().getApplicationContext(), Home.class);
intent.putExtra("group", group.getUsers().get(position));
startActivity(intent);
}
}
});
}

public void leaveGroup(View view)
{

}

class CustomAdapter extends BaseAdapter
{

@Override
public int getCount()
{

return status ? expense.size() : group.getUsers().size();
}

@Override
public Object getItem(int position)
{
return position;
}

@Override
public long getItemId(int id)
{
return id;
}

public View getView(int i, View view, ViewGroup viewgroup)
{

if (status) {
view = getLayoutInflater().inflate(R.layout.group_expense_layout, null);

TextView user = view.findViewById(R.id.username);
TextView subject = view.findViewById(R.id.subject);
TextView amount = view.findViewById(R.id.expenseAmount);

user.setText(expense.get(i).getCreditor().getName());
subject.setText(expense.get(i).getName());
amount.setText(String.valueOf(expense.get(i).getAmount()));
} else {
view = getLayoutInflater().inflate(R.layout.group_member_layout, null);

TextView name = view.findViewById(R.id.nameMember);
TextView admin = view.findViewById(R.id.privilege);
TextView date = view.findViewById(R.id.date);

name.setText(group.getUsers().get(i).getName());
admin.setText("");
date.setText("");
}

return view;
}
}
}


The fragment_group.xml file:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.HomeGroupFragment">

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/groupLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.GroupFragment">
<TextView
android:id="@+id/Groupname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/group_name"
android:textColor="#428EC4"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/member"
style="@style/selected"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="@string/history"
android:textAllCaps="false"
app:layout_constraintEnd_toStartOf="@+id/history"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Groupname" />

<Button
android:id="@+id/history"
style="@style/unselected"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="@string/members"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/member"
app:layout_constraintTop_toBottomOf="@+id/Groupname" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/history">


<ListView
android:id="@+id/expenseList"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>
</LinearLayout>

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/leave_group"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>
</RelativeLayout>


The group_expense_layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="25dp"
android:text="Username"
android:textSize="18sp"
android:textStyle="bold" />

<TextView
android:id="@+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/username"
android:layout_marginStart="65dp"
android:layout_toEndOf="@+id/username"
android:text="Name" />

<TextView
android:id="@+id/expenseAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/username"
android:layout_alignParentEnd="true"
android:layout_marginStart="93dp"
android:layout_marginEnd="25dp"
android:layout_toEndOf="@+id/subject"
android:text="TextView" />

</RelativeLayout>


The manifest:



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.flow">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label=" "
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:icon,android:label">

<activity
android:theme="@style/AppTheme"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:theme="@style/AppTheme.NoActionBar"
android:name=".Home"
android:parentActivityName=".displayClasses.LoginScreens.Login">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".displayClasses.LoginScreens.Login" />
</activity>

<activity
android:theme="@style/AppTheme"
android:name=".displayClasses.LoginScreens.activity_signup" />

<activity
android:theme="@style/AppTheme"
android:name=".displayClasses.LoginScreens.Login" />

</application>
</manifest>


But as far as I know I shouldn't implement a fragment in my Manifest. So do I need to rewrite the Intent statements? And so yes, how do I do it correctly? I'm learning to work with Android Studio any help is much appreciated.










share|improve this question

























  • can you add your manifest ?

    – JCDecary
    Nov 21 '18 at 19:52











  • @JCDecary placed it below the post.

    – Inyea
    Nov 21 '18 at 19:57











  • any reason why HomeGroupFragment need to be a fragment ?

    – JCDecary
    Nov 21 '18 at 20:05
















1















When trying to load a fragment coming from another fragment layout my application stops.



When looking at the logcat I get this error:



android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flow/com.example.flow.displayClasses.GroupScreens.HomeGroupFragment}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2005)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
at android.app.Activity.startActivityForResult(Activity.java:4586)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:881)
at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:995)
at android.support.v4.app.Fragment.startActivity(Fragment.java:1084)
at android.support.v4.app.Fragment.startActivity(Fragment.java:1073)
at com.example.flow.displayClasses.GroupScreens.GroupsFragment$1.onItemClick(GroupsFragment.java:170)
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
at android.widget.AbsListView.performItemClick(AbsListView.java:1159)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3136)
at android.widget.AbsListView$3.run(AbsListView.java:4052)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)


My fragment from where I come:



package com.example.flow.displayClasses.GroupScreens;




import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.example.flow.R;
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import android.content.Intent;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.flow.classes.Friends;
import com.example.flow.classes.Group;
import com.example.flow.classes.User;
import com.example.flow.displayClasses.FriendsScreen.FriendsFragment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.view.MenuItem;
import android.support.annotation.Nullable;
import android.widget.Toast;


public class GroupsFragment extends Fragment {

private final String TAG = this.getClass().getSimpleName();

private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;

ArrayList<Group> groups = new ArrayList<Group>();


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

public static GroupsFragment newInstance(String param1, String param2) {
GroupsFragment fragment = new GroupsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}


}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View RootView = inflater.inflate(R.layout.fragment_groups, container, false);

// Hardcoded for testing
User u1 = new User("Bram", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u2 = new User("Bram1", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u3 = new User("Bram2", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u4 = new User("Bram3", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u5 = new User("Bram4", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u6 = new User("Bram5", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u7 = new User("Bram6", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u8 = new User("Bram7", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u9 = new User("Bram8", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u10 = new User("Bram9", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u11 = new User("Bram10", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u12 = new User("Bram11", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u13 = new User("Bram12", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u14 = new User("Bram13", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u15 = new User("Bram14", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u16 = new User("Bram15", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u17 = new User("Bram16", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u18 = new User("Bram17", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");

ArrayList<User> ug1 = new ArrayList<User>();

ug1.add(u1);
ug1.add(u2);
ug1.add(u3);

ArrayList<User> ug2 = new ArrayList<User>();

ug2.add(u4);
ug2.add(u5);
ug2.add(u6);
//Collections.addAll(ug1, u4, u5, u6);

ArrayList<User> ug3 = new ArrayList<User>();
ug3.add(u1);
ug3.add(u7);
ug3.add(u8);
ug3.add(u9);

//Collections.addAll(ug1, u7, u8, u9);

ArrayList<User> ug4 = new ArrayList<User>();
Collections.addAll(ug1, u10, u11, u12);

ArrayList<User> ug5 = new ArrayList<User>();
Collections.addAll(ug1, u13, u14, u15);

ArrayList<User> ug6 = new ArrayList<User>();
Collections.addAll(ug1, u14, u5, u6);

ArrayList<User> ug7 = new ArrayList<User>();
Collections.addAll(ug1, u4, u10, u6, u18, u17);

ArrayList<User> ug8 = new ArrayList<User>();
Collections.addAll(ug1, u4, u5, u6);

Group g1 = new Group(1, ug1, u1, "budies", u1, "date", true);
Group g8 = new Group(2, ug1, u1, "budies", u1, "date", false);
Group g9 = new Group(3, ug1, u1, "budies", u1, "date", true);
Group g10 = new Group(4, ug1, u1, "budies", u1, "date", false);
Group g11 = new Group(5, ug1, u1, "budies", u1, "date", true);
Group g12 = new Group(6, ug1, u1, "budies", u1, "date", false);
Group g13 = new Group(7, ug1, u1, "budies", u1, "date", false);
Group g14 = new Group(8, ug1, u1, "budies", u1, "date", false);
Group g15 = new Group(9, ug1, u1, "budies", u1, "date", true);
Group g16 = new Group(10, ug1, u1, "budies", u1, "date", true);
Group g17 = new Group(11, ug1, u1, "budies", u1, "date", true);
Group g18 = new Group(12, ug1, u1, "budies", u1, "date", false);


Collections.addAll(groups, g1, g8, g9, g10, g11, g12, g13, g14, g15, g16, g17, g18);

ListView list = (ListView)RootView.findViewById(R.id.listView);
CustomAdapter adapter = new CustomAdapter();
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getActivity().getApplicationContext(), HomeGroupFragment.class);
intent.putExtra("group", groups.get(position));

startActivity(intent);
}
});

return RootView;

}


class CustomAdapter extends BaseAdapter {

int index;

@Override
public int getCount() {
return groups.size();
}

@Override
public Object getItem(int position) {
return position;
}

@Override
public long getItemId(int id) {
return id ;
}

public View getView(int i, View view, ViewGroup viewgroup) {

if (groups.get(i).isPrepaid()) {
view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null);
} else {
view = getLayoutInflater().inflate(R.layout.groups_layout, null);
}


TextView textView = view.findViewById(R.id.Groupname);
ImageView image = view.findViewById(R.id.member);
String t = groups.get(i).getName();
textView.setText(t);

return view;
}
}
}


The fragment that won't load:



package com.example.flow.displayClasses.GroupScreens;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import android.widget.Toast;

import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.example.flow.Home;
import com.example.flow.R;
import com.example.flow.classes.Group;
import com.example.flow.classes.GroupExpense;
import com.example.flow.classes.UserExpense;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;

public class HomeGroupFragment extends Fragment {

private final String TAG = this.getClass().getSimpleName();

private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;

ArrayList<GroupExpense> expense = new ArrayList<GroupExpense>();


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

public static HomeGroupFragment newInstance(String param1, String param2) {
HomeGroupFragment fragment = new HomeGroupFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

Group group;
boolean status;

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

super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}

}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View RootView = inflater.inflate(R.layout.fragment_group, container, false);
/*
super.onCreate(savedInstanceState);
getActivity().setContentView(R.layout.fragment_group);
ConstraintLayout layout =getActivity().findViewById(R.id.groupLayout);
status = true;*/

//harcoded

UserExpense ux = new UserExpense(group.getUsers().get(2), 5.3);
UserExpense ux1 = new UserExpense(group.getUsers().get(3), 6.91);

ArrayList<UserExpense> uxs = new ArrayList<UserExpense>();
Collections.addAll(uxs, ux, ux1);

GroupExpense ex = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex1 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex2 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex3 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex4 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex5 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex6 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex7 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex8 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex9 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex10 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex11 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex12 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex13 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex14 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex15 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);


Collections.addAll(expense, ex, ex1, ex2, ex3, ex4, ex5, ex6, ex7, ex8, ex9, ex10, ex11, ex12, ex13, ex14, ex15);

Intent intent = getActivity().getIntent();
group = Objects.requireNonNull(intent.getExtras()).getParcelable("group");

int id = intent.getIntExtra("group", -1);

TextView t = getActivity().findViewById(R.id.Groupname);
t.setText(group.getName());
t.setId(group.getGroupId());

setLayout();

return RootView;
}

public void changeToMember(View view)
{
Button member =getActivity().findViewById(R.id.member);
Button history =getActivity().findViewById(R.id.history);

if (status) {
member.setBackgroundResource(R.drawable.bottom_border_selected);
member.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
member.setTypeface(null, Typeface.BOLD);
member.setTextColor(Color.parseColor("#4799E8"));

history.setBackgroundResource(R.drawable.bottom_border);
history.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
history.setTypeface(null, Typeface.NORMAL);
history.setTextColor(Color.parseColor("#000000"));


status = false;
setLayout();
}
}

public void changeToHistory(View view)
{
Button member = getActivity().findViewById(R.id.member);
Button history =getActivity().findViewById(R.id.history);

if (!status) {
member.setBackgroundResource(R.drawable.bottom_border);
member.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
member.setTypeface(null, Typeface.NORMAL);
member.setTextColor(Color.parseColor("#000000"));

history.setBackgroundResource(R.drawable.bottom_border_selected);
history.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
history.setTypeface(null, Typeface.BOLD);
history.setTextColor(Color.parseColor("#4799E8"));
status = true;
setLayout();
}
}

public void setLayout()
{
ListView list = getActivity().findViewById(R.id.expenseList);
CustomAdapter ad = new CustomAdapter();
list.setAdapter(ad);

list.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
if (status) {
Intent intent = new Intent(getActivity().getApplicationContext(), GroupExpenseFragment.class);
intent.putExtra("expense", expense.get(position));
startActivity(intent);
} else {
Intent intent = new Intent(getActivity().getApplicationContext(), Home.class);
intent.putExtra("group", group.getUsers().get(position));
startActivity(intent);
}
}
});
}

public void leaveGroup(View view)
{

}

class CustomAdapter extends BaseAdapter
{

@Override
public int getCount()
{

return status ? expense.size() : group.getUsers().size();
}

@Override
public Object getItem(int position)
{
return position;
}

@Override
public long getItemId(int id)
{
return id;
}

public View getView(int i, View view, ViewGroup viewgroup)
{

if (status) {
view = getLayoutInflater().inflate(R.layout.group_expense_layout, null);

TextView user = view.findViewById(R.id.username);
TextView subject = view.findViewById(R.id.subject);
TextView amount = view.findViewById(R.id.expenseAmount);

user.setText(expense.get(i).getCreditor().getName());
subject.setText(expense.get(i).getName());
amount.setText(String.valueOf(expense.get(i).getAmount()));
} else {
view = getLayoutInflater().inflate(R.layout.group_member_layout, null);

TextView name = view.findViewById(R.id.nameMember);
TextView admin = view.findViewById(R.id.privilege);
TextView date = view.findViewById(R.id.date);

name.setText(group.getUsers().get(i).getName());
admin.setText("");
date.setText("");
}

return view;
}
}
}


The fragment_group.xml file:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.HomeGroupFragment">

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/groupLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.GroupFragment">
<TextView
android:id="@+id/Groupname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/group_name"
android:textColor="#428EC4"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/member"
style="@style/selected"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="@string/history"
android:textAllCaps="false"
app:layout_constraintEnd_toStartOf="@+id/history"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Groupname" />

<Button
android:id="@+id/history"
style="@style/unselected"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="@string/members"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/member"
app:layout_constraintTop_toBottomOf="@+id/Groupname" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/history">


<ListView
android:id="@+id/expenseList"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>
</LinearLayout>

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/leave_group"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>
</RelativeLayout>


The group_expense_layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="25dp"
android:text="Username"
android:textSize="18sp"
android:textStyle="bold" />

<TextView
android:id="@+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/username"
android:layout_marginStart="65dp"
android:layout_toEndOf="@+id/username"
android:text="Name" />

<TextView
android:id="@+id/expenseAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/username"
android:layout_alignParentEnd="true"
android:layout_marginStart="93dp"
android:layout_marginEnd="25dp"
android:layout_toEndOf="@+id/subject"
android:text="TextView" />

</RelativeLayout>


The manifest:



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.flow">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label=" "
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:icon,android:label">

<activity
android:theme="@style/AppTheme"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:theme="@style/AppTheme.NoActionBar"
android:name=".Home"
android:parentActivityName=".displayClasses.LoginScreens.Login">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".displayClasses.LoginScreens.Login" />
</activity>

<activity
android:theme="@style/AppTheme"
android:name=".displayClasses.LoginScreens.activity_signup" />

<activity
android:theme="@style/AppTheme"
android:name=".displayClasses.LoginScreens.Login" />

</application>
</manifest>


But as far as I know I shouldn't implement a fragment in my Manifest. So do I need to rewrite the Intent statements? And so yes, how do I do it correctly? I'm learning to work with Android Studio any help is much appreciated.










share|improve this question

























  • can you add your manifest ?

    – JCDecary
    Nov 21 '18 at 19:52











  • @JCDecary placed it below the post.

    – Inyea
    Nov 21 '18 at 19:57











  • any reason why HomeGroupFragment need to be a fragment ?

    – JCDecary
    Nov 21 '18 at 20:05














1












1








1








When trying to load a fragment coming from another fragment layout my application stops.



When looking at the logcat I get this error:



android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flow/com.example.flow.displayClasses.GroupScreens.HomeGroupFragment}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2005)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
at android.app.Activity.startActivityForResult(Activity.java:4586)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:881)
at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:995)
at android.support.v4.app.Fragment.startActivity(Fragment.java:1084)
at android.support.v4.app.Fragment.startActivity(Fragment.java:1073)
at com.example.flow.displayClasses.GroupScreens.GroupsFragment$1.onItemClick(GroupsFragment.java:170)
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
at android.widget.AbsListView.performItemClick(AbsListView.java:1159)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3136)
at android.widget.AbsListView$3.run(AbsListView.java:4052)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)


My fragment from where I come:



package com.example.flow.displayClasses.GroupScreens;




import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.example.flow.R;
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import android.content.Intent;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.flow.classes.Friends;
import com.example.flow.classes.Group;
import com.example.flow.classes.User;
import com.example.flow.displayClasses.FriendsScreen.FriendsFragment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.view.MenuItem;
import android.support.annotation.Nullable;
import android.widget.Toast;


public class GroupsFragment extends Fragment {

private final String TAG = this.getClass().getSimpleName();

private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;

ArrayList<Group> groups = new ArrayList<Group>();


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

public static GroupsFragment newInstance(String param1, String param2) {
GroupsFragment fragment = new GroupsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}


}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View RootView = inflater.inflate(R.layout.fragment_groups, container, false);

// Hardcoded for testing
User u1 = new User("Bram", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u2 = new User("Bram1", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u3 = new User("Bram2", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u4 = new User("Bram3", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u5 = new User("Bram4", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u6 = new User("Bram5", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u7 = new User("Bram6", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u8 = new User("Bram7", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u9 = new User("Bram8", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u10 = new User("Bram9", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u11 = new User("Bram10", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u12 = new User("Bram11", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u13 = new User("Bram12", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u14 = new User("Bram13", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u15 = new User("Bram14", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u16 = new User("Bram15", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u17 = new User("Bram16", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u18 = new User("Bram17", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");

ArrayList<User> ug1 = new ArrayList<User>();

ug1.add(u1);
ug1.add(u2);
ug1.add(u3);

ArrayList<User> ug2 = new ArrayList<User>();

ug2.add(u4);
ug2.add(u5);
ug2.add(u6);
//Collections.addAll(ug1, u4, u5, u6);

ArrayList<User> ug3 = new ArrayList<User>();
ug3.add(u1);
ug3.add(u7);
ug3.add(u8);
ug3.add(u9);

//Collections.addAll(ug1, u7, u8, u9);

ArrayList<User> ug4 = new ArrayList<User>();
Collections.addAll(ug1, u10, u11, u12);

ArrayList<User> ug5 = new ArrayList<User>();
Collections.addAll(ug1, u13, u14, u15);

ArrayList<User> ug6 = new ArrayList<User>();
Collections.addAll(ug1, u14, u5, u6);

ArrayList<User> ug7 = new ArrayList<User>();
Collections.addAll(ug1, u4, u10, u6, u18, u17);

ArrayList<User> ug8 = new ArrayList<User>();
Collections.addAll(ug1, u4, u5, u6);

Group g1 = new Group(1, ug1, u1, "budies", u1, "date", true);
Group g8 = new Group(2, ug1, u1, "budies", u1, "date", false);
Group g9 = new Group(3, ug1, u1, "budies", u1, "date", true);
Group g10 = new Group(4, ug1, u1, "budies", u1, "date", false);
Group g11 = new Group(5, ug1, u1, "budies", u1, "date", true);
Group g12 = new Group(6, ug1, u1, "budies", u1, "date", false);
Group g13 = new Group(7, ug1, u1, "budies", u1, "date", false);
Group g14 = new Group(8, ug1, u1, "budies", u1, "date", false);
Group g15 = new Group(9, ug1, u1, "budies", u1, "date", true);
Group g16 = new Group(10, ug1, u1, "budies", u1, "date", true);
Group g17 = new Group(11, ug1, u1, "budies", u1, "date", true);
Group g18 = new Group(12, ug1, u1, "budies", u1, "date", false);


Collections.addAll(groups, g1, g8, g9, g10, g11, g12, g13, g14, g15, g16, g17, g18);

ListView list = (ListView)RootView.findViewById(R.id.listView);
CustomAdapter adapter = new CustomAdapter();
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getActivity().getApplicationContext(), HomeGroupFragment.class);
intent.putExtra("group", groups.get(position));

startActivity(intent);
}
});

return RootView;

}


class CustomAdapter extends BaseAdapter {

int index;

@Override
public int getCount() {
return groups.size();
}

@Override
public Object getItem(int position) {
return position;
}

@Override
public long getItemId(int id) {
return id ;
}

public View getView(int i, View view, ViewGroup viewgroup) {

if (groups.get(i).isPrepaid()) {
view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null);
} else {
view = getLayoutInflater().inflate(R.layout.groups_layout, null);
}


TextView textView = view.findViewById(R.id.Groupname);
ImageView image = view.findViewById(R.id.member);
String t = groups.get(i).getName();
textView.setText(t);

return view;
}
}
}


The fragment that won't load:



package com.example.flow.displayClasses.GroupScreens;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import android.widget.Toast;

import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.example.flow.Home;
import com.example.flow.R;
import com.example.flow.classes.Group;
import com.example.flow.classes.GroupExpense;
import com.example.flow.classes.UserExpense;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;

public class HomeGroupFragment extends Fragment {

private final String TAG = this.getClass().getSimpleName();

private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;

ArrayList<GroupExpense> expense = new ArrayList<GroupExpense>();


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

public static HomeGroupFragment newInstance(String param1, String param2) {
HomeGroupFragment fragment = new HomeGroupFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

Group group;
boolean status;

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

super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}

}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View RootView = inflater.inflate(R.layout.fragment_group, container, false);
/*
super.onCreate(savedInstanceState);
getActivity().setContentView(R.layout.fragment_group);
ConstraintLayout layout =getActivity().findViewById(R.id.groupLayout);
status = true;*/

//harcoded

UserExpense ux = new UserExpense(group.getUsers().get(2), 5.3);
UserExpense ux1 = new UserExpense(group.getUsers().get(3), 6.91);

ArrayList<UserExpense> uxs = new ArrayList<UserExpense>();
Collections.addAll(uxs, ux, ux1);

GroupExpense ex = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex1 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex2 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex3 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex4 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex5 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex6 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex7 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex8 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex9 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex10 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex11 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex12 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex13 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex14 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex15 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);


Collections.addAll(expense, ex, ex1, ex2, ex3, ex4, ex5, ex6, ex7, ex8, ex9, ex10, ex11, ex12, ex13, ex14, ex15);

Intent intent = getActivity().getIntent();
group = Objects.requireNonNull(intent.getExtras()).getParcelable("group");

int id = intent.getIntExtra("group", -1);

TextView t = getActivity().findViewById(R.id.Groupname);
t.setText(group.getName());
t.setId(group.getGroupId());

setLayout();

return RootView;
}

public void changeToMember(View view)
{
Button member =getActivity().findViewById(R.id.member);
Button history =getActivity().findViewById(R.id.history);

if (status) {
member.setBackgroundResource(R.drawable.bottom_border_selected);
member.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
member.setTypeface(null, Typeface.BOLD);
member.setTextColor(Color.parseColor("#4799E8"));

history.setBackgroundResource(R.drawable.bottom_border);
history.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
history.setTypeface(null, Typeface.NORMAL);
history.setTextColor(Color.parseColor("#000000"));


status = false;
setLayout();
}
}

public void changeToHistory(View view)
{
Button member = getActivity().findViewById(R.id.member);
Button history =getActivity().findViewById(R.id.history);

if (!status) {
member.setBackgroundResource(R.drawable.bottom_border);
member.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
member.setTypeface(null, Typeface.NORMAL);
member.setTextColor(Color.parseColor("#000000"));

history.setBackgroundResource(R.drawable.bottom_border_selected);
history.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
history.setTypeface(null, Typeface.BOLD);
history.setTextColor(Color.parseColor("#4799E8"));
status = true;
setLayout();
}
}

public void setLayout()
{
ListView list = getActivity().findViewById(R.id.expenseList);
CustomAdapter ad = new CustomAdapter();
list.setAdapter(ad);

list.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
if (status) {
Intent intent = new Intent(getActivity().getApplicationContext(), GroupExpenseFragment.class);
intent.putExtra("expense", expense.get(position));
startActivity(intent);
} else {
Intent intent = new Intent(getActivity().getApplicationContext(), Home.class);
intent.putExtra("group", group.getUsers().get(position));
startActivity(intent);
}
}
});
}

public void leaveGroup(View view)
{

}

class CustomAdapter extends BaseAdapter
{

@Override
public int getCount()
{

return status ? expense.size() : group.getUsers().size();
}

@Override
public Object getItem(int position)
{
return position;
}

@Override
public long getItemId(int id)
{
return id;
}

public View getView(int i, View view, ViewGroup viewgroup)
{

if (status) {
view = getLayoutInflater().inflate(R.layout.group_expense_layout, null);

TextView user = view.findViewById(R.id.username);
TextView subject = view.findViewById(R.id.subject);
TextView amount = view.findViewById(R.id.expenseAmount);

user.setText(expense.get(i).getCreditor().getName());
subject.setText(expense.get(i).getName());
amount.setText(String.valueOf(expense.get(i).getAmount()));
} else {
view = getLayoutInflater().inflate(R.layout.group_member_layout, null);

TextView name = view.findViewById(R.id.nameMember);
TextView admin = view.findViewById(R.id.privilege);
TextView date = view.findViewById(R.id.date);

name.setText(group.getUsers().get(i).getName());
admin.setText("");
date.setText("");
}

return view;
}
}
}


The fragment_group.xml file:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.HomeGroupFragment">

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/groupLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.GroupFragment">
<TextView
android:id="@+id/Groupname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/group_name"
android:textColor="#428EC4"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/member"
style="@style/selected"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="@string/history"
android:textAllCaps="false"
app:layout_constraintEnd_toStartOf="@+id/history"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Groupname" />

<Button
android:id="@+id/history"
style="@style/unselected"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="@string/members"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/member"
app:layout_constraintTop_toBottomOf="@+id/Groupname" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/history">


<ListView
android:id="@+id/expenseList"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>
</LinearLayout>

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/leave_group"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>
</RelativeLayout>


The group_expense_layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="25dp"
android:text="Username"
android:textSize="18sp"
android:textStyle="bold" />

<TextView
android:id="@+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/username"
android:layout_marginStart="65dp"
android:layout_toEndOf="@+id/username"
android:text="Name" />

<TextView
android:id="@+id/expenseAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/username"
android:layout_alignParentEnd="true"
android:layout_marginStart="93dp"
android:layout_marginEnd="25dp"
android:layout_toEndOf="@+id/subject"
android:text="TextView" />

</RelativeLayout>


The manifest:



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.flow">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label=" "
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:icon,android:label">

<activity
android:theme="@style/AppTheme"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:theme="@style/AppTheme.NoActionBar"
android:name=".Home"
android:parentActivityName=".displayClasses.LoginScreens.Login">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".displayClasses.LoginScreens.Login" />
</activity>

<activity
android:theme="@style/AppTheme"
android:name=".displayClasses.LoginScreens.activity_signup" />

<activity
android:theme="@style/AppTheme"
android:name=".displayClasses.LoginScreens.Login" />

</application>
</manifest>


But as far as I know I shouldn't implement a fragment in my Manifest. So do I need to rewrite the Intent statements? And so yes, how do I do it correctly? I'm learning to work with Android Studio any help is much appreciated.










share|improve this question
















When trying to load a fragment coming from another fragment layout my application stops.



When looking at the logcat I get this error:



android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flow/com.example.flow.displayClasses.GroupScreens.HomeGroupFragment}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2005)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
at android.app.Activity.startActivityForResult(Activity.java:4586)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:881)
at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:995)
at android.support.v4.app.Fragment.startActivity(Fragment.java:1084)
at android.support.v4.app.Fragment.startActivity(Fragment.java:1073)
at com.example.flow.displayClasses.GroupScreens.GroupsFragment$1.onItemClick(GroupsFragment.java:170)
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
at android.widget.AbsListView.performItemClick(AbsListView.java:1159)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3136)
at android.widget.AbsListView$3.run(AbsListView.java:4052)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)


My fragment from where I come:



package com.example.flow.displayClasses.GroupScreens;




import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.example.flow.R;
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import android.content.Intent;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.flow.classes.Friends;
import com.example.flow.classes.Group;
import com.example.flow.classes.User;
import com.example.flow.displayClasses.FriendsScreen.FriendsFragment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.view.MenuItem;
import android.support.annotation.Nullable;
import android.widget.Toast;


public class GroupsFragment extends Fragment {

private final String TAG = this.getClass().getSimpleName();

private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;

ArrayList<Group> groups = new ArrayList<Group>();


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

public static GroupsFragment newInstance(String param1, String param2) {
GroupsFragment fragment = new GroupsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}


}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View RootView = inflater.inflate(R.layout.fragment_groups, container, false);

// Hardcoded for testing
User u1 = new User("Bram", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u2 = new User("Bram1", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u3 = new User("Bram2", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u4 = new User("Bram3", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u5 = new User("Bram4", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u6 = new User("Bram5", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u7 = new User("Bram6", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u8 = new User("Bram7", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u9 = new User("Bram8", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u10 = new User("Bram9", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u11 = new User("Bram10", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u12 = new User("Bram11", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u13 = new User("Bram12", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u14 = new User("Bram13", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u15 = new User("Bram14", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u16 = new User("Bram15", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u17 = new User("Bram16", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");
User u18 = new User("Bram17", "bram.de.plekker@student.ehb.be", "1234", "Captain Plek");

ArrayList<User> ug1 = new ArrayList<User>();

ug1.add(u1);
ug1.add(u2);
ug1.add(u3);

ArrayList<User> ug2 = new ArrayList<User>();

ug2.add(u4);
ug2.add(u5);
ug2.add(u6);
//Collections.addAll(ug1, u4, u5, u6);

ArrayList<User> ug3 = new ArrayList<User>();
ug3.add(u1);
ug3.add(u7);
ug3.add(u8);
ug3.add(u9);

//Collections.addAll(ug1, u7, u8, u9);

ArrayList<User> ug4 = new ArrayList<User>();
Collections.addAll(ug1, u10, u11, u12);

ArrayList<User> ug5 = new ArrayList<User>();
Collections.addAll(ug1, u13, u14, u15);

ArrayList<User> ug6 = new ArrayList<User>();
Collections.addAll(ug1, u14, u5, u6);

ArrayList<User> ug7 = new ArrayList<User>();
Collections.addAll(ug1, u4, u10, u6, u18, u17);

ArrayList<User> ug8 = new ArrayList<User>();
Collections.addAll(ug1, u4, u5, u6);

Group g1 = new Group(1, ug1, u1, "budies", u1, "date", true);
Group g8 = new Group(2, ug1, u1, "budies", u1, "date", false);
Group g9 = new Group(3, ug1, u1, "budies", u1, "date", true);
Group g10 = new Group(4, ug1, u1, "budies", u1, "date", false);
Group g11 = new Group(5, ug1, u1, "budies", u1, "date", true);
Group g12 = new Group(6, ug1, u1, "budies", u1, "date", false);
Group g13 = new Group(7, ug1, u1, "budies", u1, "date", false);
Group g14 = new Group(8, ug1, u1, "budies", u1, "date", false);
Group g15 = new Group(9, ug1, u1, "budies", u1, "date", true);
Group g16 = new Group(10, ug1, u1, "budies", u1, "date", true);
Group g17 = new Group(11, ug1, u1, "budies", u1, "date", true);
Group g18 = new Group(12, ug1, u1, "budies", u1, "date", false);


Collections.addAll(groups, g1, g8, g9, g10, g11, g12, g13, g14, g15, g16, g17, g18);

ListView list = (ListView)RootView.findViewById(R.id.listView);
CustomAdapter adapter = new CustomAdapter();
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getActivity().getApplicationContext(), HomeGroupFragment.class);
intent.putExtra("group", groups.get(position));

startActivity(intent);
}
});

return RootView;

}


class CustomAdapter extends BaseAdapter {

int index;

@Override
public int getCount() {
return groups.size();
}

@Override
public Object getItem(int position) {
return position;
}

@Override
public long getItemId(int id) {
return id ;
}

public View getView(int i, View view, ViewGroup viewgroup) {

if (groups.get(i).isPrepaid()) {
view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null);
} else {
view = getLayoutInflater().inflate(R.layout.groups_layout, null);
}


TextView textView = view.findViewById(R.id.Groupname);
ImageView image = view.findViewById(R.id.member);
String t = groups.get(i).getName();
textView.setText(t);

return view;
}
}
}


The fragment that won't load:



package com.example.flow.displayClasses.GroupScreens;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import android.widget.Toast;

import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.example.flow.Home;
import com.example.flow.R;
import com.example.flow.classes.Group;
import com.example.flow.classes.GroupExpense;
import com.example.flow.classes.UserExpense;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;

public class HomeGroupFragment extends Fragment {

private final String TAG = this.getClass().getSimpleName();

private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;

ArrayList<GroupExpense> expense = new ArrayList<GroupExpense>();


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

public static HomeGroupFragment newInstance(String param1, String param2) {
HomeGroupFragment fragment = new HomeGroupFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

Group group;
boolean status;

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

super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}

}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View RootView = inflater.inflate(R.layout.fragment_group, container, false);
/*
super.onCreate(savedInstanceState);
getActivity().setContentView(R.layout.fragment_group);
ConstraintLayout layout =getActivity().findViewById(R.id.groupLayout);
status = true;*/

//harcoded

UserExpense ux = new UserExpense(group.getUsers().get(2), 5.3);
UserExpense ux1 = new UserExpense(group.getUsers().get(3), 6.91);

ArrayList<UserExpense> uxs = new ArrayList<UserExpense>();
Collections.addAll(uxs, ux, ux1);

GroupExpense ex = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex1 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex2 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex3 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex4 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex5 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex6 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex7 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex8 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex9 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex10 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex11 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex12 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex13 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex14 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);
GroupExpense ex15 = new GroupExpense(1, group.getUsers().get(1), "pitta", "voor te eten", 12.21, "13 oktober 2018", uxs);


Collections.addAll(expense, ex, ex1, ex2, ex3, ex4, ex5, ex6, ex7, ex8, ex9, ex10, ex11, ex12, ex13, ex14, ex15);

Intent intent = getActivity().getIntent();
group = Objects.requireNonNull(intent.getExtras()).getParcelable("group");

int id = intent.getIntExtra("group", -1);

TextView t = getActivity().findViewById(R.id.Groupname);
t.setText(group.getName());
t.setId(group.getGroupId());

setLayout();

return RootView;
}

public void changeToMember(View view)
{
Button member =getActivity().findViewById(R.id.member);
Button history =getActivity().findViewById(R.id.history);

if (status) {
member.setBackgroundResource(R.drawable.bottom_border_selected);
member.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
member.setTypeface(null, Typeface.BOLD);
member.setTextColor(Color.parseColor("#4799E8"));

history.setBackgroundResource(R.drawable.bottom_border);
history.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
history.setTypeface(null, Typeface.NORMAL);
history.setTextColor(Color.parseColor("#000000"));


status = false;
setLayout();
}
}

public void changeToHistory(View view)
{
Button member = getActivity().findViewById(R.id.member);
Button history =getActivity().findViewById(R.id.history);

if (!status) {
member.setBackgroundResource(R.drawable.bottom_border);
member.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
member.setTypeface(null, Typeface.NORMAL);
member.setTextColor(Color.parseColor("#000000"));

history.setBackgroundResource(R.drawable.bottom_border_selected);
history.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
history.setTypeface(null, Typeface.BOLD);
history.setTextColor(Color.parseColor("#4799E8"));
status = true;
setLayout();
}
}

public void setLayout()
{
ListView list = getActivity().findViewById(R.id.expenseList);
CustomAdapter ad = new CustomAdapter();
list.setAdapter(ad);

list.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
if (status) {
Intent intent = new Intent(getActivity().getApplicationContext(), GroupExpenseFragment.class);
intent.putExtra("expense", expense.get(position));
startActivity(intent);
} else {
Intent intent = new Intent(getActivity().getApplicationContext(), Home.class);
intent.putExtra("group", group.getUsers().get(position));
startActivity(intent);
}
}
});
}

public void leaveGroup(View view)
{

}

class CustomAdapter extends BaseAdapter
{

@Override
public int getCount()
{

return status ? expense.size() : group.getUsers().size();
}

@Override
public Object getItem(int position)
{
return position;
}

@Override
public long getItemId(int id)
{
return id;
}

public View getView(int i, View view, ViewGroup viewgroup)
{

if (status) {
view = getLayoutInflater().inflate(R.layout.group_expense_layout, null);

TextView user = view.findViewById(R.id.username);
TextView subject = view.findViewById(R.id.subject);
TextView amount = view.findViewById(R.id.expenseAmount);

user.setText(expense.get(i).getCreditor().getName());
subject.setText(expense.get(i).getName());
amount.setText(String.valueOf(expense.get(i).getAmount()));
} else {
view = getLayoutInflater().inflate(R.layout.group_member_layout, null);

TextView name = view.findViewById(R.id.nameMember);
TextView admin = view.findViewById(R.id.privilege);
TextView date = view.findViewById(R.id.date);

name.setText(group.getUsers().get(i).getName());
admin.setText("");
date.setText("");
}

return view;
}
}
}


The fragment_group.xml file:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.HomeGroupFragment">

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/groupLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.GroupFragment">
<TextView
android:id="@+id/Groupname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/group_name"
android:textColor="#428EC4"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/member"
style="@style/selected"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="@string/history"
android:textAllCaps="false"
app:layout_constraintEnd_toStartOf="@+id/history"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Groupname" />

<Button
android:id="@+id/history"
style="@style/unselected"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="@string/members"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/member"
app:layout_constraintTop_toBottomOf="@+id/Groupname" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/history">


<ListView
android:id="@+id/expenseList"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>
</LinearLayout>

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/leave_group"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>
</RelativeLayout>


The group_expense_layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="25dp"
android:text="Username"
android:textSize="18sp"
android:textStyle="bold" />

<TextView
android:id="@+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/username"
android:layout_marginStart="65dp"
android:layout_toEndOf="@+id/username"
android:text="Name" />

<TextView
android:id="@+id/expenseAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/username"
android:layout_alignParentEnd="true"
android:layout_marginStart="93dp"
android:layout_marginEnd="25dp"
android:layout_toEndOf="@+id/subject"
android:text="TextView" />

</RelativeLayout>


The manifest:



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.flow">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label=" "
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:icon,android:label">

<activity
android:theme="@style/AppTheme"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:theme="@style/AppTheme.NoActionBar"
android:name=".Home"
android:parentActivityName=".displayClasses.LoginScreens.Login">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".displayClasses.LoginScreens.Login" />
</activity>

<activity
android:theme="@style/AppTheme"
android:name=".displayClasses.LoginScreens.activity_signup" />

<activity
android:theme="@style/AppTheme"
android:name=".displayClasses.LoginScreens.Login" />

</application>
</manifest>


But as far as I know I shouldn't implement a fragment in my Manifest. So do I need to rewrite the Intent statements? And so yes, how do I do it correctly? I'm learning to work with Android Studio any help is much appreciated.







java android android-fragments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 19:56







Inyea

















asked Nov 21 '18 at 19:33









InyeaInyea

124




124













  • can you add your manifest ?

    – JCDecary
    Nov 21 '18 at 19:52











  • @JCDecary placed it below the post.

    – Inyea
    Nov 21 '18 at 19:57











  • any reason why HomeGroupFragment need to be a fragment ?

    – JCDecary
    Nov 21 '18 at 20:05



















  • can you add your manifest ?

    – JCDecary
    Nov 21 '18 at 19:52











  • @JCDecary placed it below the post.

    – Inyea
    Nov 21 '18 at 19:57











  • any reason why HomeGroupFragment need to be a fragment ?

    – JCDecary
    Nov 21 '18 at 20:05

















can you add your manifest ?

– JCDecary
Nov 21 '18 at 19:52





can you add your manifest ?

– JCDecary
Nov 21 '18 at 19:52













@JCDecary placed it below the post.

– Inyea
Nov 21 '18 at 19:57





@JCDecary placed it below the post.

– Inyea
Nov 21 '18 at 19:57













any reason why HomeGroupFragment need to be a fragment ?

– JCDecary
Nov 21 '18 at 20:05





any reason why HomeGroupFragment need to be a fragment ?

– JCDecary
Nov 21 '18 at 20:05












2 Answers
2






active

oldest

votes


















0














android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flow/com.example.flow.displayClasses.GroupScreens.HomeGroupFragment}; have you declared this activity in your AndroidManifest.xml?


Have you declared the activity inside the Manifest?



EDIT:



This code here



        @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getActivity().getApplicationContext(), HomeGroupFragment.class);
intent.putExtra("group", groups.get(position));

startActivity(intent);
}


That's not how you initialize a fragment.
startActivity() is used to start activites. That's why the crash is happening.



To use a framgent you have to do a Fragment Transaction. Create a FrameLayout in you activity where you will add that fragment.
More info How do I add a Fragment to an Activity with a programmatically created content view






share|improve this answer


























  • Should I? I mean, I thought that a fragment (HomegroupFragment) shouldn't be declared. The activity that the other fragment( where you come from) uses is declared in the manifest.

    – Inyea
    Nov 21 '18 at 19:54











  • Could you show what the proper way to initialize a fragment?

    – Inyea
    Nov 21 '18 at 20:07











  • @RhaniEgghe please follow tutorials to properly understand it.

    – NIKHIL MAURYA
    Nov 21 '18 at 20:09











  • I am doing so but sometimes I get confused. From the post you linked I think I know how to properly implement it. What I came up with: HomeGroupFragment homeGroupFragment = new HomeGroupFragment(); FragmentManager manager = getFragmentManager(); manager.beginTransaction( .replace(R.id.relativelayout_for_fragment, homeGroupFragment, homeGroupFragment.getTag() ).commit();

    – Inyea
    Nov 21 '18 at 20:20











  • Do you have a FrameLayout in your activity_main.xml?

    – armen
    Nov 21 '18 at 21:16





















0














You need to import these libraries:



 import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;


Then in onClick you need to call fragment transation for display
a fragment. Intents are for activities:



 HomeGroupFragment f = HomeGroupFragment.newInstance(position); // call the fragment you want to display with new instance
//f.setArguments(bundle); // if you want to send arguments
FragmentManager fragmentManager = getSupportFragmentManager(); // for transaction, call fragment manager
fragmentManager.beginTransaction().replace(R.id.main_frame, f).addToBackStack(null).commit();
// addToBackStack = optional if ypu want to add the fragment to stack
// commit = end the transaction


If you want to send arguments:



 Bundle bundle = new Bundle();
bundle.putInt("position", groups.get(position));
bundle.putString("anyText", groups.getText());





share|improve this answer


























  • Thanks for your reply! Do I need to import any other things, because it can't seem to resolve 'groups'

    – Inyea
    Nov 21 '18 at 22:41











  • you have different id of ListView(grupo fragment). Does it display the fragment??

    – armen
    Nov 21 '18 at 23:18











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419337%2funable-to-load-fragment-from-other-fragment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flow/com.example.flow.displayClasses.GroupScreens.HomeGroupFragment}; have you declared this activity in your AndroidManifest.xml?


Have you declared the activity inside the Manifest?



EDIT:



This code here



        @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getActivity().getApplicationContext(), HomeGroupFragment.class);
intent.putExtra("group", groups.get(position));

startActivity(intent);
}


That's not how you initialize a fragment.
startActivity() is used to start activites. That's why the crash is happening.



To use a framgent you have to do a Fragment Transaction. Create a FrameLayout in you activity where you will add that fragment.
More info How do I add a Fragment to an Activity with a programmatically created content view






share|improve this answer


























  • Should I? I mean, I thought that a fragment (HomegroupFragment) shouldn't be declared. The activity that the other fragment( where you come from) uses is declared in the manifest.

    – Inyea
    Nov 21 '18 at 19:54











  • Could you show what the proper way to initialize a fragment?

    – Inyea
    Nov 21 '18 at 20:07











  • @RhaniEgghe please follow tutorials to properly understand it.

    – NIKHIL MAURYA
    Nov 21 '18 at 20:09











  • I am doing so but sometimes I get confused. From the post you linked I think I know how to properly implement it. What I came up with: HomeGroupFragment homeGroupFragment = new HomeGroupFragment(); FragmentManager manager = getFragmentManager(); manager.beginTransaction( .replace(R.id.relativelayout_for_fragment, homeGroupFragment, homeGroupFragment.getTag() ).commit();

    – Inyea
    Nov 21 '18 at 20:20











  • Do you have a FrameLayout in your activity_main.xml?

    – armen
    Nov 21 '18 at 21:16


















0














android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flow/com.example.flow.displayClasses.GroupScreens.HomeGroupFragment}; have you declared this activity in your AndroidManifest.xml?


Have you declared the activity inside the Manifest?



EDIT:



This code here



        @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getActivity().getApplicationContext(), HomeGroupFragment.class);
intent.putExtra("group", groups.get(position));

startActivity(intent);
}


That's not how you initialize a fragment.
startActivity() is used to start activites. That's why the crash is happening.



To use a framgent you have to do a Fragment Transaction. Create a FrameLayout in you activity where you will add that fragment.
More info How do I add a Fragment to an Activity with a programmatically created content view






share|improve this answer


























  • Should I? I mean, I thought that a fragment (HomegroupFragment) shouldn't be declared. The activity that the other fragment( where you come from) uses is declared in the manifest.

    – Inyea
    Nov 21 '18 at 19:54











  • Could you show what the proper way to initialize a fragment?

    – Inyea
    Nov 21 '18 at 20:07











  • @RhaniEgghe please follow tutorials to properly understand it.

    – NIKHIL MAURYA
    Nov 21 '18 at 20:09











  • I am doing so but sometimes I get confused. From the post you linked I think I know how to properly implement it. What I came up with: HomeGroupFragment homeGroupFragment = new HomeGroupFragment(); FragmentManager manager = getFragmentManager(); manager.beginTransaction( .replace(R.id.relativelayout_for_fragment, homeGroupFragment, homeGroupFragment.getTag() ).commit();

    – Inyea
    Nov 21 '18 at 20:20











  • Do you have a FrameLayout in your activity_main.xml?

    – armen
    Nov 21 '18 at 21:16
















0












0








0







android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flow/com.example.flow.displayClasses.GroupScreens.HomeGroupFragment}; have you declared this activity in your AndroidManifest.xml?


Have you declared the activity inside the Manifest?



EDIT:



This code here



        @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getActivity().getApplicationContext(), HomeGroupFragment.class);
intent.putExtra("group", groups.get(position));

startActivity(intent);
}


That's not how you initialize a fragment.
startActivity() is used to start activites. That's why the crash is happening.



To use a framgent you have to do a Fragment Transaction. Create a FrameLayout in you activity where you will add that fragment.
More info How do I add a Fragment to an Activity with a programmatically created content view






share|improve this answer















android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flow/com.example.flow.displayClasses.GroupScreens.HomeGroupFragment}; have you declared this activity in your AndroidManifest.xml?


Have you declared the activity inside the Manifest?



EDIT:



This code here



        @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(getActivity().getApplicationContext(), HomeGroupFragment.class);
intent.putExtra("group", groups.get(position));

startActivity(intent);
}


That's not how you initialize a fragment.
startActivity() is used to start activites. That's why the crash is happening.



To use a framgent you have to do a Fragment Transaction. Create a FrameLayout in you activity where you will add that fragment.
More info How do I add a Fragment to an Activity with a programmatically created content view







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 20:09

























answered Nov 21 '18 at 19:49









NIKHIL MAURYANIKHIL MAURYA

1319




1319













  • Should I? I mean, I thought that a fragment (HomegroupFragment) shouldn't be declared. The activity that the other fragment( where you come from) uses is declared in the manifest.

    – Inyea
    Nov 21 '18 at 19:54











  • Could you show what the proper way to initialize a fragment?

    – Inyea
    Nov 21 '18 at 20:07











  • @RhaniEgghe please follow tutorials to properly understand it.

    – NIKHIL MAURYA
    Nov 21 '18 at 20:09











  • I am doing so but sometimes I get confused. From the post you linked I think I know how to properly implement it. What I came up with: HomeGroupFragment homeGroupFragment = new HomeGroupFragment(); FragmentManager manager = getFragmentManager(); manager.beginTransaction( .replace(R.id.relativelayout_for_fragment, homeGroupFragment, homeGroupFragment.getTag() ).commit();

    – Inyea
    Nov 21 '18 at 20:20











  • Do you have a FrameLayout in your activity_main.xml?

    – armen
    Nov 21 '18 at 21:16





















  • Should I? I mean, I thought that a fragment (HomegroupFragment) shouldn't be declared. The activity that the other fragment( where you come from) uses is declared in the manifest.

    – Inyea
    Nov 21 '18 at 19:54











  • Could you show what the proper way to initialize a fragment?

    – Inyea
    Nov 21 '18 at 20:07











  • @RhaniEgghe please follow tutorials to properly understand it.

    – NIKHIL MAURYA
    Nov 21 '18 at 20:09











  • I am doing so but sometimes I get confused. From the post you linked I think I know how to properly implement it. What I came up with: HomeGroupFragment homeGroupFragment = new HomeGroupFragment(); FragmentManager manager = getFragmentManager(); manager.beginTransaction( .replace(R.id.relativelayout_for_fragment, homeGroupFragment, homeGroupFragment.getTag() ).commit();

    – Inyea
    Nov 21 '18 at 20:20











  • Do you have a FrameLayout in your activity_main.xml?

    – armen
    Nov 21 '18 at 21:16



















Should I? I mean, I thought that a fragment (HomegroupFragment) shouldn't be declared. The activity that the other fragment( where you come from) uses is declared in the manifest.

– Inyea
Nov 21 '18 at 19:54





Should I? I mean, I thought that a fragment (HomegroupFragment) shouldn't be declared. The activity that the other fragment( where you come from) uses is declared in the manifest.

– Inyea
Nov 21 '18 at 19:54













Could you show what the proper way to initialize a fragment?

– Inyea
Nov 21 '18 at 20:07





Could you show what the proper way to initialize a fragment?

– Inyea
Nov 21 '18 at 20:07













@RhaniEgghe please follow tutorials to properly understand it.

– NIKHIL MAURYA
Nov 21 '18 at 20:09





@RhaniEgghe please follow tutorials to properly understand it.

– NIKHIL MAURYA
Nov 21 '18 at 20:09













I am doing so but sometimes I get confused. From the post you linked I think I know how to properly implement it. What I came up with: HomeGroupFragment homeGroupFragment = new HomeGroupFragment(); FragmentManager manager = getFragmentManager(); manager.beginTransaction( .replace(R.id.relativelayout_for_fragment, homeGroupFragment, homeGroupFragment.getTag() ).commit();

– Inyea
Nov 21 '18 at 20:20





I am doing so but sometimes I get confused. From the post you linked I think I know how to properly implement it. What I came up with: HomeGroupFragment homeGroupFragment = new HomeGroupFragment(); FragmentManager manager = getFragmentManager(); manager.beginTransaction( .replace(R.id.relativelayout_for_fragment, homeGroupFragment, homeGroupFragment.getTag() ).commit();

– Inyea
Nov 21 '18 at 20:20













Do you have a FrameLayout in your activity_main.xml?

– armen
Nov 21 '18 at 21:16







Do you have a FrameLayout in your activity_main.xml?

– armen
Nov 21 '18 at 21:16















0














You need to import these libraries:



 import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;


Then in onClick you need to call fragment transation for display
a fragment. Intents are for activities:



 HomeGroupFragment f = HomeGroupFragment.newInstance(position); // call the fragment you want to display with new instance
//f.setArguments(bundle); // if you want to send arguments
FragmentManager fragmentManager = getSupportFragmentManager(); // for transaction, call fragment manager
fragmentManager.beginTransaction().replace(R.id.main_frame, f).addToBackStack(null).commit();
// addToBackStack = optional if ypu want to add the fragment to stack
// commit = end the transaction


If you want to send arguments:



 Bundle bundle = new Bundle();
bundle.putInt("position", groups.get(position));
bundle.putString("anyText", groups.getText());





share|improve this answer


























  • Thanks for your reply! Do I need to import any other things, because it can't seem to resolve 'groups'

    – Inyea
    Nov 21 '18 at 22:41











  • you have different id of ListView(grupo fragment). Does it display the fragment??

    – armen
    Nov 21 '18 at 23:18
















0














You need to import these libraries:



 import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;


Then in onClick you need to call fragment transation for display
a fragment. Intents are for activities:



 HomeGroupFragment f = HomeGroupFragment.newInstance(position); // call the fragment you want to display with new instance
//f.setArguments(bundle); // if you want to send arguments
FragmentManager fragmentManager = getSupportFragmentManager(); // for transaction, call fragment manager
fragmentManager.beginTransaction().replace(R.id.main_frame, f).addToBackStack(null).commit();
// addToBackStack = optional if ypu want to add the fragment to stack
// commit = end the transaction


If you want to send arguments:



 Bundle bundle = new Bundle();
bundle.putInt("position", groups.get(position));
bundle.putString("anyText", groups.getText());





share|improve this answer


























  • Thanks for your reply! Do I need to import any other things, because it can't seem to resolve 'groups'

    – Inyea
    Nov 21 '18 at 22:41











  • you have different id of ListView(grupo fragment). Does it display the fragment??

    – armen
    Nov 21 '18 at 23:18














0












0








0







You need to import these libraries:



 import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;


Then in onClick you need to call fragment transation for display
a fragment. Intents are for activities:



 HomeGroupFragment f = HomeGroupFragment.newInstance(position); // call the fragment you want to display with new instance
//f.setArguments(bundle); // if you want to send arguments
FragmentManager fragmentManager = getSupportFragmentManager(); // for transaction, call fragment manager
fragmentManager.beginTransaction().replace(R.id.main_frame, f).addToBackStack(null).commit();
// addToBackStack = optional if ypu want to add the fragment to stack
// commit = end the transaction


If you want to send arguments:



 Bundle bundle = new Bundle();
bundle.putInt("position", groups.get(position));
bundle.putString("anyText", groups.getText());





share|improve this answer















You need to import these libraries:



 import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;


Then in onClick you need to call fragment transation for display
a fragment. Intents are for activities:



 HomeGroupFragment f = HomeGroupFragment.newInstance(position); // call the fragment you want to display with new instance
//f.setArguments(bundle); // if you want to send arguments
FragmentManager fragmentManager = getSupportFragmentManager(); // for transaction, call fragment manager
fragmentManager.beginTransaction().replace(R.id.main_frame, f).addToBackStack(null).commit();
// addToBackStack = optional if ypu want to add the fragment to stack
// commit = end the transaction


If you want to send arguments:



 Bundle bundle = new Bundle();
bundle.putInt("position", groups.get(position));
bundle.putString("anyText", groups.getText());






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 23:03

























answered Nov 21 '18 at 21:55









armenarmen

22125




22125













  • Thanks for your reply! Do I need to import any other things, because it can't seem to resolve 'groups'

    – Inyea
    Nov 21 '18 at 22:41











  • you have different id of ListView(grupo fragment). Does it display the fragment??

    – armen
    Nov 21 '18 at 23:18



















  • Thanks for your reply! Do I need to import any other things, because it can't seem to resolve 'groups'

    – Inyea
    Nov 21 '18 at 22:41











  • you have different id of ListView(grupo fragment). Does it display the fragment??

    – armen
    Nov 21 '18 at 23:18

















Thanks for your reply! Do I need to import any other things, because it can't seem to resolve 'groups'

– Inyea
Nov 21 '18 at 22:41





Thanks for your reply! Do I need to import any other things, because it can't seem to resolve 'groups'

– Inyea
Nov 21 '18 at 22:41













you have different id of ListView(grupo fragment). Does it display the fragment??

– armen
Nov 21 '18 at 23:18





you have different id of ListView(grupo fragment). Does it display the fragment??

– armen
Nov 21 '18 at 23:18


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419337%2funable-to-load-fragment-from-other-fragment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy