【发布时间】:2011-07-05 15:55:23
【问题描述】:
快速总结:我正在制作一个解析二进制文件、存储顶点及其属性并在 openGL 中显示它们的应用程序。我正在尝试在解析时实现 ProgressDialog,但遇到了相当大的麻烦。我已经尝试在很多地方实现这一点,但这是我目前的设置:
public class PointViewer extends Activity{
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
filePath = extras.getString("file_path");
mGLView = new GLSurfaceView(this);
theRenderer = new OpenGLRenderer();
mGLView.setRenderer(theRenderer);
//Parse the file and set the arrays
theRenderer.setLAS(filePath);
setContentView(mGLView);
}
...
}
渲染类...
public class OpenGLRenderer extends Activity implements GLSurfaceView.Renderer {
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void setLAS (String fileName){
new ProgressTask(this).execute();
}
...
/*
* The class for the progress dialog
*/
private class ProgressTask extends AsyncTask<String, Void, Boolean> {
private ProgressDialog dialog;
private Context context;
//private List<Message> messages;
public ProgressTask(Context ctx) {
context = ctx;
dialog = new ProgressDialog(context);
}
/** progress dialog to show user that the backup is processing. */
protected void onPreExecute() {
this.dialog.setMessage("Progress start");
this.dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
this.dialog.show();
}
@Override
protected void onPostExecute(final Boolean success) {
if (dialog.isShowing()) {
dialog.dismiss();
}
if (success) {
Toast.makeText(context, "OK", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Error", Toast.LENGTH_LONG).show();
}
}
protected Boolean doInBackground(final String... args) {
try{
ptCloud = new PointCloud(args[0]);
...
dialog.setProgress(percentParsed);
return true;
} catch (Exception e){
Log.e("tag", "error", e);
return false;
}
}
}
当我调用 dialog = new ProgressDialog(context); 它在空指针异常时出错,我假设是因为存在上下文问题...有人有什么想法吗?
【问题讨论】:
-
无法启动活动.... ERROR/AndroidRuntime(25782): at ...OpenGLRenderer$ProgressTask.
(OpenGLRenderer.java:303),我在问题中标记的那个。
标签: android progressdialog android-context