Friday 15 May 2015

Android resizing based on device screen size -


I have the following code in my Android application when I run it on an old Samsung Dart (API <13) , Then I get a null-pointer exception as described below.

Is there any special reason that the code is working for the four rows above it, but is it not that it is getting the NullPointer? @SuppressLint ("NewApi") @Pressing Warnings ("Excluded") Public Zero Adjust Size () {Int width, height; Display display = getWindowManager () GetDefaultDisplay (); If (android.os.build.VERSION.SDK_INT> = 13) {point size = new point (); Display.getSize (size); Width = size.x; Height = size Y; } And {width = display.getWidth (); // Excluded Height = display.getHeight (); // Excluded} Image View Counties = (Image View) ViewById (R.id.btnCounties); ImageView subscriber = (ImageView) findViewById (R.id.btnMembers); ImageView webLink = (ImageView) findViewById (R.id.btnWebLink); ImageView logo = (ImageView) findViewById (R.id.logo); // Calculate the image size if (height & gt; width) {counties.getLayoutParams (). Height = (int) (width / 2.5); Counties.getLayoutParams (). Width = (int) (width / 2.5); Members.getLayoutParams () Height = (int) (width / 2.5); Members.getLayoutParams () Width = (int) (width / 2.5); WebLink.getLayoutParams (). Height = (int) ((width / 2.4) / 3.5); // Null Pointer Error webLink.getLayoutParams (). Width = (int) (width / 2.4); Logo.getLayoutParams () Height = (int) (height / 6); Logo.getLayoutParams () width = width; } And (counties.getLayoutParams). Height = (int) (height / 2.5); Counties.getLayoutParams (). Width = (int) (height / 2.5); Members.getLayoutParams () Height = (int) (height / 2.5); Members.getLayoutParams () Width = (int) (height / 2.5); }}

just,

  ImageView webLink = (See image) Find VVBID (RID BTN Web Links);   

webLink is null .

Check your layout XML: Are you sure the name ( BtnWebLink ) is correct? Are you really loading the correct layout xml file?

Potentially you have ImageView in a layout but Android is loading the layout of a specific screen size where there is no BTN web link

There is a breakpoint in that row and check whether the variable webLink is zero.

The blank pointer exception first time you try to use the variable.

No comments:

Post a Comment