我为平板电脑制作了一个在 android 3.2 上运行良好的应用程序。现在我正试图让它在 android 4+ 上工作,但不知何故,一小部分代码不起作用。我是一个初学者,所以我无法弄清楚什么是行不通的,因为代码是从前段时间的一个例子中获取的。
崩溃的代码部分只是一个文本框,您可以在其中根据微调器编写任何您想要的内容,您可以在其中从数据库中选择要过滤的字段。它在 3.2 上完美运行(并且同一段代码正在其他一些微调器中工作,我在两个版本的 android 上的另一个片段上都有)。
首先,我们使用 logcat:
11-12 18:33:00.428: E/AndroidRuntime(8140): FATAL EXCEPTION: main
11-12 18:33:00.428: E/AndroidRuntime(8140): java.lang.NullPointerException
11-12 18:33:00.428: E/AndroidRuntime(8140): at dvgvsc.vscdvg.Fragmentsearchlist.ifacesearch(Fragmentsearchlist.java:159)
11-12 18:33:00.428: E/AndroidRuntime(8140): at dvgvsc.vscdvg.Fragmentsearchlist.onPrepareOptionsMenu(Fragmentsearchlist.java:103)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.FragmentManagerImpl.dispatchPrepareOptionsMenu(FragmentManager.java:1865)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.Activity.onPreparePanel(Activity.java:2463)
11-12 18:33:00.428: E/AndroidRuntime(8140): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:438)
11-12 18:33:00.428: E/AndroidRuntime(8140): at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:761)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.Activity.invalidateOptionsMenu(Activity.java:2552)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.FragmentManagerImpl.invalidateOptionsMenu(FragmentManager.java:1914)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.Fragment.setHasOptionsMenu(Fragment.java:898)
11-12 18:33:00.428: E/AndroidRuntime(8140): at dvgvsc.vscdvg.Fragmentsearchlist.onCreateView(Fragmentsearchlist.java:47)
11-12 18:33:00.428: E/AndroidRuntime(8140): at dvgvsc.vscdvg.OrdenesFragment.onCreateView(OrdenesFragment.java:65)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:828)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.BackStackRecord.run(BackStackRecord.java:622)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.os.Handler.handleCallback(Handler.java:605)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.os.Handler.dispatchMessage(Handler.java:92)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.os.Looper.loop(Looper.java:137)
11-12 18:33:00.428: E/AndroidRuntime(8140): at android.app.ActivityThread.main(ActivityThread.java:4514)
11-12 18:33:00.428: E/AndroidRuntime(8140): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 18:33:00.428: E/AndroidRuntime(8140): at java.lang.reflect.Method.invoke(Method.java:511)
11-12 18:33:00.428: E/AndroidRuntime(8140): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
11-12 18:33:00.428: E/AndroidRuntime(8140): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
11-12 18:33:00.428: E/AndroidRuntime(8140): at dalvik.system.NativeStart.main(Native Method)
这是崩溃的代码((Line: text_search.addTextChangedListener(new TextWatcher() { ))
private final void ifacesearch() {
/** search box that is used on the searches, using a listerner which will move the cursor based on the user imput. */
/*EditText text_search = (EditText)getActivity().findViewById(R.id.text_search);
text_search.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable text) {
if (text.length() > 0) {
adapter.changeCursor(vscdvgActivity._db.defcursor(TABLA, SEARCH_FILTER, text.toString()));
}else{
adapter.changeCursor(vscdvgActivity._db.defcursor(TABLA, null, null));
}
}
public void beforeTextChanged(CharSequence text, int start, int before, int count) {
}
public void onTextChanged(CharSequence text, int start, int before, int count) {
}
});*/
/** add to the spinner the db fields /*
/*Spinner spinner_filter = (Spinner)getActivity().findViewById(R.id.spinner_filter);
ArrayAdapter<String> spinner_adapter = new ArrayAdapter<String>(
getActivity(),
android.R.layout.simple_spinner_dropdown_item,
COLUMN_FILTER[1]);
spinner_filter.setAdapter(spinner_adapter);
spinner_filter.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
SEARCH_FILTER = COLUMN_FILTER[0][position];
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});*/
有什么想法可能会崩溃吗?
提前致谢。