user2857301
user2857301

Reputation: 27

rootView cannot be resolved to a variable

Okay so i'm having an issue under: rootView in my code and the error it's causing: rootView cannot be resolved to a variable what could this mean? Do I have something wrong with my R. file? I'm using it within a fragment so could that be an issue as well?

The rest of the method:

public class FragmentC extends Fragment {

    private ListView myListView1;
    public String[] strListView; 


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

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


        myListView1 = (ListView) rootView.findViewById(R.id.listView1);

        strListView = getResources().getStringArray(R.array.my_data_list);

        return rootView; 

        ArrayAdapter<String> objAdapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_list_item_1, strListView);
        myListView1.setAdapter(objAdapter);
    }

}

I've only got an issue under both rootViews contained within this method, thanks guys.

Upvotes: 1

Views: 1517

Answers (1)

nem035
nem035

Reputation: 35491

First of all, you have a return statement in the beginning of your method and then again in the middle of your method which is just wrong. Return statement means that your method should finish and possibly return some sort of a value to its caller.

Please research a little bit what a return statement is.

Here is a good starting read

Secondly, you don't declare a variable called rootView anywhere but you are trying to use it. That is why the compiler gives you an error because rootView doesn't exist. Again, research how to create variables in Java.

Here is another good starting read

Upvotes: 1

Related Questions