title: Android errors when getting battery info (in a Fragment)
body: <p>My app has several action bar tabs, this is one of the fragments.It is supposed to display some information about the battery. The errors appear after navigating the app for a bit.Please explain what caused the problem and what should be done to solve it </p>
  
  <p>Here are the errors from the LogCat :</p>
  
  <pre><code>05-15 07:24:30.809: E/AndroidRuntime(25883): FATAL EXCEPTION: main
  05-15 07:24:30.809: E/AndroidRuntime(25883): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.BATTERY_CHANGED flg=0x60000010 (has extras) } in com.example.mytaskmanager.Battery$1@4185ea78
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:755)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at android.os.Handler.handleCallback(Handler.java:605)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at android.os.Handler.dispatchMessage(Handler.java:92)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at android.os.Looper.loop(Looper.java:154)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at android.app.ActivityThread.main(ActivityThread.java:4624)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at java.lang.reflect.Method.invoke(Method.java:511)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at dalvik.system.NativeStart.main(Native Method)
  05-15 07:24:30.809: E/AndroidRuntime(25883): Caused by: java.lang.NullPointerException
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at com.example.mytaskmanager.Battery.setare(Battery.java:77)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at com.example.mytaskmanager.Battery$1.onReceive(Battery.java:120)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:746)
  05-15 07:24:30.809: E/AndroidRuntime(25883):     ... 9 more
  </code></pre>
  
  <p>and the code : </p>
  
  <pre><code>public class Battery extends Fragment {
      private TextView batteryInfo, memoryInfo, procent;
      int  health = 0, level=0, plugged=0, scale=0, status=0, temperature=0, voltage=0;
      String  technology = "";
      boolean present = false;
      ProgressBar pb;
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View myFragmentView = inflater.inflate(R.layout.layout, container, false);
          return myFragmentView;
      }
  
      @Override
      public void onResume() {
          super.onResume();
          procent=(TextView)getActivity().findViewById(R.id.BatteryProc);
          batteryInfo=(TextView)getActivity().findViewById(R.id.textViewBatteryInfo);
          pb = (ProgressBar)getActivity().findViewById(R.id.progressbar);
          memoryInfo = (TextView)getActivity().findViewById(R.id.memory);
          setare();
          getMemInfo();
  
      }
  
  
  
      public void setare(){
  
          procent.setText("Level: " + level + "%");
          pb.setProgress(level);
          batteryInfo.setText(
                  "Health: "+health+"\n"+
                  "Plugged: "+plugged+"\n"+
                  "Present: "+present+"\n"+
                  "Scale: "+scale+"\n"+
                  "Status: "+status+"\n"+
                  "Technology: "+technology+"\n"+
                  "Temperature: "+temperature+"\n"+
                  "Voltage: "+voltage+"\n");
  
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          getActivity().registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
       }
  
      private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
  
              health= intent.getIntExtra(BatteryManager.EXTRA_HEALTH,0);
              level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
              plugged= intent.getIntExtra(BatteryManager.EXTRA_PLUGGED,0);
              present= intent.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
              scale= intent.getIntExtra(BatteryManager.EXTRA_SCALE,0);
              status= intent.getIntExtra(BatteryManager.EXTRA_STATUS,0);
              technology= intent.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
              temperature= intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0);
              voltage= intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE,0);
  
              batteryInfo=(TextView)getActivity().findViewById(R.id.textViewBatteryInfo);
              pb = (ProgressBar)getActivity().findViewById(R.id.progressbar);
              memoryInfo = (TextView)getActivity().findViewById(R.id.memory);
              procent=(TextView)getActivity().findViewById(R.id.BatteryProc);
  
              setare();        
              getMemInfo();
  
          }
      };
  </code></pre>