开发者

Webview not working?

I've got the following method...

public class Image extends Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);

/* Using WebView to display the full-screen image */
WebView full = (WebView)findViewById(R.id.webview);

/* Set up the Zoom controls */
FrameLayout mContentView = (FrameLayout) getWindow().
getDecorView().findViewById(android.R.id.content);
final View zoom = this.full.getZoomControls();
mContentView.addView(zoom开发者_开发问答, ZOOM_PARAMS);
zoom.setVisibility(View.VISIBLE);

/* Create a new Html that contains the full-screen image */
String html = new String();
html = ("<html><center><img src=\"1276253554007.jpg\"></html>" );

/* Finally, display the content using WebView */
full.loadDataWithBaseURL("file:///sdcard/DCIM/Camera/",
                                                        html,
                                                        "text/html",
                                                        "utf-8",
                                                        "");
}

}

R.id.webview refrences...

 <?xml version="1.0" encoding="utf-8"?>
 <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

But I'm getting a full cannot be resolved or is not a field compile error, but full is defined as.. WebView full = (WebView)findViewById(R.id.webview); anyone have any idea why this isnt working?

Thanks.


Remove "this." prefix from the full variable usages. It looks like you're trying to access method local variable, while "this." keyword is intended for accessing member variables.

Here is modified code sample which compiled and runs just fine for me.

    public class Image extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);

    /* Using WebView to display the full-screen image */
    WebView full = (WebView)findViewById(R.id.webview);

    /* Set up the Zoom controls */
    FrameLayout mContentView = (FrameLayout) getWindow().
    getDecorView().findViewById(android.R.id.content);
    final View zoom = full.getZoomControls();
    mContentView.addView(zoom);
    zoom.setVisibility(View.VISIBLE);

    /* Create a new Html that contains the full-screen image */
    String html = new String();
    html = ("<html><center><img src=\"1276253554007.jpg\"></html>" );

    /* Finally, display the content using WebView */
    full.loadDataWithBaseURL("file:///sdcard/DCIM/Camera/",
                                                            html,
                                                            "text/html",
                                                            "utf-8",
                                                            "");
    }

}


Your comments to the other answer reminded me of a similiar problem I once read on SO. Guess it's the same: you're looking for WebView in the Actitvity view while I guess it's actually declared in a dialog view... The linked answer solved the other OP's problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