title: ProgressBar in fragment
body: <p>I have <code>+</code> and <code>-</code> buttons in fragment and by pressing them i need to change the progress of <code>ProgressBar</code>, but instead i get NullPointException</p>
  
  <p>In MainActivity:</p>
  
  <pre><code>public void selectVentilatorFunction(View view) {
  
      prg = (ProgressBar)view.findViewById(R.id.ventilator_progress);
      int pressedbutton = view.getId();
  
      switch (pressedbutton){
       case R.id.increase:
           if(int_ventilator &lt; 100) int_ventilator = int_ventilator + 10;
           break;
       case R.id.decrease:
           if(int_ventilator &gt; 0) int_ventilator = int_ventilator - 10;
           break;
      }
      prg.setProgress(int_ventilator);
      Log.d(TAG,"Ventilator progresas " + int_ventilator);
  }
  </code></pre>
  
  <p>Fragment.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/black" &gt;
  
  
  &lt;RelativeLayout
          android:id="@+id/buttonview"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_marginBottom="45dp"
          android:layout_marginLeft="45dp"
          android:layout_marginRight="45dp"&gt;
  
        &lt;ProgressBar
              android:id="@+id/ventilator_progress"
              style="?android:attr/progressBarStyleHorizontal"
              android:layout_width="match_parent"
              android:layout_height="100dp" 
              android:layout_marginTop="200dp"
              android:layout_alignParentTop="true"
              android:progress="50"/&gt;
  
          &lt;Button
              android:id="@+id/decrease"
              android:layout_width="250dp"
              android:layout_height="160dp"
              android:layout_marginBottom="625dp"
              android:background="@android:color/transparent"
              android:layout_alignParentBottom="true"
              android:layout_alignParentLeft="true"
              android:onClick="selectVentilatorFunction" /&gt;
  
          &lt;Button
              android:id="@+id/increase"
              android:layout_width="250dp"
              android:layout_height="160dp"
              android:layout_marginBottom="625dp"
              android:background="@android:color/transparent"
              android:layout_alignParentBottom="true"
              android:layout_alignParentRight="true"
              android:onClick="selectVentilatorFunction" /&gt;          
  
          &lt;/RelativeLayout&gt;
  
          &lt;ImageView        
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:contentDescription="@string/background"
              android:background="@drawable/bg2"
              android:scaleType="fitXY" /&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>LogCat if needed </p>
  
  <pre><code>11-10 13:53:52.870: E/AndroidRuntime(16452): FATAL EXCEPTION: main
  11-10 13:53:52.870: E/AndroidRuntime(16452): Process: com.example.leftpanelmenutest, PID: 16452
  11-10 13:53:52.870: E/AndroidRuntime(16452): java.lang.IllegalStateException: Could not execute method of the activity
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at android.view.View$1.onClick(View.java:3814)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at android.view.View.performClick(View.java:4424)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at android.view.View$PerformClick.run(View.java:18383)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at android.os.Handler.handleCallback(Handler.java:733)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at android.os.Handler.dispatchMessage(Handler.java:95)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at android.os.Looper.loop(Looper.java:137)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at android.app.ActivityThread.main(ActivityThread.java:4998)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at java.lang.reflect.Method.invokeNative(Native Method)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at java.lang.reflect.Method.invoke(Method.java:515)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:811)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:627)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at dalvik.system.NativeStart.main(Native Method)
  11-10 13:53:52.870: E/AndroidRuntime(16452): Caused by: java.lang.reflect.InvocationTargetException
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at java.lang.reflect.Method.invokeNative(Native Method)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at java.lang.reflect.Method.invoke(Method.java:515)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at android.view.View$1.onClick(View.java:3809)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    ... 11 more
  11-10 13:53:52.870: E/AndroidRuntime(16452): Caused by: java.lang.NullPointerException
  11-10 13:53:52.870: E/AndroidRuntime(16452):    at com.example.leftpanelmenutest.MainActivity.selectVentilatorFunction(MainActivity.java:76)
  11-10 13:53:52.870: E/AndroidRuntime(16452):    ... 14 more
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Full code, there isn't much in it. In MainActivity i have 4 buttons and select the fragment.</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      final protected static String TAG = "MainActivity";
  
      Fragment fr;
      FragmentManager fm;
      FragmentTransaction fragmentTransaction;
      boolean firsttime;
      byte[] myData = {10,20};
      public ProgressBar prg;
      int int_ventilator = 0, int_light = 0;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          getWindow().getDecorView().setSystemUiVisibility(
                  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE);
          if(fr==null){
          fr =  new StartMenu();
          fm = getFragmentManager();
          fragmentTransaction = fm.beginTransaction();
          fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
          fragmentTransaction.add(R.id.fragment_place, fr);
          fragmentTransaction.commit();
  
          }
  
  }
  
      public byte[] getMyData() {
          return myData;
      }
      public int getInt() {
          return int_ventilator;
      }
  
      public void selectMainFunction(View view) {
  
      }
  
      public void selectVentilatorFunction(View view) {
          int pressedbutton = view.getId();   
          prg = (ProgressBar)view.findViewById(R.id.ventilator_progress); 
          switch (pressedbutton){
           case R.id.increase:
               if(int_ventilator &lt; 100) int_ventilator = int_ventilator + 10;
               break;
           case R.id.decrease:
               if(int_ventilator &gt; 0) int_ventilator = int_ventilator - 10;
               break;
          }
          prg.setProgress(int_ventilator);
          Log.d(TAG,"Ventilator progresas " + int_ventilator);
      }
  
      public void selectIndoorLightFunction(View view) {
          int pressedbutton = view.getId();
          switch (pressedbutton){
           case R.id.increase:
               if(int_light &lt; 100) int_light = int_light + 10;
               break;
           case R.id.decrease:
               if(int_light &gt; 0) int_light = int_light - 10;
               break;
          }
          Log.d(TAG,"Light progresas " + int_light);
      }
  
  public void selectOutdoorFunction(View view) {
  
      }
  
      public void selectMenu(View view) {
           int pressedbutton = view.getId();
  
  
           switch (pressedbutton){
           case R.id.startmenu:
               fr = new StartMenu();
               break;
          case R.id.ventilatormenu:
              fr = new VentilatorMenu();   
               break;
          case R.id.indoormenu:
              fr = new IndoorLightMenu();
               break;
          case R.id.outdoormenu:
              fr = new OutdoorLight();
               break;
           }
           fm = getFragmentManager();
           fragmentTransaction = fm.beginTransaction();
           fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
           fragmentTransaction.replace(R.id.fragment_place, fr);
           fragmentTransaction.commit();
  
      }
  }
  </code></pre>
  
  <p>VentilatorFragment</p>
  
  <pre><code>public class VentilatorMenu extends Fragment{
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Log.e("Test", "VENTILATOR");
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          MainActivity activity = (MainActivity) getActivity();
          View view = inflater.inflate(R.layout.bg2layout, container, false);
          return view;
      }
  
  }
  </code></pre>