0

I want to pass values to the add-temple class using for loop.

My add temple function:

 // Adding new temple
 public void Add_Temple(kovil Kovil) {
 SQLiteDatabase db = this.getWritableDatabase();
 ContentValues values = new ContentValues();

values.put(KEY_TMPNAME, Kovil.gettemplename()); 
values.put(KEY_TMPTYPE, Kovil.gettempletype()); 
values.put(KEY_LATITUDE, Kovil.getlatitude()); 
values.put(KEY_LONGITUDE, Kovil.getlongitude()); 
values.put(KEY_IMGNAME, Kovil.getimage_name()); 
values.put(KEY_YEARBUILD, Kovil.getyear_build()); 
values.put(KEY_ADDRESS, Kovil.getaddress()); 
values.put(KEY_CITY, Kovil.getcity()); 
values.put(KEY_EMAIL, Kovil.getemail()); 
values.put(KEY_WEB, Kovil.getwebsite()); 
values.put(KEY_TEL1, Kovil.gettelephone1()); 
values.put(KEY_TEL2, Kovil.gettelephone2());
values.put(KEY_DESCRI, Kovil.getDescription());

// Inserting Row
db.insert(TABLE_TEMPLE, null, values);
db.close(); // Closing database connection
}

My for loop to send values to the Add temple function:

        kovil insertData1 = new kovil("temple_name", "temple_type", "latitude",  "longitude", "image_name", "year_build", "address", "city", "email", "website", "telephone1", "telephone2",  "Description");
       // dbhand .Add_Temple(insertData1 );

        kovil insertData2 = new kovil("temple_name2", "temple_type2", "latitude2",  "longitude2", "image_name2", "year_build2", "address2", "city2", "email2", "website2", "telephone12", "telephone22",  "Description2");
      //  dbhand .Add_Temple(insertData2 );

        for(int i=0;i<2; i++){

            dbhand .Add_Temple("insertData"+i);

        }

I get a syntax error in the for loop. Can some one help me to write this for loop please.

error message

Multiple markers at this line
- insertData cannot be resolved to a variable
- The method Add_Temple(kovil) in the type Dbhandler is not applicable for the arguments 
 (String)
3
  • Do you not think that adding the error message would help people to help you? Commented Feb 11, 2014 at 8:17
  • please post the error message Commented Feb 11, 2014 at 8:19
  • the error message is that dbhand .Add_Temple() accepts arguments of type kovil not of type string... Commented Feb 11, 2014 at 8:20

2 Answers 2

3

Your Add_Temple function argument is of type "kovil", you are passing String type instead.

You should put your "kovil" objects to ArrayList, for example, and then iterate through it like so:

ArrayList<kovil> arrayList = new ArrayList<>();
arrayList.add(insertData1);
arrayList.add(insertData2);
for (int i=0; i<arrayList.size(); i++){
    dbhand.Add_Temple(arrayList.get(i));
};
Sign up to request clarification or add additional context in comments.

1 Comment

yes, i can simply pass it one by one dbhand .Add_Temple(insertData1); like this. but i want to do it in a for loop.
1

You should be doing something like this

Kovil insertData1 = new Kovil("temple_name", "temple_type", "latitude",  "longitude", "image_name", "year_build", "address", "city", "email", "website", "telephone1", "telephone2",  "Description");


Kovil insertData2 = new Kovil("temple_name2", "temple_type2", "latitude2",  "longitude2", "image_name2", "year_build2", "address2", "city2", "email2", "website2", "telephone12", "telephone22",  "Description2");

Kovil[] array = new Kovil[]{insertData1, insertData2};

for(Kovil k : array) {
   dbhand .addTemple(k);
}

On a side note:

Please fix the keyword,function naming, follow Java naming conventions

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.