EditText added is not a TextInputEditText. Please switch to using that class instead. (Debugger) [duplicate]












-1
















This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers




When running my code I keep getting this error in my logcat: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference



When debugging I get the following message:
EditText added is not a TextInputEditText. Please switch to using that class instead.



I have been searching for days but without luck. I am still learning to work with Android Studio so any help to resolve my problem would be appreciated!



My "GroupsFragment.java":



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 android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;

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);


/*
BindDictionary<Group> dictionary = new BindDictionary<>();

dictionary.addStringField(R.id.blabla, new StringExtractor<Group>() {
@Override
public String getStringValue(Group groupname, int position) {
return groupname.getName();
}
});

dictionary.addStringField(R.id.prepaidIcon, new StringExtractor<Group>() {
@Override
public String getStringValue(Group prepaid, int position) {
return "" + prepaid.isPrepaid();
}
});
FunDapter adapter = new FunDapter(GroupsFragment.this.getActivity(), groups, R.layout.groups_layout, dictionary);
*/

//getActivity() returns the Activity hosting the Fragment,
// while getView() returns the view you inflated and returned by onCreateView
//may cause nullpointer exception


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)
{
Group selectedProduct = groups.get(position);
Toast.makeText(GroupsFragment.this.getActivity(), selectedProduct.getName(), Toast.LENGTH_SHORT).show();

}
});

return RootView;

}


class CustomAdapter extends BaseAdapter {

int index;

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

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

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

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.blabla);
ImageView image = view.findViewById(R.id.member);
String t = groups.get(i).getName();
textView.setText(t);//nullpointer exception

return view;
}
}
}


My "groups_lay_out.xml":



<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/blabla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"

android:text="@string/textview"
android:textAppearance="?android:attr/textAppearanceLarge" />


<ImageView
android:id="@+id/member"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/blabla"
android:layout_marginStart="20dp"
android:src="@drawable/ic_member" />
</RelativeLayout>


My "fragment_groups.xml":



<?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:id="@+id/groupsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.GroupsFragment"
>


<TextView
android:id="@+id/groupName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"


android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="@string/groups"
android:textColor="#428EC4"
android:textSize="30sp"
android:textStyle="bold" />


<EditText
android:id="@+id/search_bar"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="20dp"
android:layout_marginTop="77dp"
android:layout_marginEnd="20dp"
android:background="@drawable/ic_bordersearch"
android:ems="10"
android:gravity="center"
android:hint="@string/search_text" />

<ImageButton
android:id="@+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignTop="@+id/search_bar"
android:layout_alignEnd="@+id/search_bar"
android:layout_alignBottom="@+id/search_bar"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_search_icon" />

<ImageButton
android:id="@+id/plusButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="298dp"
android:layout_marginEnd="25dp"
android:layout_marginBottom="55dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_plussign" />


<RelativeLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="386dp"
android:layout_below="@+id/search_bar"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="20dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="50dp"
android:orientation="vertical">

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

</RelativeLayout>


My logcat:



 Process: com.example.flow, PID: 16906
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.flow.displayClasses.GroupScreens.GroupsFragment$CustomAdapter.getView(GroupsFragment.java:237)
at android.widget.AbsListView.obtainView(AbsListView.java:2366)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillFromTop(ListView.java:847)
at android.widget.ListView.layoutChildren(ListView.java:1826)
at android.widget.AbsListView.onLayout(AbsListView.java:2165)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:142)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1556)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:888)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
2018-11-21 14:01:06.799 16906-16906/com.example.flow E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


My debugger:



