hi I’m trying to load up a html file via a Custom Alert box, to take advantage of formatting. but my app crashes when ever I launch the dialog. I had a problem yesterday too when I was just using html string conversion, I could get things like bold text working, but couldn’t encourage it to use an image file located in my root/assets folder. I wonder if its a code error or am I referencing my assets folder incorrectly. I know it sounds like two problems but I’m hoping they are related?
I’ve tried with and without the JS true, there is no js in my html file, and its very basic.
WebView mWebView = (WebView) findViewById(R.id.webView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/helppage.html");
Error Dump
03-24 14:20:59.800: W/dalvikvm(5574): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
03-24 14:20:59.800: E/AndroidRuntime(5574): FATAL EXCEPTION: main
03-24 14:20:59.800: E/AndroidRuntime(5574): java.lang.NullPointerException
03-24 14:20:59.800: E/AndroidRuntime(5574): at com.mediabar.timelapse.TimeLapseActivity.createDialog(TimeLapseActivity.java:140)
03-24 14:20:59.800: E/AndroidRuntime(5574): at com.mediabar.timelapse.TimeLapseActivity$3.onClick(TimeLapseActivity.java:66)
03-24 14:20:59.800: E/AndroidRuntime(5574): at android.view.View.performClick(View.java:2538)
03-24 14:20:59.800: E/AndroidRuntime(5574): at android.view.View$PerformClick.run(View.java:9152)
03-24 14:20:59.800: E/AndroidRuntime(5574): at android.os.Handler.handleCallback(Handler.java:587)
03-24 14:20:59.800: E/AndroidRuntime(5574): at android.os.Handler.dispatchMessage(Handler.java:92)
03-24 14:20:59.800: E/AndroidRuntime(5574): at android.os.Looper.loop(Looper.java:130)
03-24 14:20:59.800: E/AndroidRuntime(5574): at android.app.ActivityThread.main(ActivityThread.java:3691)
03-24 14:20:59.800: E/AndroidRuntime(5574): at java.lang.reflect.Method.invokeNative(Native Method)
03-24 14:20:59.800: E/AndroidRuntime(5574): at java.lang.reflect.Method.invoke(Method.java:507)
03-24 14:20:59.800: E/AndroidRuntime(5574): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
03-24 14:20:59.800: E/AndroidRuntime(5574): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
03-24 14:20:59.800: E/AndroidRuntime(5574): at dalvik.system.NativeStart.main(Native Method)
EDIT: Added activity
public class mainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.pull_left_in, R.anim.push_right_out);
setContentView(R.layout.main);
Button help = (Button) findViewById(R.id.help);
help.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
createDialog();
}
});
}
public void createDialog() {
final Dialog dialog = new Dialog(CopyOfTimeLapseActivitybackup.this);
dialog.setContentView(R.layout.help_dialog);
dialog.setTitle("Help Area");
WebView mWebView = (WebView) findViewById(R.id.webView);
mWebView.loadUrl("file:///android_asset/helppage.html");
Button button = (Button) dialog.findViewById(R.id.okButton);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
Change this line:
to look like this:
You have to do it this way because your webview’s parent is the dialog, not your Activity layout.
I think you might also have to move all of your findViewById() calls to after the
dialog.show();