I trying to Make One App in which I will be Using CSV to restore to Sqlite Database . This Code is working Fine on Android Emulator But Not Working On Device. Please Help I am stuck very badly from last 3 days I am unable to figured out and tried many solution from Google but none of them are working.
public class MainActivity extends ListActivity {
TextView lbl;
DBController controller;
Button btnimport;
ListView lv;
final Context context = this;
ListAdapter adapter;
ArrayList<HashMap<String, String>> myList;
public static final int requestcode = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    controller = new DBController(this);
    lbl = (TextView) findViewById(R.id.txtresulttext);
    btnimport = (Button) findViewById(R.id.btnupload);
    lv = getListView();
    btnimport.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent fileintent = new Intent(Intent.ACTION_GET_CONTENT);
            fileintent.addCategory(Intent.CATEGORY_OPENABLE);
            fileintent.setType("text/csv");
            try {
                startActivityForResult(Intent.createChooser(fileintent,"Open CSv"),requestcode);
            } catch (ActivityNotFoundException e) {
                lbl.setText("No activity can handle picking a file. Showing alternatives.");
            }
        }
    });
    myList = controller.getAllProducts();
    if (myList.size() != 0) {
        ListView lv = getListView();
        ListAdapter adapter = new SimpleAdapter(MainActivity.this, myList,
                R.layout.v, new String[]{"a", "b", "c"}, new int[]{
                R.id.txtproductcompany, R.id.txtproductname, R.id.txtproductprice});
        setListAdapter(adapter);
        lbl.setText("");
    }
        }
/** you were wrong here
 * R.id.txtjournalname, R.id.txtjournalissn, R.id.txtjournalif});
 in v.xml its
 R.id.txtproductcompany, R.id.txtproductname, R.id.txtproductprice});
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data == null)
    return;
           switch (requestCode) {
        case requestcode:
            String filepath = data.getData().getPath();
            controller = new DBController(getApplicationContext());
            SQLiteDatabase db = controller.getWritableDatabase();
            String tableName = "tbljournal";
            db.execSQL("delete from " + tableName);
            try {
                if (resultCode == RESULT_OK) {
                    try {
                        FileReader file = new FileReader(filepath);
                        BufferedReader buffer = new BufferedReader(file);
                        ContentValues contentValues = new ContentValues();
                        String line = "";
                        db.beginTransaction();
                        buffer.readLine();
                        while ((line = buffer.readLine()) != null) {
                            String[] str = line.split(",", 4);  // defining 3 columns with null or blank field //values acceptance
                            //Id, Company,Name,Price
                            String spinnerdata = str[0].toString();
                            String uniqueid = str[1].toString();
                            String melting = str[2].toString();
                            String weight = str[3].toString();
                            Log.e("data", spinnerdata);
                            contentValues.put("spinnerdata", spinnerdata);
                            contentValues.put("uniqueid", uniqueid);
                            contentValues.put("melting", melting);
                            contentValues.put("weight", weight);
                            db.insert(tableName, null, contentValues);
                            lbl.setText("Successfully Updated Database.");
                        }
                        db.setTransactionSuccessful();
                        db.endTransaction();
                    }catch (SQLException e)
                    {
                        Log.e("Error",e.getMessage().toString());
                    }
                    catch (IOException e) {
                        if (db.inTransaction())
                        db.endTransaction();
                        Dialog d = new Dialog(this);
                        d.setTitle(e.getMessage().toString() + "first");
                        d.show();
                        // db.endTransaction();
                    }
                } else {
                    if (db.inTransaction())
                    db.endTransaction();
                    Dialog d = new Dialog(this);
                    d.setTitle("Only CSV files allowed");
                    d.show();
                                        }
                              } catch (Exception ex) {
                if (db.inTransaction())
                db.endTransaction();
                Dialog d = new Dialog(this);
                d.setTitle(ex.getMessage().toString() + "second");
                d.show();
                // db.endTransaction();
            }
    }
    myList = controller.getAllProducts();
    if (myList.size() != 0) {
        ListView lv = getListView();
        ListAdapter adapter = new SimpleAdapter(MainActivity.this, myList,
                R.layout.v, new String[]{"a", "b", "c"}, new int[]{
                R.id.txtproductcompany, R.id.txtproductname, R.id.txtproductprice});
        setListAdapter(adapter);
        lbl.setText("Data Imported");
    }
}
}
Below are LogCat
03-15 16:54:27.577 2559-2611/? E/AbstractTracker: Can't create handler inside thread that has not called Looper.prepare() 03-15 16:54:36.185 2559-2620/com.example.arnav.androidcsv.demo E/AbstractTracker: Can't create handler inside thread that has not called Looper.prepare() 03-15 16:54:46.556 2559-2763/com.example.arnav.androidcsv.demo E/AbstractTracker: Can't create handler inside thread that has not called Looper.prepare()
Once I select CSV file from file Manager Nothing Happening it get Stuck .
 
    