11/21 14:02:22: Launching app
$ adb shell am start -n "com.example.flow/com.example.flow.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Connecting to com.example.flow
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.example.flow is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8620', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1399)
W/om.example.flo: JIT profile information will not be recorded: profile file does not exits.
I/chatty: uid=10085(com.example.flow) identical 10 lines
W/om.example.flo: JIT profile information will not be recorded: profile file does not exits.
I/InstantRun: starting instant run server: is main process
W/om.example.flo: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/om.example.flo: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
D/OpenGLRenderer: Skia GL Pipeline
D/: HostConnection::get() New Host Connection established 0xcb955e80, tid 17046
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xcb897b40: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@923b4b0
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)









share|improve this question













marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Try to change view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null); to view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, parent,false); . Also must be sure that your groups list must not be null. Also return position for getItem() and getItemId() method.

    – Piyush
    Nov 21 '18 at 13:10








  • 1





    Does R.layout.groups_prepaid_layout and R.layout.groups_layout both contains textview with id "@+id/blabla"?

    – nik
    Nov 21 '18 at 13:12













  • @Piyush placing parent between R.layout.groups_prepaid_latyout and false gives me a 'couldn't resolve symbol' error. I corrected the other suggestions that you made

    – Inyea
    Nov 21 '18 at 13:33











  • @nik They didn't but they do now and it works like a charm. You made my day sir!

    – Inyea
    Nov 21 '18 at 13:35











  • @RhaniEgghe Np....happy to help.

    – nik
    Nov 22 '18 at 8:30
















-1
















This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers




When running my code I keep getting this error in my logcat: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference



When debugging I get the following message:
EditText added is not a TextInputEditText. Please switch to using that class instead.



I have been searching for days but without luck. I am still learning to work with Android Studio so any help to resolve my problem would be appreciated!



My "GroupsFragment.java":



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 android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;

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);


/*
BindDictionary<Group> dictionary = new BindDictionary<>();

dictionary.addStringField(R.id.blabla, new StringExtractor<Group>() {
@Override
public String getStringValue(Group groupname, int position) {
return groupname.getName();
}
});

dictionary.addStringField(R.id.prepaidIcon, new StringExtractor<Group>() {
@Override
public String getStringValue(Group prepaid, int position) {
return "" + prepaid.isPrepaid();
}
});
FunDapter adapter = new FunDapter(GroupsFragment.this.getActivity(), groups, R.layout.groups_layout, dictionary);
*/

//getActivity() returns the Activity hosting the Fragment,
// while getView() returns the view you inflated and returned by onCreateView
//may cause nullpointer exception


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)
{
Group selectedProduct = groups.get(position);
Toast.makeText(GroupsFragment.this.getActivity(), selectedProduct.getName(), Toast.LENGTH_SHORT).show();

}
});

return RootView;

}


class CustomAdapter extends BaseAdapter {

int index;

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

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

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

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.blabla);
ImageView image = view.findViewById(R.id.member);
String t = groups.get(i).getName();
textView.setText(t);//nullpointer exception

return view;
}
}
}


My "groups_lay_out.xml":



<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/blabla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"

android:text="@string/textview"
android:textAppearance="?android:attr/textAppearanceLarge" />


<ImageView
android:id="@+id/member"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/blabla"
android:layout_marginStart="20dp"
android:src="@drawable/ic_member" />
</RelativeLayout>


My "fragment_groups.xml":



<?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:id="@+id/groupsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.GroupsFragment"
>


<TextView
android:id="@+id/groupName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"


android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="@string/groups"
android:textColor="#428EC4"
android:textSize="30sp"
android:textStyle="bold" />


<EditText
android:id="@+id/search_bar"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="20dp"
android:layout_marginTop="77dp"
android:layout_marginEnd="20dp"
android:background="@drawable/ic_bordersearch"
android:ems="10"
android:gravity="center"
android:hint="@string/search_text" />

<ImageButton
android:id="@+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignTop="@+id/search_bar"
android:layout_alignEnd="@+id/search_bar"
android:layout_alignBottom="@+id/search_bar"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_search_icon" />

<ImageButton
android:id="@+id/plusButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="298dp"
android:layout_marginEnd="25dp"
android:layout_marginBottom="55dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_plussign" />


<RelativeLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="386dp"
android:layout_below="@+id/search_bar"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="20dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="50dp"
android:orientation="vertical">

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

</RelativeLayout>


My logcat:



 Process: com.example.flow, PID: 16906
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.flow.displayClasses.GroupScreens.GroupsFragment$CustomAdapter.getView(GroupsFragment.java:237)
at android.widget.AbsListView.obtainView(AbsListView.java:2366)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillFromTop(ListView.java:847)
at android.widget.ListView.layoutChildren(ListView.java:1826)
at android.widget.AbsListView.onLayout(AbsListView.java:2165)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:142)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1556)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:888)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
2018-11-21 14:01:06.799 16906-16906/com.example.flow E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


My debugger:



11/21 14:02:22: Launching app
$ adb shell am start -n "com.example.flow/com.example.flow.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Connecting to com.example.flow
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.example.flow is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8620', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1399)
W/om.example.flo: JIT profile information will not be recorded: profile file does not exits.
I/chatty: uid=10085(com.example.flow) identical 10 lines
W/om.example.flo: JIT profile information will not be recorded: profile file does not exits.
I/InstantRun: starting instant run server: is main process
W/om.example.flo: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/om.example.flo: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
D/OpenGLRenderer: Skia GL Pipeline
D/: HostConnection::get() New Host Connection established 0xcb955e80, tid 17046
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xcb897b40: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@923b4b0
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)









share|improve this question













marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Try to change view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null); to view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, parent,false); . Also must be sure that your groups list must not be null. Also return position for getItem() and getItemId() method.

    – Piyush
    Nov 21 '18 at 13:10








  • 1





    Does R.layout.groups_prepaid_layout and R.layout.groups_layout both contains textview with id "@+id/blabla"?

    – nik
    Nov 21 '18 at 13:12













  • @Piyush placing parent between R.layout.groups_prepaid_latyout and false gives me a 'couldn't resolve symbol' error. I corrected the other suggestions that you made

    – Inyea
    Nov 21 '18 at 13:33











  • @nik They didn't but they do now and it works like a charm. You made my day sir!

    – Inyea
    Nov 21 '18 at 13:35











  • @RhaniEgghe Np....happy to help.

    – nik
    Nov 22 '18 at 8:30














-1












-1








-1









This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers




When running my code I keep getting this error in my logcat: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference



When debugging I get the following message:
EditText added is not a TextInputEditText. Please switch to using that class instead.



I have been searching for days but without luck. I am still learning to work with Android Studio so any help to resolve my problem would be appreciated!



My "GroupsFragment.java":



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 android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;

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);


/*
BindDictionary<Group> dictionary = new BindDictionary<>();

dictionary.addStringField(R.id.blabla, new StringExtractor<Group>() {
@Override
public String getStringValue(Group groupname, int position) {
return groupname.getName();
}
});

dictionary.addStringField(R.id.prepaidIcon, new StringExtractor<Group>() {
@Override
public String getStringValue(Group prepaid, int position) {
return "" + prepaid.isPrepaid();
}
});
FunDapter adapter = new FunDapter(GroupsFragment.this.getActivity(), groups, R.layout.groups_layout, dictionary);
*/

//getActivity() returns the Activity hosting the Fragment,
// while getView() returns the view you inflated and returned by onCreateView
//may cause nullpointer exception


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)
{
Group selectedProduct = groups.get(position);
Toast.makeText(GroupsFragment.this.getActivity(), selectedProduct.getName(), Toast.LENGTH_SHORT).show();

}
});

return RootView;

}


class CustomAdapter extends BaseAdapter {

int index;

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

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

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

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.blabla);
ImageView image = view.findViewById(R.id.member);
String t = groups.get(i).getName();
textView.setText(t);//nullpointer exception

return view;
}
}
}


My "groups_lay_out.xml":



