title: attempt to invoke on a null object error
body: <p>I'm having this error: when I press a button it will go to an activity which has an array. Before adding the array it was fine. After adding the array the app crashes.</p>
  
  <pre><code>public class navigation_front extends AppCompatActivity {
      Button scan_btn;
      Spinner dest;
      EditText Edit_current;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(navigation_front);
          scan_btn = (Button) findViewById(R.id.scan_btn);
          final Activity activity = this;
          scan_btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  IntentIntegrator integrator = new IntentIntegrator(activity);
                  integrator.setDesiredBarcodeFormats(IntentIntegrator.PRODUCT_CODE_TYPES);
                  integrator.setPrompt("Scan");
                  integrator.setCameraId(0);
                  integrator.setBeepEnabled(false);
                  integrator.setBarcodeImageEnabled(false);
                  integrator.initiateScan();
  
              }
          });
          dest = (Spinner) findViewById(R.id.edit_destination);
          String edit_destination = dest.getSelectedItem().toString().trim();
          final ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.destination_array, R.layout.support_simple_spinner_dropdown_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          dest.setAdapter(adapter);
          dest.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  String type = parent.getItemAtPosition(position).toString();
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; parent) {
              }
          });
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
          if(result.getContents() != null){
              if(result.getContents() == null) {
                  Log.d("MainActivity", "Cancelled scan");
                  Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
              } else {
                  EditText editText =(EditText)findViewById(R.id.Edit_current);
                  editText.setText("" + result.getContents(), TextView.BufferType.EDITABLE);
              }
  
          }
  </code></pre>
  
  <p>Here is the error log:</p>
  
  <pre><code>FATAL EXCEPTION: main
                    Process: com.sp.ez_mart, PID: 15263
                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sp.ez_mart/com.sp.ez_mart.navigation_front}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2726)
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2787)
                        at android.app.ActivityThread.-wrap12(ActivityThread.java)
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1504)
                        at android.os.Handler.dispatchMessage(Handler.java:102)
                        at android.os.Looper.loop(Looper.java:154)
                        at android.app.ActivityThread.main(ActivityThread.java:6247)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
                     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
                        at com.sp.ez_mart.navigation_front.onCreate(navigation_front.java:54)
                        at android.app.Activity.performCreate(Activity.java:6754)
                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2787) 
                        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1504) 
                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                        at android.os.Looper.loop(Looper.java:154) 
                        at android.app.ActivityThread.main(ActivityThread.java:6247) 
                        at java.lang.reflect.Method.invoke(Native Method) 
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872) 
                        at 
  </code></pre>
  
  <p>com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) </p>