Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
PLEASE HELP me understand how to to pass thses values properly .. m doing it for my final project..
Java
 class UserOverlay_Save{
   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
Posted
Updated 1-Dec-15 3:42am
v2
Comments
Richard MacCutchan 1-Dec-15 9:01am    
What are obj, and obj1 supposed to be instances of, and where do they get initialised? This code looks somewhat disconnected, much the same as your previous version of the same question.
Sānyà Sani 1-Dec-15 9:46am    
obj, and obj1 are instances of Useroverlay_save class, and i dont know why exactly they must b initialized.
yes the code is much similar because i was having errors in the log_cat but now there is no error apparently but still my values from one class to other activity are not being sent.. i clearly do not understand the logic to apply so please help me in this thanks
Richard MacCutchan 1-Dec-15 10:24am    
obj, and obj1 are instances of Useroverlay_save class, and i dont know why exactly they must b initialized.

Well you cannot expect anyone here to know. If you do not understand the logic of your own code, then I suggest you start again, or do some more studying.

You need to initialise all objects before you can use them. You also need to catch all exceptions and handle them. If you cannot understand these basics then you are going to continue to struggle.
Sānyà Sani 1-Dec-15 10:27am    
i do understand my code .. i just dnt understand the logic of how to pass the values in the other class..
Richard MacCutchan 1-Dec-15 10:34am    
Well you clearly do not understand, otherwise you would have solved this already. You create two instances of the Useroverlay_save class inside the Insert method of the DatabasHelper class but you never do anything with them, other than try to get values that you have never set. I think you need to go back to some Java tutorials to understand the use of constructors, getters and setters.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900