<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/blabla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"

android:text="@string/textview"
android:textAppearance="?android:attr/textAppearanceLarge" />


<ImageView
android:id="@+id/member"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/blabla"
android:layout_marginStart="20dp"
android:src="@drawable/ic_member" />
</RelativeLayout>


My "fragment_groups.xml":



<?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:id="@+id/groupsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.GroupsFragment"
>


<TextView
android:id="@+id/groupName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"


android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="@string/groups"
android:textColor="#428EC4"
android:textSize="30sp"
android:textStyle="bold" />


<EditText
android:id="@+id/search_bar"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="20dp"
android:layout_marginTop="77dp"
android:layout_marginEnd="20dp"
android:background="@drawable/ic_bordersearch"
android:ems="10"
android:gravity="center"
android:hint="@string/search_text" />

<ImageButton
android:id="@+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignTop="@+id/search_bar"
android:layout_alignEnd="@+id/search_bar"
android:layout_alignBottom="@+id/search_bar"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_search_icon" />

<ImageButton
android:id="@+id/plusButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="298dp"
android:layout_marginEnd="25dp"
android:layout_marginBottom="55dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_plussign" />


<RelativeLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="386dp"
android:layout_below="@+id/search_bar"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="20dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="50dp"
android:orientation="vertical">

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

</RelativeLayout>


My logcat:



 Process: com.example.flow, PID: 16906
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.flow.displayClasses.GroupScreens.GroupsFragment$CustomAdapter.getView(GroupsFragment.java:237)
at android.widget.AbsListView.obtainView(AbsListView.java:2366)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillFromTop(ListView.java:847)
at android.widget.ListView.layoutChildren(ListView.java:1826)
at android.widget.AbsListView.onLayout(AbsListView.java:2165)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:142)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1556)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:888)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
2018-11-21 14:01:06.799 16906-16906/com.example.flow E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


My debugger:



11/21 14:02:22: Launching app
$ adb shell am start -n "com.example.flow/com.example.flow.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Connecting to com.example.flow
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.example.flow is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8620', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1399)
W/om.example.flo: JIT profile information will not be recorded: profile file does not exits.
I/chatty: uid=10085(com.example.flow) identical 10 lines
W/om.example.flo: JIT profile information will not be recorded: profile file does not exits.
I/InstantRun: starting instant run server: is main process
W/om.example.flo: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/om.example.flo: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
D/OpenGLRenderer: Skia GL Pipeline
D/: HostConnection::get() New Host Connection established 0xcb955e80, tid 17046
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xcb897b40: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@923b4b0
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)









share|improve this question















This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers




When running my code I keep getting this error in my logcat: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference



When debugging I get the following message:
EditText added is not a TextInputEditText. Please switch to using that class instead.



I have been searching for days but without luck. I am still learning to work with Android Studio so any help to resolve my problem would be appreciated!



My "GroupsFragment.java":



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 android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;

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);


/*
BindDictionary<Group> dictionary = new BindDictionary<>();

dictionary.addStringField(R.id.blabla, new StringExtractor<Group>() {
@Override
public String getStringValue(Group groupname, int position) {
return groupname.getName();
}
});

dictionary.addStringField(R.id.prepaidIcon, new StringExtractor<Group>() {
@Override
public String getStringValue(Group prepaid, int position) {
return "" + prepaid.isPrepaid();
}
});
FunDapter adapter = new FunDapter(GroupsFragment.this.getActivity(), groups, R.layout.groups_layout, dictionary);
*/

//getActivity() returns the Activity hosting the Fragment,
// while getView() returns the view you inflated and returned by onCreateView
//may cause nullpointer exception


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)
{
Group selectedProduct = groups.get(position);
Toast.makeText(GroupsFragment.this.getActivity(), selectedProduct.getName(), Toast.LENGTH_SHORT).show();

}
});

return RootView;

}


