2014-12-25 5 views
1

데이터베이스 프로젝트에 6 개의 레코드가 있습니다. 각 레코드를 읽고 동적 배열로 전환 한 결과를 확인하는 루프입니다. 그러나 for 루프가 끝날 때까지 계속할 수 없습니다! 루프가 세 번째 레코드를 검사하기 위해!for() 루프가 지속되지 않습니다

int count = db.count_field("location", "id"); 

    geoAttrs = new ArrayList<StructureGeo>(); 
    StructureGeo geo = new StructureGeo(); 

    for (int i = 0; i < count; i++) { 
     geo.lat = db.get_lat("location", i); 
     geo.lang = db.get_log("location", i); 
     geo.result = gps2m(latitude, longitude, geo.lat, geo.lang); 
     geoAttrs.add(geo); 
     Log.i("LOG", "Array Index #" + i + " = " + geoAttrs.get(i)); 
    } 
    db.close(); 
    } 

편집 :

토스트 코드 뒤에 :

int count = db.count_field("location", "id"); 

및 결과 :

enter image description here

+0

총계 방법 .. –

+0

루핑하기 전에 카운트 크기를 확인하십시오. – Razgriz

+0

다시 확인하십시오 ... 토스트 코드 – Developer

답변

0

루프는 괜찮습니다. 루프가 시작되기 전에 count 변수를 제어하는 ​​라인을 삽입하십시오.

int count = db.count_field("location", "id"); 
    Log.d("LOG", "count equals " + count); 
geoAttrs = new ArrayList<StructureGeo>(); 
StructureGeo geo = new StructureGeo(); 

예상보다 적 으면 버그를 확인하십시오. 나는 당신의 문제는 아마도 db.count_field에있다 예상

int count = db.count_field("location", "id"); 

geoAttrs = new ArrayList<StructureGeo>(); 
StructureGeo geo = new StructureGeo(); 
int counter = 0; 
for (int i = 0; i < count; i++) { 
     counter++; 
if(counter == 3){ 
    geo.lat = db.get_lat("location", i); 
    geo.lang = db.get_log("location", i); 
    geo.result = gps2m(latitude, longitude, geo.lat, geo.lang); 
    geoAttrs.add(geo); 
    Log.i("LOG", "Array Index #" + i + " = " + geoAttrs.get(i)); 
    break; // ends loop 
    } 


} 
db.close(); 
} 
+0

다시 확인하십시오 ... 토스트 코드 – Developer

0

귀하의 질문을 바탕으로 당신은 루프 전체 6 대신 3 항목에 대한 확인하려면, 이것은 그래서 같은 INT 변수를 사용하여 수행 할 수 있습니다 , db.get_lat 또는 db.get_log 방법.

그래서 질문에 추가해주십시오.

+0

사진이 없습니다. 내 친구가 없습니다 ... 모든 레코드를 가져 와서 루프 내부의 모든 명령을 기록하고 싶습니다. 하지만 위의 코드는 세 개만 레코드 – Developer

+0

을 가져오고 있습니다. 코드가 좋을 수도 있습니다. 데이터베이스에 값이있는 레코드가 3 개만있을 수 있습니다. – Fihox

+0

: (데이터베이스 6 개 레코드, 첫 번째 게시물에 그림 표시 ... – Developer

0

:

관련 문제