gpt4 book ai didi

java - 试图调用本地数据库变量并且应用程序停止工作

转载 作者:行者123 更新时间:2023-12-01 11:50:14 25 4
gpt4 key购买 nike

如果我从本地数据库调用变量,我的应用程序将停止工作。我使用了带有字符串的 ALertDialog(让我大声翻译它),并且尝试从本地数据库调用变量。

public class CameraActivity extends Activity
{
private BdLocal bdl = new BdLocal(); //DB
public static final int TAMANHOAREAFUMACA = 100;
public static final int QUALIDADEJPEG = 100;

PreviewCamera mPreview;

@Override
protected void onCreate(Bundle savedInstanceState) {

AlertDialog dialog;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getResources().getString(R.string.afericao_instrucao) +
String.valueOf(bdl.getLauTempo()) + //this variable make my app stop woking
getResources().getString(R.string.fotos) +
String.valueOf(bdl.getQntFotos()) + //this variable make my app stop woking
getResources().getString(R.string.segundos));

builder.setPositiveButton(android.R.string.ok, null);
dialog = builder.create();
dialog.show();

super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_camera);
}

我已经使用了一些其他代码,但总是让我的应用程序停止工作。

解决方案?

最佳答案

如果没有堆栈跟踪和 BdLocal 代码,调试起来非常困难。但是,您不能在 setContentView 之前添加对话框。考虑将所有代码移至 onResume 方法:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_camera);
}

@Override
protected void onResume(){
super.onResume();
AlertDialog dialog;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getResources().getString(R.string.afericao_instrucao) +
String.valueOf(bdl.getLauTempo()) + //this variable make my app stop woking
getResources().getString(R.string.fotos) +
String.valueOf(bdl.getQntFotos()) + //this variable make my app stop woking
getResources().getString(R.string.segundos));

builder.setPositiveButton(android.R.string.ok, null);
dialog = builder.create();
dialog.show();
}

如果 Activity 尚未添加到窗口中,您就无法真正创建对话框。

关于java - 试图调用本地数据库变量并且应用程序停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28854901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com