-1

enter image description here public class GroupFragment extends Fragment {

private View groupFragmentView;
private ListView list_View;

here i have created instances as well

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        // Inflate the layout for this fragment
        groupFragmentView =  inflater.inflate(R.layout.fragment_group, container, false);
        InitializeFields();      
return groupFragmentView;
    }

`

private void InitializeFields()
{

    list_View =  (ListView) groupFragmentView.findViewById(android.R.id.**list_View**);

}}

1 now here im getting error for listView

2 on the left side of equals im having no issue even for the casting there is no error

3 i have tried everything but still couldnt resolve it

4 im still learning android

error showing is-----

error: cannot find symbol list_View = (ListView) groupFragmentView.findViewById(android.R.id.list_View); ^ symbol: variable list_View location: class id

`

<?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=".GroupFragment">

<ListView

    android:layout_width="match_parent"
    android:layout_height="match_parent" />

`

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    Try removed **andorid** from the code `list_View = (ListView) groupFragmentView.findViewById(android.R.id.list_View);`. If ListView is defined by you in the layout, then it is **R.id.list_View**. If that doesn't fix your problem, then post your layout, **fragment_group.xml**. – i_A_mok Nov 20 '20 at 10:17
  • i have added xml part as well – sourav kadam Nov 20 '20 at 10:34
  • 1
    Give id to ListView, so add `android:id="@+id/list_View"` inside ListView tag. – i_A_mok Nov 20 '20 at 10:57
  • Does this answer your question? [What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-or-cannot-resolve-symbol-error-mean) – Mark Rotteveel Feb 14 '21 at 11:20

1 Answers1

1

You have to pass the object of view in your method.

@Override public View onCreateView(LayoutInflater inflater, 
      ViewGroup container, Bundle savedInstanceState) { 
    // Inflate the layout for this fragment
    groupFragmentView=inflater.inflate(R.layout.fragment_group,container,false); 
    InitializeFields(groupFragmentView);
    return groupFragmentView;
}

private void InitializeFields(View view)
{
    list_View =  (ListView) view.findViewById(android.R.id.**list_View**);}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Rajshekhar
  • 571
  • 5
  • 9