Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android setLayoutParams for webview generates ERROR

is it possible to set

mWebView = (WebView) findViewById(R.id.webviewHelp);
        mWebView.setLayoutParams(new ViewGroup.LayoutParams(100, 200));

here

 mWebView.setLayoutParams(new Gallery.LayoutParams(70,85));

is also tested but not working :(

in my activity? my xml file is as below

(here i've to create webview through XML is needed in my application)

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"   android:id="@+id/rl"
        android:layout_height="360dip">
    <!--    <WebView android:id="@+id/webviewHelp" android:layout_width="fill_parent"-->
    <!--        android:layout_height="fill_parent" />-->
    <WebView android:id="@+id/webviewHelp" android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
        <Button android:id="@+id/My_btn"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" android:gravity="center" android:textSize="8px" android:text="Download this mp3 file"
    android:textColor="@color/white" 
            android:layout_width="fill_parent" android:layout_height="33dip"
            android:visibility="invisible" />
        <Button android:id="@+id/My_btn1"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" android:text="this is button !"
            android:layout_width="0dip" android:layout_height="0dip"
            android:visibility="invisible" />
    </RelativeLayout>

and i am getting this ERROR and application forcefully close

06-11 15:42:51.816: DEBUG/AndroidRuntime(323): Shutting down VM
06-11 15:42:51.816: WARN/dalvikvm(323): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
06-11 15:42:51.816: ERROR/AndroidRuntime(323): Uncaught handler: thread main exiting due to uncaught exception
06-11 15:42:51.835: ERROR/AndroidRuntime(323): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout$DependencyGraph.findRoots(RelativeLayout.java:1291)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1238)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:279)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:299)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:569)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:361)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewRoot.performTraversals(ViewRoot.java:747)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1613)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.os.Looper.loop(Looper.java:123)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.app.ActivityThread.main(ActivityThread.java:4203)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at java.lang.reflect.Method.invokeNative(Native Method)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at java.lang.reflect.Method.invoke(Method.java:521)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at dalvik.system.NativeStart.main(Native Method)
06-11 15:42:51.845: INFO/Process(52): Sending signal. PID: 323 SIG: 3
06-11 15:42:51.845: INFO/dalvikvm(323): threadid=7: reacting to signal 3
06-11 15:42:51.857: ERROR/dalvikvm(323): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
06-11 15:42:52.566: DEBUG/dalvikvm(99): GC freed 4505 objects / 251696 bytes in 293ms

what is wrong i am doing? thanks in advance :Pragna

like image 237
Android Avatar asked Dec 28 '22 19:12

Android


1 Answers

Instead of this:

   mWebView = (WebView) findViewById(R.id.webviewHelp);    
   mWebView.setLayoutParams(new ViewGroup.LayoutParams(100, 200));

use:

   mWebView = (WebView) findViewById(R.id.webviewHelp);        
   LayoutParamters lp = mWebView.getLayoutParams();    
   lp.width=100;   
   lp.height=200;   
   mWebView.setLayoutParams(lp); 
like image 60
sat Avatar answered Jan 06 '23 11:01

sat