日志详细信息为:
> 引起:java.lang.NullPointerException:storage == null at java.util.Arrays $ ArrayList。(Arrays.java:38) 在java.util.Arrays.asList(Arrays.java:155) 在android.widget.ArrayAdapter。(ArrayAdapter.java:128) 在 com.venkatesh.autocompletetextviewdemo.MainActivity.onCreate(MainActivity.java:20) 在android.app.Activity.performCreate(Activity.java:5990) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 在android.app.ActivityThread.access $ 800(ActivityThread.java:151) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:135) 在android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) 在java.lang.reflect.Method.invoke(Method.java:372) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) I /处理:发送信号。 PID:4291 SIG:9申请被终止。
现在Lotcat是: 11-19 21:13:21.648 3567-3567 /? E / memtrack:无法加载memtrack模块(没有这样的文件或目录) 11-19 21:13:21.648 3567-3567 /? E / android.os.Debug:无法加载memtrack模块:-2 11-19 21:13:22.714 3578-3578 /? E / cutils-trace:打开跟踪文件时出错:权限被拒绝(13) 11-19 21:13:25.940 2026-2237 / com.google.android.gms.persistent E / NetworkScheduler.SR:提供无法识别的操作:android.intent.action.PACKAGE_REMOVED 11-19 21:13:26.626 3611-3611 /? E / memtrack:无法加载memtrack模块(没有这样的文件或目录) 11-19 21:13:26.626 3611-3611 /? E / android.os.Debug:无法加载memtrack模块:-2 11-19 21:17:07.624 1520-1607 / system_process E / wifi:getStaticLongField sWifiHalHandle 0x7f3999c273d0 11-19 21:17:07.624 1520-1607 / system_process E / WifiStateMachine:cancelDelayedScan - > 1
[ 11-19 21:17:07.643 1520: 1548 D/ ]
HostConnection::get() New Host Connection established 0x7f3994836710, tid 1548
[ 11-19 21:17:07.651 1520: 1548 W/ ]
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
11-19 21:17:07.664 1520-1607 / system_process E / WifiStateMachine:cancelDelayedScan - > 2 11-19 21:17:07.806 1130-1130 /? E / EGL_emulation:tid 1130:eglCreateSyncKHR(1865):错误0x3004(EGL_BAD_ATTRIBUTE) 11-19 21:17:08.488 1520-1549 / system_process E / libsuspend:写入/ sys / power / wakeup_count时出错:参数无效 11-19 21:17:08.510 1130-1130 /? E / EGL_emulation:tid 1130:eglCreateSyncKHR(1865):错误0x3004(EGL_BAD_ATTRIBUTE) 11-19 21:17:08.616 1520-1549 / system_process E / libsuspend:写入/ sys / power / state时出错:设备或资源繁忙
package com.venkatesh.autocompletetextviewdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DBHelper mydb = new DBHelper(this);
final String[] mydata = mydb.SelectAllData();
final AutoCompleteTextView autoCom = findViewById(R.id.ACtextview);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, mydata);
autoCom.setThreshold(1); /** will start working form first character. */
autoCom.setAdapter(adapter);
}
}
public String[] SelectAllData(){
try {
String arrData[] = null;
SQLiteDatabase db;
db=this.getReadableDatabase();
String SQLstr = " Select * From " + MANF_TABLE_NAME;
Cursor cursor =db.rawQuery(SQLstr,null);
if (cursor != null)
{
if (cursor.moveToFirst()) {
arrData = new String[cursor.getCount()];
int i = 0 ;
do {
arrData[i] = cursor.getString(1) ;
System.out.print(arrData[i]);
i++;
} while (cursor.moveToNext());
}
}
cursor.close();
return arrData;
} catch ( Exception e ) {
return null;
}
}
答案 0 :(得分:0)
这似乎是空指针异常,在那里你定义了一个数组,你是否将该数组连接到列表视图或其他视图或什么? ...如果是这样,请在使用该视图之前检查并确保使用XML
方法将该视图从findViewById();
文件连接到Java代码。如果使用这些视图的代码是在另一种方法而不是onCreate
,请不要忘记在类中和onCreat方法之前声明视图或者sth,例如:private ListView mylist;
或者其他,否则其他方法中的代码无法达到这些视图。