lundi 30 novembre 2015

Unable to pass image URI, Values are null for Insert function

i have a function which is taking image path from the gallery and set it in the text view so that i can send it to my other DB_class for insert function. but i am not able to send it As it seem to have problem with my setter or getter functions.. please have a look on the code and LogCat below its been days now and i have seen so many related problems but none of their solution worked.

   class imagePath{
   public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String realPath;
//FOR IMAGE PATH SAVING
        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
            String selectedImagePath;
            Uri selectedImageUri = data.getData();

//MEDIA GALLERY
            selectedImagePath = ImageFilePath.getPath(getApplicationContext(), selectedImageUri);
            Log.i("Image-->File Path-->", " " + selectedImagePath);
            setImgTextViews(Build.VERSION.SDK_INT, selectedImagePath);
            SET_saveImg(selectedImagePath);\\send it setter_metthod
        }
          else if(Build.VERSION.SDK_INT < 19)
            {
            realPath = this.getRealPathFromURI_FromAPI11_18(this, data.getData());
                setImgTextViews(Build.VERSION.SDK_INT, realPath);
            }
//----------->>>>>>>>>>>---------->>>>FOR VIDEO PATH SAVING------>>>>>>------------>>>>>>>>>>>-------->>>>>>>>>---------->>>>

        if (requestCode == RESULT_LOAD_VIDEO && resultCode == RESULT_OK && null != data)
        {
//FOR VIDEO PATH SAVING
            String selectedVidPath;
            Uri selectedVidUri = data.getData();

//VIDEO____PLAY___LIST
            selectedVidPath = ImageFilePath.getPath(getApplicationContext(), selectedVidUri);
            Log.i("VIDEO-->File Path-->", "" + selectedVidPath);
            setVIDTextViews(Build.VERSION.SDK_INT, selectedVidPath);
            SET_saveVid(selectedVidPath);\\ send it setter_metthod
        }
    }
//---->>------>>>------->>>>SETTERS--FOR IMAGE-->SET_saveImg(selectedImagePath)For&VIDEO-->>SET_saveVid(selectedVidPath)--->>AND--->>GETTERS FOR IMAGE AND VIDEO--------->>>>>

    String realPath; String vidPath;
    public String GET_saveImg()//IS CALLED FROM DATABASE_HELPER CLASS TO PROVIDE THE SETTER VALUES
    {
        return realPath;
    }

    public void SET_saveImg(String realPath)
    {
        this.realPath=realPath;

    }
    public String GET_saveVid()
    {
        return vidPath;
    }
    public void SET_saveVid(String vidPath)
    {
      this.vidPath= vidPath;
    }


}

class DatabasHelper extends SqliteOpenHelper{
SQLiteDatabase db;    User_overlay_save obj = new User_overlay_save();
                          User_overlay_save obj1 = new User_overlay_save() ;



    // Database Name
    public static String DATABASE_NAME = "MY_database";

    // Current version of database
    private static final int DATABASE_VERSION = 1;

    // Name of table
    private static final String TABLE_Images = "images";

    // All Keys used in table
     static final String KEY_ID = "id";
     static final String KEY_IMAGE = "image";
     static final String KEY_FILE = "file";


    public static String TAG = "tag";

    private static final String CREATE_TABLE_Images = "CREATE TABLE "
            + TABLE_Images + "(" + KEY_ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_IMAGE + " TEXT," + KEY_FILE + " TEXT" +");";

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    /*This method is called by system if the database is accessed but not yet created*/

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(CREATE_TABLE_Images); // create Image table

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + CREATE_TABLE_Images); // drop table if exists

        onCreate(db);
    }

public boolean Insert() throws SQLException {
    //boolean success = false;

    String imgpath = obj.GET_saveImg();
    String vidPath = obj1.GET_saveVid();
    Log.i("IMAGE-->Path from DB-->", "" + imgpath);\\ i added these lines so i would know if my values are being transferred from one activity to another 
    Log.i("VIDEO-->File Path-->", "" + vidPath);

    db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_IMAGE, imgpath);
    values.put(KEY_FILE, vidPath);

    db.insert(TABLE_Images, null, values);
   // success=true;
    db.close();
    return true;}}

---------------------------LOG--CAT------------------------------------------

11-30 20:42:01.687 26765-26765/com.example.sanya.ar_expeditor W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
11-30 20:42:05.549 26765-26765/com.example.sanya.ar_expeditor I/Image-->File Path-->:  /storage/sdcard1/Download/aries.png
11-30 20:42:05.601 26765-26765/com.example.sanya.ar_expeditor I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@94939d4 time:24961584
11-30 20:42:07.939 26765-26765/com.example.sanya.ar_expeditor W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
11-30 20:42:10.645 26765-26765/com.example.sanya.ar_expeditor I/VIDEO-->File Path-->: /storage/sdcard1/DCIM/100ANDRO/MOV_1035.mp4
11-30 20:42:10.702 26765-26765/com.example.sanya.ar_expeditor I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@94939d4 time:24966685
11-30 20:42:11.713 26765-26765/com.example.sanya.ar_expeditor I/IMAGE-->Path from DB-->: null
11-30 20:42:11.713 26765-26765/com.example.sanya.ar_expeditor I/VIDEO-->File Path-->: null
11-30 20:42:14.799 26765-26765/com.example.sanya.ar_expeditor W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection

Aucun commentaire:

Enregistrer un commentaire