试图调用本地数据库变量并且应用程序停止工作
Tring to call a local database variable and the app stop working
如果我从本地数据库调用变量,我的应用程序将停止工作。我使用了带有字符串的 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 还没有添加到 window,您就无法真正创建对话框。
如果我从本地数据库调用变量,我的应用程序将停止工作。我使用了带有字符串的 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 还没有添加到 window,您就无法真正创建对话框。