Android update sqlite table - android

I have written Update table using dbAdapter.
public void loadDownloadData() {
SoapPrimitive responsePrimitiveData;
//Loop Table list
for (int i = 0; i < tablesName.size(); i++) {
try {
responsePrimitiveData = soapPrimitiveData(tablesName.get(i));
if (responsePrimitiveData != null) {
try {
String result = responsePrimitiveData.toString();
JSONObject jsonobject = new JSONObject(result);
JSONArray array = jsonobject.getJSONArray("Table1");
int max = array.length();
// Loop each table data
for (int j = 0; j < max; j++) {
JSONObject obj = array.getJSONObject(j);
JSONArray names = obj.names();
StringBuilder strFields = new StringBuilder();
StringBuilder strValues = new StringBuilder();
String[] strToFields = new String[names.length()];
String[] strToFieldsVal = new String[names.length()];
//getting the Json name, values in separate string array
for (int k = 0; k < names.length(); k++) {
String name = names.getString(k);
strToFields[k] = names.getString(k);
String strVal;
if(obj.getString(name)== null){
strVal="";
strToFieldsVal[k]="";
}else{
if(obj.getString(name).equals(" ")){
strVal="";
strToFieldsVal[k]="";
}else{
String tmp1 = obj.getString(name).replaceAll("\\s+", " ");
String tmp = tmp1.replaceAll("\\s+", " ");
strVal =tmp.replaceAll("\\s+", " ");
strToFieldsVal[k]=strVal;
}
}
strFields.append(name + ",");
strValues.append(strVal+",");
} //end of json for loop
strFields.deleteCharAt(strFields.length() - 1);
strValues.deleteCharAt(strValues.length() - 1);
if(getTableUpdateType(tablesName.get(i)).equals("1")){
String actualtable = getAndroidTablename(tablesName.get(i));
if(isTableRecords(tablesName.get(i))){
String[] strWhereField = getTablePrimaryKey(tablesName.get(i),strBusinessUnit);
String[] strWhereFieldVal = new String[strWhereField.length];
StringBuilder whereFields = new StringBuilder();
for (int a = 0; a < strWhereField.length; a++) {
strWhereFieldVal[a] = obj.getString(strWhereField[a]);
whereFields.append(strWhereField[a] + "= ? and ");
}
whereFields.delete(whereFields.length() - 4, whereFields.length());
updateTableRecords(actualtable, strToFields, strToFieldsVal,whereFields.toString() ,strWhereFieldVal);
}else{
insertTableRecords(actualtable, strToFields, strToFieldsVal);
}
}else if(getTableUpdateType(tablesName.get(i)).equals("2")){
}else if(getTableUpdateType(tablesName.get(i)).equals("3")){
}else{
}
}//end of each table data
} catch (JSONException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
}
and I called like update method:
public void updateTableRecords(String strTableName, String[] strToFields, String[] strValues,String strWhereField ,String[] strWhereFieldVal){
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(DownlaodTableActivity.this);
dbAdapter.openDataBase();
ContentValues initialValues = new ContentValues();
for(int i=0 ;i<strToFields.length;i++){
initialValues.put(strToFields[i],strValues[i]);
}
long n = dbAdapter.updateRecordsInDB(strTableName, initialValues, strWhereField, strWhereFieldVal);
System.out.println( " -- n--- " + n);
Toast.makeText(DownlaodTableActivity.this, n+" rows updated", Toast.LENGTH_SHORT).show();
}
I want to generate update statement dynamic way. From These code I put Where part also.But I did not generate where clause.
see :
UPDATE strTableName SET ExecutiveCode=?, FreeIssuePrefix=?, DisPaySchedulePrefix=?, NextFreeIssueNo=?, NextReturnNo=?, UploadedType=?, DisNextFOCNo=?, DisNextFreeIssueNo=?
Please help me How to give the Where clase(Here I gave String & arguments as string array)
Thanks in advance...

try like this
dbAdapter.updateRecordsInDB(strTableName, initialValues,""+whereField+"='"+whereFieldValue+"'",null);
if your whereField field's type is number then don't use ''
If you have to compare with multiple values use
String where="";
for(int i=0;i<strWhereField.length();i++)
{
where=where+whereField[i]+"='"+strWhereFieldValue[i]+"'"
if(i<(strWhereField.length()-1)) where=where+" and"
}
dbAdapter.updateRecordsInDB(strTableName, initialValues,where,null);

Related

How to get String Array from JSON Object

I am trying to get a list of available numbers from the following json object
void doJSONParser(String str)
{
try {
JSONObject order = new JSONObject(str);
JSONArray index = order.getJSONArray("webnautes");
for(int i = 0; i < index.length(); i++)
{
JSONObject tt = index.getJSONObject(i);
name += "name: " + tt.getString("name")+"\n";
phone = new String[tt.getString("phone").length()];
//phone += "phone: " + tt.getString("phone")+"\n";
}
Log.d("JSON DATA:", name);
Log.d("JSON DATA:", phone.toString());
}
catch (JSONException e)
{
e.printStackTrace();
Log.d("JSON ERROR", e.getLocalizedMessage());
}
}
Try this
JSONArray phoneJson = tt.getJSONArray("phone");
String[] arr = new String[phoneJson.length()];
for(int i = 0; i < phoneJson.length(); i++)
arr[i] = phoneJson.getString(i);

Filter number from Array of string and get the index of last two greater number in android

I have a ArrayList that has value like [Value,Sum3,121,data8input,in:21::7,7.00,9.01] and I want to extract only number as the output should be like this [3,121,8,21,7,7.00,9.01] and then have to rearrange ascending and then get the index of last two number as result will be [21,121].
My tried code below,
for (int i = 0; i < arrayString.size(); i++) {
Pattern p = Pattern.compile("-?\\d+(,\\d+)*?\\.?\\d+?");
List<String> numbers = new ArrayList<String>();
Matcher m = p.matcher(arrayString.get(i).getvalue);
numbers.addAll(m);
for (int j = 0; j < numbers.size(); j++) {
Log.d("REMEMBERFILTER", allCollection.get(i).getTextValue());
}
}
}
do something like this, though it is not exactly memory efficient as I am using another list.
ArrayList<String> tempList = new ArrayList<>();
for (int i = 0; i < yourArrayList.size(); i++) {
tempList.add(yourArrayList.get(i).replaceAll("[^0-9]", ""));
}
//Arrange in ascending order
Collections.sort(tempList);
//Also try to remove those indexes which has only letters with
tempList.removeAll(Arrays.asList("", null));
for (int i = 0; i < tempList.size(); i++) {
Log.d("+++++++++", "" + tempList.get(i));
}
//You can get the last two or any element by get method of list by //list.size()-1 and list.size()-2 so on
This is a way to do it, finalArray has the 2 numbers you want:
String[] str = new String[] {"Value", "Sum3", "121", "data8input", "in:21::7", "7.00,9.01"};
StringBuilder longStringBuilder = new StringBuilder();
for (String s : str) {
longStringBuilder.append(s).append(" ");
}
String longString = longStringBuilder.toString();
String onlyNumbers = " " + longString.replaceAll("[^0-9.]", " ") + " ";
onlyNumbers = onlyNumbers.replaceAll(" \\. ", "").trim();
while (onlyNumbers.indexOf(" ") > 0) {
onlyNumbers = onlyNumbers.replaceAll(" ", " ");
}
String[] array = onlyNumbers.split(" ");
Double[] doubleArray = new Double[array.length];
for (int i = 0; i < array.length; i++) {
try {
doubleArray[i] = Double.parseDouble(array[i]);
} catch (NumberFormatException e) {
e.printStackTrace();
doubleArray[i] = 0.0;
}
}
Arrays.sort(doubleArray);
int numbersCount = doubleArray.length;
Double[] finalArray;
if (numbersCount >= 2) {
finalArray = new Double[]{doubleArray[numbersCount - 2], doubleArray[numbersCount - 1]};
} else if (numbersCount == 1) {
finalArray = new Double[]{ doubleArray[0]};
} else {
finalArray = new Double[]{};
}
for (Double number : finalArray) {
System.out.println(number);
}

Nested JSONArray Record Parsing Issue Android

I am making a App which receives a JSON Data From Server, User will select a value from Spinner like 0,1,2... and so on, On the Basis of number selection JSON will return a data from user defined index like 0,1.. i don't know how to parse a inner JSON Data in Android
json = new JSONObject(JSONParser.Result);
JSONArray jArray = json.getJSONArray("data");
StopElement _stop = new StopElement();
Log.d("JSON Algo Result", json.toString());
if (jArray!=null) {
for (int i = 0; i < jArray.length(); i++) {
jsonarray = jArray.getJSONArray(i);
if (jsonarray != null) {
for (int j = 0; j < jsonarray.length(); i++){
if(i==0) {
jsonarray = jArray.getJSONArray(j);
_stop.setName(jsonarray.getString(0));
StopElement.Stop_name_list.add(_stop.getName());
}
}
} else {
break;
}
}
} else {
return null;
}
**JSON Data**
[[["Sadiqabad Chowk","33.634525","73.074326","suzk1"],["Chungi No 8","33.627262","73.093567","suzk1"],["Jahaz Ground","33.628395","73.101936","suzk1"],["Khana Bridge","33.629967","73.112823","suzk1"],["Kuri Road","33.643162","73.102928","21"],["Faizabad","33.663212","73.084801","21"]],[["Sadiqabad Chowk","33.634525","73.074326","suzk1"],["Petrol Pump","33.634109","73.076363","suzk1"],["Chandni Chowk","33.631584","73.072563","suzk1"],["Rahmanabad","33.639065","73.075714","3"],["Passport Office","33.642410","73.076981","3"],["Shamsabad","33.650101","73.079994","3"],["Faizabad","33.663212","73.084801","3"]],[["Sadiqabad Chowk","33.634525","73.074326","suzk1"],["Chungi No 8","33.627262","73.093567","suzk1"],["Jahaz Ground","33.628395","73.101936","suzk1"],["Khana Bridge","33.629967","73.112823","suzk1"],["Zia Masjid","33.637196","73.107407","124-A"],["Kuri Road","33.643162","73.102928","124-A"],["Dhok Kala Khan","33.653118","73.095444","124-A"],["Faizabad","33.663212","73.084801","124-A"]],[["Sadiqabad Chowk","33.634525","73.074326","suzk1"],["Chungi No 8","33.627262","73.093567","suzk1"],["Jahaz Ground","33.628395","73.101936","suzk1"],["Khana Bridge","33.629967","73.112823","suzk1"],["Zia Masjid","33.637196","73.107407","136"],["Kuri Road","33.643162","73.102928","136"],["Iqbal Town","33.644279","73.100113","136"],["Dhok Kala Khan","33.653118","73.095444","136"],["Faizabad","33.663212","73.084801","136"]],[["Sadiqabad Chowk","33.634525","73.074326","suzk13"],["Dhok Ali Akbar","33.636997","73.092117","suzk13"],["Highway Stop","33.679722","73.075584","suzk13"],["Bhinder","33.556244","73.167946","suzk3"],["Lohi Bher","33.586273","73.145493","124"],["Wild Life Park","33.578770","73.132309","124"],["Airport Chowk","33.593803","73.139938","124"],["Gangal","33.612591","73.125801","124"],["Khana Bridge","33.629967","73.112823","124"],["Zia Masjid","33.637196","73.107407","124"],["Kuri Road","33.643162","73.102928","124"],["Dhok Kala Khan","33.653118","73.095444","124"],["Faizabad","33.663212","73.084801","124"]],[["Sadiqabad Chowk","33.634525","73.074326","suzk13"],["Petrol Pump","33.634109","73.076363","suzk13"],["Chandni Chowk","33.631584","73.072563","suzk13"],["Central Hospital","33.628784","73.070641","suzk13"],["Naz Cinema","33.623936","73.067802","suzk13"],["Waris Khan","33.620728","73.066078","suzk13"],["Comittee Chowk","33.612946","73.065193","suzk13"],["Liaquat Bagh","33.606808","73.064835","suzk13"],["Marir Hassan","33.596905","73.064445","suzk7"],["Punjab House","33.592701","73.065453","suzk7"],["Jhanda","33.588970","73.076195","suzk7"],["Raheemabad","33.599159","73.080048","21"],["Airport","33.603565","73.097137","21"],["Tajabad","33.601593","73.126213","21"],["Koral Chowk","33.605282","73.131279","21"],["Khana Bridge","33.629967","73.112823","21"],["Kuri Road","33.643162","73.102928","21"],["Faizabad","33.663212","73.084801","21"]],[["Sadiqabad Chowk","33.634525","73.074326","suzk13"],["Petrol Pump","33.634109","73.076363","suzk13"],["Chandni Chowk","33.631584","73.072563","suzk13"],["Central Hospital","33.628784","73.070641","suzk13"],["Naz Cinema","33.623936","73.067802","suzk13"],["Waris Khan","33.620728","73.066078","suzk13"],["Comittee Chowk","33.612946","73.065193","suzk13"],["Liaquat Bagh","33.606808","73.064835","suzk13"],["Medical College","33.602753","73.067200","29"],["Sir Syed Boys School","33.609600","73.078766","29"],["Fauji Tower","33.606770","73.084106","29"],["Chaklala Station","33.601013","73.095924","29"],["Raheemabad","33.599159","73.080048","29"],["Airport","33.603565","73.097137","21"],["Tajabad","33.601593","73.126213","21"],["Koral Chowk","33.605282","73.131279","21"],["Khana Bridge","33.629967","73.112823","21"],["Kuri Road","33.643162","73.102928","21"],["Faizabad","33.663212","73.084801","21"]],[["Sadiqabad Chowk","33.634525","73.074326","suzk13"],["Petrol Pump","33.634109","73.076363","suzk13"],["Chandni Chowk","33.631584","73.072563","suzk13"],["Central Hospital","33.628784","73.070641","suzk13"],["Naz Cinema","33.623936","73.067802","suzk13"]]]
this will work definitely for you.
String data= "[[['Jahaz Ground','33.628395','73.101936','suzk1'],['Khana Bridge','33.628395','73.101936','suzk1']]]";
try {
JSONArray json = new JSONArray(data);
JSONArray aray = (JSONArray)json.get(0);
for(int i =0; i< aray.length();i++){
JSONArray object = (JSONArray)aray.get(i);
String title = (String)object .get(0);
String lat = (String)object.get(1);
String lng = (String)object.get(2);
String com = (String)object.get(3);
}
} catch (JSONException e) {
e.printStackTrace();
}
try this way,
U can get result as per your request
private String jsonString="[[['Sadiqabad Chowk','33.634525','73.074326','suzk1'],['Chungi No 8','33.627262','73.093567','suzk1'],['Jahaz Ground','33.628395','73.101936','suzk1'],['Khana Bridge','33.629967','73.112823','suzk1'],['Kuri Road','33.643162','73.102928','21'],['Faizabad','33.663212','73.084801','21']],[['Sadiqabad Chowk','33.634525','73.074326','suzk1'],['Petrol Pump','33.634109','73.076363','suzk1'],['Chandni Chowk','33.631584','73.072563','suzk1'],['Rahmanabad','33.639065','73.075714','3'],['Passport Office','33.642410','73.076981','3'],['Shamsabad','33.650101','73.079994','3'],['Faizabad','33.663212','73.084801','3']],[['Sadiqabad Chowk','33.634525','73.074326','suzk1'],['Chungi No 8','33.627262','73.093567','suzk1'],['Jahaz Ground','33.628395','73.101936','suzk1'],['Khana Bridge','33.629967','73.112823','suzk1'],['Zia Masjid','33.637196','73.107407','124-A'],['Kuri Road','33.643162','73.102928','124-A'],['Dhok Kala Khan','33.653118','73.095444','124-A'],['Faizabad','33.663212','73.084801','124-A']],[['Sadiqabad Chowk','33.634525','73.074326','suzk1'],['Chungi No 8','33.627262','73.093567','suzk1'],['Jahaz Ground','33.628395','73.101936','suzk1'],['Khana Bridge','33.629967','73.112823','suzk1'],['Zia Masjid','33.637196','73.107407','136'],['Kuri Road','33.643162','73.102928','136'],['Iqbal Town','33.644279','73.100113','136'],['Dhok Kala Khan','33.653118','73.095444','136'],['Faizabad','33.663212','73.084801','136']],[['Sadiqabad Chowk','33.634525','73.074326','suzk13'],['Dhok Ali Akbar','33.636997','73.092117','suzk13'],['Highway Stop','33.679722','73.075584','suzk13'],['Bhinder','33.556244','73.167946','suzk3'],['Lohi Bher','33.586273','73.145493','124'],['Wild Life Park','33.578770','73.132309','124'],['Airport Chowk','33.593803','73.139938','124'],['Gangal','33.612591','73.125801','124'],['Khana Bridge','33.629967','73.112823','124'],['Zia Masjid','33.637196','73.107407','124'],['Kuri Road','33.643162','73.102928','124'],['Dhok Kala Khan','33.653118','73.095444','124'],['Faizabad','33.663212','73.084801','124']],[['Sadiqabad Chowk','33.634525','73.074326','suzk13'],['Petrol Pump','33.634109','73.076363','suzk13'],['Chandni Chowk','33.631584','73.072563','suzk13'],['Central Hospital','33.628784','73.070641','suzk13'],['Naz Cinema','33.623936','73.067802','suzk13'],['Waris Khan','33.620728','73.066078','suzk13'],['Comittee Chowk','33.612946','73.065193','suzk13'],['Liaquat Bagh','33.606808','73.064835','suzk13'],['Marir Hassan','33.596905','73.064445','suzk7'],['Punjab House','33.592701','73.065453','suzk7'],['Jhanda','33.588970','73.076195','suzk7'],['Raheemabad','33.599159','73.080048','21'],['Airport','33.603565','73.097137','21'],['Tajabad','33.601593','73.126213','21'],['Koral Chowk','33.605282','73.131279','21'],['Khana Bridge','33.629967','73.112823','21'],['Kuri Road','33.643162','73.102928','21'],['Faizabad','33.663212','73.084801','21']],[['Sadiqabad Chowk','33.634525','73.074326','suzk13'],['Petrol Pump','33.634109','73.076363','suzk13'],['Chandni Chowk','33.631584','73.072563','suzk13'],['Central Hospital','33.628784','73.070641','suzk13'],['Naz Cinema','33.623936','73.067802','suzk13'],['Waris Khan','33.620728','73.066078','suzk13'],['Comittee Chowk','33.612946','73.065193','suzk13'],['Liaquat Bagh','33.606808','73.064835','suzk13'],['Medical College','33.602753','73.067200','29'],['Sir Syed Boys School','33.609600','73.078766','29'],['Fauji Tower','33.606770','73.084106','29'],['Chaklala Station','33.601013','73.095924','29'],['Raheemabad','33.599159','73.080048','29'],['Airport','33.603565','73.097137','21'],['Tajabad','33.601593','73.126213','21'],['Koral Chowk','33.605282','73.131279','21'],['Khana Bridge','33.629967','73.112823','21'],['Kuri Road','33.643162','73.102928','21'],['Faizabad','33.663212','73.084801','21']],[['Sadiqabad Chowk','33.634525','73.074326','suzk13'],['Petrol Pump','33.634109','73.076363','suzk13'],['Chandni Chowk','33.631584','73.072563','suzk13'],['Central Hospital','33.628784','73.070641','suzk13'],['Naz Cinema','33.623936','73.067802','suzk13']]]";
private void getJSONResult(String jsonString) {
// TODO Auto-generated method stub
try {
JSONArray jsonArray = new JSONArray(jsonString);
// i.e. the JsonMainArray
JSONArray JsonInnerArray= (JSONArray)jsonArray.get(0);
// i.e. the JsonInnerArray
for(int i =0; i< JsonInnerArray.length();i++){
JSONArray jsonObject = (JSONArray)JsonInnerArray.get(i);
//i.e. the jsonObject of JsonInnerArray
String title = (String)jsonObject .get(0);
String latitude = (String)jsonObject.get(1);
String longitude = (String)jsonObject.get(2);
String companyName = (String)jsonObject.get(3);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
I Solved My Issue like this
try {
int count = 0;
if (success == 1) {
json = new JSONObject(JSONParser.Result);
jArray = json.getJSONArray("data");
StopElement _stop = new StopElement();
for (int i = 0; i < jArray.length(); i++) {
count = count + 1;
// Log.d("Counter", String.valueOf(count));
get_path.add(String.valueOf(count));
jsonarray = jArray.getJSONArray(i);
Log.d("path Array", jsonarray.toString());
if (getitemno>0) {
getpath = jArray.getJSONArray(getitemno);
for (int j = 0; j < getpath.length(); j++) {
getresult = getpath.getJSONArray(j);
_stop.setName(getresult.getString(0));
_map.setLat(getresult.getDouble(1));
_map.setLng(getresult.getDouble(2));
StopElement.Stop_name_list.add(_stop.getName());
MapCoordinatesElement.Lat.add(_map.getLat());
MapCoordinatesElement.Lng.add(_map.getLng());
//Log.d("Stop names", _stop.getName());
// Log.d("Index Array", getpath.toString());
}
} else {
getpath = jArray.getJSONArray(0);
for (int j = 0; j < getpath.length(); j++) {
getresult = getpath.getJSONArray(j);
_stop.setName(getresult.getString(0));
_map.setLat(getresult.getDouble(1));
_map.setLng(getresult.getDouble(2));
StopElement.Stop_name_list.add(_stop.getName());
MapCoordinatesElement.Lat.add(_map.getLat());
MapCoordinatesElement.Lng.add(_map.getLng());
//Log.d("Stop names", _stop.getName());
//Log.d("Index Array", getpath.toString());
}
}
}
// Log.d("Stop names of Algo", StopElement.Stop_name_list.toString());
// Log.d("Index Stop names", StopElement.Stop_name_list.toString());
} catch (JSONException e) {
e.printStackTrace();
}

How to sort/order JSON output?

I have a JSON loop and I am able to get objects in the loop, but the problem is my output is not in order:
My expected output is:
Menu Id 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
but I get results like:
Menu Id: 19,18,23,16,17,14,15,12,13,21,20,22,4,3,11,2,1.
How can I sort this the way I expect?
JSONArray values = menuObject.toJSONArray(names);
for (int i = 0; i< values.length(); i++) {
JSONObject json2 = (JSONObject) values.getJSONObject(i);
//int menu_id = json2.getInt("menu_id");
menu_id = json2.getString("menu_id");
int m_id = Integer.parseInt(menu_id);
if (json2.has("menu_parent")) {
menu_parent = json2.getString("menu_parent");
}
if (m_id < 0) {
//
} else {
id = id + menu_id + ",";
int menu_category = Integer.parseInt(menu_parent);
System.out.println("Menu Id" + id);
if (json2.has("menu_name")) {
menu_list = json2.getString(KEY_MENU).trim();
System.out.println("Menu List" +menu_title);
menu_title = menu_title + menu_list + ",";
}
}
}
I think you can get it sorted this way:
Collections.sort("your data", new Comparator<Item>() {
public int compare(Item i1, Item i2) {
return i1.getCaption().compareTo(i2.getCaption());
}
});
After this is done, it should be sorted out.
Try this:
String menuids = "19,18,23,16,17,14,15,12,13,21,20,22,4,3,11,2,1";
String[] ids = menuids.split(",");
Integer[] result = new Integer[ids.length];
for (int i = 0; i < ids.length; i++) {
result[i] = Integer.parseInt(ids[i].trim());
}
Collections.sort(Arrays.asList(result));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < result.length; i++) {
Integer intValue = result[i];
sb.append(intValue);
if (i < result.length - 1) {
sb.append(", ");
}
}
String finaldata = sb.toString();
System.out.println(finaldata);

Initialize the value of a arraylist

I can't understand what is wrong in my code . I am getting error in myAddressUniqueness. don't know why.Before i have tried it with string data type but got the same error. It is saying java.null exception.
ArrayList<String> myAddressUniqueness = null;
String name = "hello";
if (indexBody < 0 || !cursor.moveToFirst())
return;
smsList.clear();
do {
// int cursorPostion = cursor.getPosition();
String address;
String msgStr = cursor.getString(indexBody);
String senderNumber = cursor.getString(indexAddr);
Log.d("Name : ", senderNumber);
// String name = cursor.getString(cursor
// .getColumnIndex(PhoneLookup.DISPLAY_NAME));
// Log.d("Name : ",name);
if (name != null) {
address = name;
} else {
address = senderNumber;
}
Log.d("Address: ", address);
flag = 1;
//Log.e("Number: ", addressUniqueness.length + "");
for (j = 0; j < myAddressUniqueness.size(); j++) {
if (myAddressUniqueness.contains(address)) {
flag = 0;
break;
}
}
if (flag == 1) {
myAddressUniqueness.add(new String(address));
i++;
String str = "Sender: " + address + "\n";
smsList.add(str);
}
// TODO Auto-generated catch block
} while (cursor.moveToNext());
Change your declaration to
ArrayList<String> myAddressUniqueness = new ArrayList<String>();
You have it initialized to null. This will instantiate it then you can add data to it.
You should instantiate myAddressUniqueness by myAddressUniqueness = new ArrayList<String>() before using it.

Categories

Resources