this code raise run time exception
<p><strong>This code is to get account from mobile in application</strong></p>

<pre><code>package com.example.lenovo.email;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.Patterns;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;

import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity {
    private static String[] userEmailId = null;
    private static String mDeviceId = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Spinner dropdown = (Spinner)findViewById(R.id.spinner);

        String[] email_a=null;
        email_a=setUserEmailId(this);
        if(email_a == null)
        {
            throw new RuntimeException("null");
        }
        else {
            ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, email_a);
            dropdown.setAdapter(adapter);
            EditText edit = (EditText) findViewById(R.id.editText2);
            // edit.setText(setUserEmailId(this));
        }

    }
  //used to get accounts in dropdown list
    private static String[] setUserEmailId(Context mContext) {
        Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
        Account[] accounts = AccountManager.get(mContext).getAccounts();
int i=0;
        for (Account account : accounts) {
            if (emailPattern.matcher(account.name).matches()) {
                userEmailId[i] = account.name;
                Log.d("Email",userEmailId[i]);
                i++;
            }
        }

        return  userEmailId;
    }

}
</code></pre>

<p>Code gives run time exception.<br>
When I run this code unfortunately application has been stopped.<br>
I can't resolve this exception .....</p>