앱 스토어에서 현재 앱을 사용할 수 있지만 완전히 이해할 수없는 오류 보고서 유형이 있습니다. 내 애플 내부 SQLite 데이터베이스를 사용하지만, 일부 장치 (확실히 대다수는) 다음과 같은 오류가 가끔 발생 :"android.database.sqlite.SQLiteException : 드문 경우의 오류"
android.database.sqlite.SQLiteException : 이러한 테이블을 : image_data (코드 1) : 컴파일하는 동안 : 카테고리 = '천문학'AND 스탬프> = 1,357,426,800과 합체 (title_nl, '') = ''
내가이 테이블이 존재하고 난 확신 image_data로부터 최소 (스탬프)을 선택 이 쿼리가 올바른지 확인하십시오. 나는이 오류가 앱의 위젯에서만 발생하고 AlarmManager에 의해 방송 된 BroadcastReceiver에서 발생한다는 것을 알고있다. (앱은 하루 앱의 그림처럼 새로운 항목을 다운로드하려고 시도한다.)
저는 데이터베이스에 액세스 할 때 Context와 관련이 있다고 생각합니다. AppContextHelper라는 클래스가 있는데,이 클래스는 Application을 확장하고 컨텍스트를 저장하는 정적 멤버를가집니다. 이 컨텍스트는 데이터베이스에 액세스 할 때 항상 사용됩니다.
내 질문 : 어떤 경우 위젯이나 앞서 언급 한 AlarmManager에 의해 방송 된 BroadcastReceiver에서 데이터베이스를 수집 할 때 그 컨텍스트가 유효하지 않을 수 있으며 그 경우 제공된 '컨텍스트'를 사용하여 '애플리케이션 '문맥? 그렇다면 컨텍스트가 잘못되었거나 더 나은 이유는 무엇입니까? 어떤 컨텍스트가 제공되는 것입니까?
미리 감사드립니다.
마찬가지로 위젯이나 AlarmManager 클래스의 일부 장치에서만 문제가 발생한 코드를 요청했습니다.
Intent myIntent = new Intent(AppContextHelper.getContext(), ApodDownloader.class);
mPendingIntent = PendingIntent.getBroadcast(AppContextHelper.getContext(), 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)AppContextHelper.getContext().getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis() + 10000, AlarmManager.INTERVAL_HOUR, mPendingIntent);
AppContextHelper.java
: 나는알람을 초기화 코드 (즉, 적어도 라인 코드입니다)에 알람 관리기 클래스의 오류로 이어지는 코드를 게시 할 예정입니다
public class AppContextHelper extends Application { private static Context mContext; @Override public void onCreate() { super.onCreate(); mContext = this; } public static Context getContext(){ return mContext; } }
(일부) ApodDownloader.java (여기에는 예외 발생 라인이 포함됨)
@Override public void onReceive(Context arg0, Intent arg1) { (new AsyncTaskThreadPool<Integer, Void, Boolean>() { @Override protected Boolean doInBackground(Integer... params) { Helpers.logMessage("Checking new entries."); SQLiteDatabase db = FrescoDatabase.acquireReadableDatabase(AppContextHelper.getContext()); try { >>> THIS LINE THROWS THE EXCEPTION <<< maxStamp = Helpers.executeScalarLong(db, "SELECT Min(stamp) FROM image_data WHERE category = 'Astronomy' AND stamp >= 1357426800 and coalesce(title_nl, '') = ''"); [...] } finally { FrescoDatabase.releaseReadableDatabase(); } [...] more code } [...] onPostExecute }).executeOnExecutor(AsyncTaskThreadPool.THREAD_POOL_EXECUTOR, 0);
FrescoDatabase.java 데이터베이스는 시작시 응용 프로그램에서 자동으로 생성되며이 코드는 작동하지만 예외를 발생시키는 장치에서도 작동합니다. AppManager가 위젯과 AlarmManager의 BroadcastReceiver를 제외하고 완벽하게 실행되기 때문에 데이터베이스가 문제가있는 장치에 있다는 것을 충분히 강조 할 수는 없습니다. db가 올바르게 초기화되지 않았다는 것을 알려주지 마십시오.
(도의 일부) 도우미.자바
public class Helpers { [...] public static long executeScalarLong(SQLiteDatabase db, String query) { return executeScalarLong(db, query, new String[] { }); } public static long executeScalarLong(SQLiteDatabase db, String query, String... parameters) { (line 85, see stack trace down below) Cursor cursor = db.rawQuery(query, parameters); try { cursor.moveToNext(); long val = cursor.getLong(0); return val; } catch (Exception e) { ; } finally { cursor.close(); } return -1; } }
예외 로그 (요청 된 바와 같이)
java.lang.RuntimeException: An error occured while executing doInBackground()
at nl.tagpulse.utils.AsyncTaskThreadPool$3.done(AsyncTaskThreadPool.java:329)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: android.database.sqlite.SQLiteException: no such table: image_data (code 1): , while compiling: SELECT Min(stamp) FROM image_data WHERE category = 'Astronomy' AND stamp >= 1357426800 and coalesce(title_nl, '') = ''
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1012)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:623)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
at nl.tagpulse.fresco.other.Helpers.executeScalarLong(Helpers.java:85)
at nl.tagpulse.fresco.other.Helpers.executeScalarLong(Helpers.java:82)
at nl.tagpulse.fresco.business.FrescoDatabase.retrieveNewEntries(FrescoDatabase.java:64)
at nl.tagpulse.fresco.business.ApodDownloader$1.doInBackground(ApodDownloader.java:192)
at nl.tagpulse.fresco.business.ApodDownloader$1.doInBackground(ApodDownloader.java:1)
at nl.tagpulse.utils.AsyncTaskThreadPool$2.call(AsyncTaskThreadPool.java:317)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 4 more
는 I는 Helpers.java 블록에서 라인 (85) 마커를 추가했다. 희망이 도움이됩니다.
자바 코드를 게시하면 아무 것도 할 수 없습니다. – Sajmon
코드를 추가하여 명확히하려고했습니다. 희망이 도움이됩니다. – Toverbal
도 오류 로그를 게시하십시오. – kdehairy