lundi 2 mars 2015

loop functions doesn't work in the code


1) I'm trying to use for loop in some case in my code such a



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// get the file from asset Folder.
AssetManager assetManager = getAssets();
InputStream inputStream ;

try {

inputStream = assetManager.open("Data6sec.txt"); //open the file
int size = inputStream.available(); //the size of the string

/* Save the file & read it then close it as byte[] */
byte[] buffer = new byte[size];
inputStream.read(buffer);
inputStream.close();

String text = new String(buffer); //convert byte to string

**// delete the first 4 lines
text = text.replaceAll("(?ms).*?[\r\n]+(.*)", "$1");
text = text.replaceAll("(?ms).*?[\r\n]+(.*)", "$1");
text = text.replaceAll("(?ms).*?[\r\n]+(.*)", "$1");
text = text.replaceAll("(?ms).*?[\r\n]+(.*)", "$1");**

/* View the Array list. */
List<String> container = Arrays.asList(text.split(","));
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_expandable_list_item_1, container);
ListView valList = (ListView) findViewById(R.id.lv1);
valList.setAdapter(adapter);



} catch (IOException e1) {
e1.printStackTrace();
}
}


but when i run the app on the emulator the app stops + in the command



List<String> container = Arrays.asList(text.split(","));


text is not resolved.


why? and how i can solve this?


2) i want to read a specific elements from this array list List container = Arrays.asList(text.split(","));


how can I read it? (NOTE the list has 300 element and i want only to read every 3 elements starting from element 3)


i tried this but the app stops on the emulator:



List<String> container2 = Arrays.asList(text.split(","));
int j = 2
for(int i = 0; i <container.length; i++ ){

container2[i] = container[j];
j+=3;

}


can you help me??





Aucun commentaire:

Enregistrer un commentaire