即时尝试执行查询,但显示错误。 这是我的代码如何显示数据库中的数据android
public String c(){
objBD = new Bd(nContext, "Laboratorios", null, 1);
db = objBD.getReadableDatabase();
Cursor c=db.rawQuery("SELECT * FROM Laboratorios WHERE ID = (SELECT MAX(ID) FROM Laboratorios);", null);
if(c!=null) {
while (c.moveToNext()) {
String iLab = c.getString(c.getColumnIndex("Descripcion"));
//.add(iLab);
return iLab;
}
}
return null;
}
这就是我想要显示它
protected void onCreate(Bundle savedInstanceState) {
TextView Lab=(TextView)findViewById(R.id.lab_con);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_consulta);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ConexionBD O1=new ConexionBD(this);
O1.c();
Lab.setText(O1);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
/*String texto ="bien";
Toast toast = Toast.makeText(this, texto, Toast.LENGTH_LONG);
toast.show();
Intent i =new Intent(this,Labs.class);
startActivity(i);*/
}
public void salir (View view){
String texto ="Se ha guardado su registro";
Toast toast = Toast.makeText(this, texto, Toast.LENGTH_LONG);
toast.show();
Intent salida=new Intent(Intent.ACTION_MAIN); //Llamando a la activity principal
finish();
}
这是错误的活动
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
我尝试做一个空白的活动,但总是有这个错误,谢谢你的帮助。
这是错误
了java.lang.RuntimeException:无法启动活动ComponentInfo {} com.example.oscar.app/com.example.oscar.app.consulta:显示java.lang.NullPointerException :尝试在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)处的空对象引用上调用虚方法'void android.support.design.widget.FloatingActionButton.setOnClickListener(android.view.View $ OnClickListener)' android.app.ActivityThread.android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)在android.app.ActivityThread.-wrap12(ActivityThread.java)上android.app.ActivityThread $ h.handleMessage(ActivityThread.java:1460)在android.os。 Handler.dispatchMessage(Handler.java:102)在android.os .Looper.loop(Looper.java:154)at android.app.ActivityThread.main(ActivityThread.java:6077)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)导致:java.lang.NullPointerException:尝试调用虚拟方法'void android.support。在android.app.Activity.performCreate的com.example.oscar.app.consulta.onCreate(consulta.java:31)处的空对象引用上设计“design.widget.FloatingActionButton.setOnClickListener(android.view.View $ OnClickListener) (android.app.ActivityThread.java:2599)在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)上的android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) )at android.app.ActivityThread.-wrap12(ActivityThread.java)at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460)at android.os .Handler.dispatchMessage(Handler.java:102)at android.os.Looper.loop(Looper.java:154)at android.app.ActivityThread.main(ActivityThread.java:6077)at java.lang.reflect.Method。调用(本地方法)在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865)在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
我做到了,但不起作用 –