class CustomAdapter extends BaseAdapter {

int index;

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

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

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

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.blabla);
ImageView image = view.findViewById(R.id.member);
String t = groups.get(i).getName();
textView.setText(t);//nullpointer exception

return view;
}
}
}


My "groups_lay_out.xml":



<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/blabla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"

android:text="@string/textview"
android:textAppearance="?android:attr/textAppearanceLarge" />


<ImageView
android:id="@+id/member"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/blabla"
android:layout_marginStart="20dp"
android:src="@drawable/ic_member" />
</RelativeLayout>


My "fragment_groups.xml":



<?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:id="@+id/groupsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".displayClasses.GroupScreens.GroupsFragment"
>


<TextView
android:id="@+id/groupName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"


android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="@string/groups"
android:textColor="#428EC4"
android:textSize="30sp"
android:textStyle="bold" />


<EditText
android:id="@+id/search_bar"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="20dp"
android:layout_marginTop="77dp"
android:layout_marginEnd="20dp"
android:background="@drawable/ic_bordersearch"
android:ems="10"
android:gravity="center"
android:hint="@string/search_text" />

<ImageButton
android:id="@+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignTop="@+id/search_bar"
android:layout_alignEnd="@+id/search_bar"
android:layout_alignBottom="@+id/search_bar"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_search_icon" />

<ImageButton
android:id="@+id/plusButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="298dp"
android:layout_marginEnd="25dp"
android:layout_marginBottom="55dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_plussign" />


<RelativeLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="386dp"
android:layout_below="@+id/search_bar"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="20dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="50dp"
android:orientation="vertical">

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

</RelativeLayout>


My logcat:



 Process: com.example.flow, PID: 16906
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.flow.displayClasses.GroupScreens.GroupsFragment$CustomAdapter.getView(GroupsFragment.java:237)
at android.widget.AbsListView.obtainView(AbsListView.java:2366)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillFromTop(ListView.java:847)
at android.widget.ListView.layoutChildren(ListView.java:1826)
at android.widget.AbsListView.onLayout(AbsListView.java:2165)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:142)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1556)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:888)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1231)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
2018-11-21 14:01:06.799 16906-16906/com.example.flow E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


My debugger:



11/21 14:02:22: Launching app
$ adb shell am start -n "com.example.flow/com.example.flow.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Waiting for application to come online: com.example.flow | com.example.flow.test
Connecting to com.example.flow
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.example.flow is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8620', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1399)
W/om.example.flo: JIT profile information will not be recorded: profile file does not exits.
I/chatty: uid=10085(com.example.flow) identical 10 lines
W/om.example.flo: JIT profile information will not be recorded: profile file does not exits.
I/InstantRun: starting instant run server: is main process
W/om.example.flo: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/om.example.flo: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
D/OpenGLRenderer: Skia GL Pipeline
D/: HostConnection::get() New Host Connection established 0xcb955e80, tid 17046
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xcb897b40: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@923b4b0
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
D/EGL_emulation: eglMakeCurrent: 0xcb897b40: ver 3 0 (tinfo 0xde66cde0)




This question already has an answer here:




  • Null pointer Exception - findViewById()

    10 answers








java android






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 13:03









InyeaInyea

124




124




marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Try to change view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null); to view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, parent,false); . Also must be sure that your groups list must not be null. Also return position for getItem() and getItemId() method.

    – Piyush
    Nov 21 '18 at 13:10








  • 1





    Does R.layout.groups_prepaid_layout and R.layout.groups_layout both contains textview with id "@+id/blabla"?

    – nik
    Nov 21 '18 at 13:12













  • @Piyush placing parent between R.layout.groups_prepaid_latyout and false gives me a 'couldn't resolve symbol' error. I corrected the other suggestions that you made

    – Inyea
    Nov 21 '18 at 13:33











  • @nik They didn't but they do now and it works like a charm. You made my day sir!

    – Inyea
    Nov 21 '18 at 13:35











  • @RhaniEgghe Np....happy to help.

    – nik
    Nov 22 '18 at 8:30



















  • Try to change view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null); to view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, parent,false); . Also must be sure that your groups list must not be null. Also return position for getItem() and getItemId() method.

    – Piyush
    Nov 21 '18 at 13:10








  • 1





    Does R.layout.groups_prepaid_layout and R.layout.groups_layout both contains textview with id "@+id/blabla"?

    – nik
    Nov 21 '18 at 13:12













  • @Piyush placing parent between R.layout.groups_prepaid_latyout and false gives me a 'couldn't resolve symbol' error. I corrected the other suggestions that you made

    – Inyea
    Nov 21 '18 at 13:33











  • @nik They didn't but they do now and it works like a charm. You made my day sir!

    – Inyea
    Nov 21 '18 at 13:35











  • @RhaniEgghe Np....happy to help.

    – nik
    Nov 22 '18 at 8:30

















Try to change view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null); to view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, parent,false); . Also must be sure that your groups list must not be null. Also return position for getItem() and getItemId() method.

– Piyush
Nov 21 '18 at 13:10







Try to change view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, null); to view = getLayoutInflater().inflate(R.layout.groups_prepaid_layout, parent,false); . Also must be sure that your groups list must not be null. Also return position for getItem() and getItemId() method.

– Piyush
Nov 21 '18 at 13:10






1




1





Does R.layout.groups_prepaid_layout and R.layout.groups_layout both contains textview with id "@+id/blabla"?

– nik
Nov 21 '18 at 13:12







Does R.layout.groups_prepaid_layout and R.layout.groups_layout both contains textview with id "@+id/blabla"?

– nik
Nov 21 '18 at 13:12















@Piyush placing parent between R.layout.groups_prepaid_latyout and false gives me a 'couldn't resolve symbol' error. I corrected the other suggestions that you made

– Inyea
Nov 21 '18 at 13:33





@Piyush placing parent between R.layout.groups_prepaid_latyout and false gives me a 'couldn't resolve symbol' error. I corrected the other suggestions that you made

– Inyea
Nov 21 '18 at 13:33













@nik They didn't but they do now and it works like a charm. You made my day sir!

– Inyea
Nov 21 '18 at 13:35





@nik They didn't but they do now and it works like a charm. You made my day sir!

– Inyea
Nov 21 '18 at 13:35













@RhaniEgghe Np....happy to help.

– nik
Nov 22 '18 at 8:30





@RhaniEgghe Np....happy to help.

– nik
Nov 22 '18 at 8:30












1 Answer
1






active

oldest

votes


















0














You are getting that error because TextView wasn't initialised before you tried to set the text. Declare it outside the current block and initialise within onCreateView. Then you can set the text anywhere in your code.



For example,



    TextView textView; 

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





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You are getting that error because TextView wasn't initialised before you tried to set the text. Declare it outside the current block and initialise within onCreateView. Then you can set the text anywhere in your code.



    For example,



        TextView textView; 

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





    share|improve this answer




























      0














      You are getting that error because TextView wasn't initialised before you tried to set the text. Declare it outside the current block and initialise within onCreateView. Then you can set the text anywhere in your code.



      For example,



          TextView textView; 

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





      share|improve this answer


























        0












        0








        0







        You are getting that error because TextView wasn't initialised before you tried to set the text. Declare it outside the current block and initialise within onCreateView. Then you can set the text anywhere in your code.



        For example,



            TextView textView; 

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





        share|improve this answer













        You are getting that error because TextView wasn't initialised before you tried to set the text. Declare it outside the current block and initialise within onCreateView. Then you can set the text anywhere in your code.



        For example,



            TextView textView; 

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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 13:17









        inspiredMichaelinspiredMichael

        1246




        1246

















            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Can I use Tabulator js library in my java Spring + Thymeleaf project?