這裏是棧跟蹤..........你會看到「刪除」幾次,以及在代碼中,因爲我希望保持我的包私人。Matcher.appendEvaluated()上的NullPointerException?
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.*removed*.*removed*/com.*removed*.*removed*.List}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at java.util.regex.Matcher.appendEvaluated(Matcher.java:135)
at java.util.regex.Matcher.appendReplacement(Matcher.java:115)
at java.util.regex.Matcher.replaceAll(Matcher.java:322)
at java.lang.String.replaceAll(String.java:1963)
at com.*removed*.*removed*.List.fillData(NoteList.java:100)
at com.*removed*.*removed*.List.onCreate(NoteList.java:31)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
... 11 more
......這裏是相關的代碼。當用戶啓動List活動時,我希望他們根據他們從前一個列表中點擊的項目查看結果。主頁是一個列表,因此List活動基本上是一個查詢,其中我搜索數據庫中的所有條目,其中的書名列名與他們在主頁中單擊的名稱相匹配。該方法用查詢的結果「填充」列表視圖。
@SuppressWarnings("deprecation")
private void fillData() {
String[] args = {"woo"};
for(int i = 0; i < args.length ; i++){
args[i] = args[i].replaceAll("woo", getBook());}
String[] projection = ............removed
Cursor cursor = managedQuery(Provider.CONTENT_URI, projection,
Database.COLUMN_BOOK + "=" + "?",
args, null);
String[] from = ............removed
int[] to = ...........removed
adapter = new SimpleCursorAdapter(List.this, R.layout.note_row, cursor, from,
to);
setListAdapter(adapter); }
static String book;
public static String getBook() {return book;}
public static void setBook(String book) {List.book = book;}
ADN這裏是從主頁
public void onItemClick(AdapterView<?> adapter, View v,
int position, long id) {
final String[] choice = getResources().getStringArray(R.array.booknames);
String book = choice[position];
List.setBook(book);
Intent x = new Intent(Home.this, List.class);
Home.this.startActivity(x);
}
這個程序是已經在市場上的代碼和設備的約3%收到此空指針異常。所以這樣做並不像我所希望的那樣完全有效。
我的第一個猜測是我沒有正確地初始化變量參數,這會導致ReplaceAll方法在極少數情況下出現毛刺。 我的第二個猜測是我應該避免getter和setter並使用bundle。
如何重寫此查詢以獲得100%的成功?
什麼設備無法正常工作? – PearsonArtPhoto
即時通訊關閉摩托羅拉MileStone(又名Droid 1或原來的Droid) –