i am working on an image gallery app in which i am loading images from URL so i have saved some image URLs in a text file and i am trying to read URLs from text file to ArrayList<String>
but i am not able to load images in my app.
i tried this: but not works images are not loading
package com.nostra13.example.universalimageloader;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public final class Constants {
public static List<String> LIST = new ArrayList<String>();
public void parseFile() {
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("link.txt"));
while ((sCurrentLine = br.readLine()) != null) {
LIST.add(sCurrentLine);
}
br.close();
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try {
if (br != null)br.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
public static final String[] IMAGES = LIST.toArray(new String[LIST.size()]);
private Constants() {
}
public static class Config {
public static final boolean DEVELOPER_MODE = false;
}
public static class Extra {
public static final String IMAGES = "com.nostra13.example.universalimageloader.IMAGES";
public static final String IMAGE_POSITION = "com.nostra13.example.universalimageloader.IMAGE_POSITION";
}
}
but if i add URLs manually like this: it works.
public static final String[] IMAGES = new String[] {
"https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q",
"https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q",
"https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q",
"https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTybItEfE2Xu-Or72BHw8uZf19_mV2Kr8cuuU8kKYrVbeZPXIeX-Q",
};
but i want to add text from text file (sdcard/file.txt) instead of manually adding.