Q: spinner1 cannot be resolved or is not a field I am not able to understand why i am getting an error here.The error is spinner1 cannot be resolved.Plz help me out fast.I am new to java and android development so explain accordingly.
This is my java code
package com.example.dailyexpenses;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;  
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.ImageView;
import android.widget.TextView;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
  import android.view.ViewGroup;

    public class GamesFragment extends Fragment {
    String[] Languages = { "Select a Language", "C# Language", "HTML Language",
        "XML Language", "PHP Language" };
        // Declaring the Integer Array with resourse Id's of Images for the Spinners
        Integer[] images = { 0, R.drawable.icon, R.drawable.petrol,
        R.drawable.books, R.drawable.recharge}; 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_games, container, false);

    Spinner mySpinner = (Spinner) findViewById(R.id.spinner1);


    return rootView;
}

 }

This is fragment_games.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"
android:orientation="vertical"
android:background="#ff8400" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="15dp"
    android:text="choose from the categories below"
    android:textAppearance="?android:attr/textAppearanceMedium" />

 <Spinner
  android:drawSelectorOnTop="true"
  android:id="@+id/spinner1"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:prompt="@string/select">
</Spinner>



 </RelativeLayout>


A: You need to call 
rootView.findViewById

since android does not yet to know where to search.
For more explanation: 
Probably (not to judge ofc) you are familiar to call findViewById in the method onCreate of an Activity, but before that you did call setContentView. After setting the content by setContentView android knows where to search for the id when you call findViewById. That is for the case when you are using activity. On the other hand, with fragments it is a different case. You won't be setting the content by setContentView, instead you have to prepare a view and return it on onCreateView and let the android set the content as it wishes. Be careful, on lines you are calling findViewById above there, you haven't return the view yet, so android does not know where to search as you call findViewById. So you have to make your searches not on not-set-yet-content, but on the rootView you are just about to return. So above the code is the solution to this well described problem.
