Skip to content Skip to sidebar Skip to footer

How To Save A Vector Object In Android?

I've been searching around a lot and couldn't accomplish this. I have created a class 'VectorEx', extending 'Vector', to store two methods, one for saving the vector and one for lo

Solution 1:

Maybe one of these permission is missing in your AndroidManifest:

<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.WRITE_INTERNAL_STORAGE" />

Solution 2:

I am pretty sure You're trying to write to the root directory. You probably want to be writing to your app's directory or External Storage(If any), not root.

Solution 3:

here are the vector constucts:
Vector( ) 
Vector(int size) 
Vector(int size, int incr) 
Vector(Collection c)

//Demonstrate various Vector operations. import java.util.*; 
classVectorDemo { 
    publicstaticvoidmain(String args[]) { 
        // initial size is 3, increment is 2 Vectorv=newVector(3, 2); 
        System.out.println("Initial size: " + v.size()); 
        System.out.println("Initial capacity: " + 
        v.capacity()); 

        v.addElement(newInteger(1)); 
        v.addElement(newInteger(2)); 
        v.addElement(newInteger(3)); 
        v.addElement(newInteger(4)); 
        System.out.println("Capacity after four additions: " + 

        v.capacity()); 
        v.addElement(newDouble(5.45)); 
        System.out.println("Current capacity: " + 
        v.capacity()); 

        v.addElement(newDouble(6.08)); 
        v.addElement(newInteger(7)); 
        System.out.println("Current capacity: " + 
        v.capacity()); 

        v.addElement(newFloat(9.4)); 
        v.addElement(newInteger(10)); 
        System.out.println("Current capacity: " + 
        v.capacity()); 

        v.addElement(newInteger(11)); 
        v.addElement(newInteger(12)); 
        System.out.println("First element: " + 
        (Integer)v.firstElement()); 
        System.out.println("Last element: " + 
        (Integer)v.lastElement()); 

        if(v.contains(newInteger(3))) 
            System.out.println("Vector contains 3."); 
            // enumerate the elements in the vector. EnumerationvEnum= v.elements(); 
            System.out.println("\\nElements in vector:"); 
            while(vEnum.hasMoreElements()) 
                System.out.print(vEnum.nextElement() + " "); 
                System.out.println(); 
            } 
        }
}



The output from this program is shown here:

Initial size: 0 
Initial capacity: 3 
Capacity after four additions: 5 
Current capacity: 5 
Current capacity: 7 
Current capacity: 9 
First element: 1 
Last element: 12 
Vector contains 3. 
Elements in vector: 
12345.456.0879.4101112

Post a Comment for "How To Save A Vector Object In Android?"