logo
down
shadow

PQgetResult always returns NULL


PQgetResult always returns NULL

By : Juan Carlos C
Date : November 22 2020, 01:01 AM
I think the issue was by ths following , To help debug the issue, I started the PostgreSQL server with a debug level setting:
code :
$ postgres -d 2


Share : facebook icon twitter icon
managedQuery(Media.EXTERNAL_CONTENT_URI, projection,null,null, null); returns null when running on device

managedQuery(Media.EXTERNAL_CONTENT_URI, projection,null,null, null); returns null when running on device


By : fluxus2x
Date : March 29 2020, 07:55 AM
Hope that helps , same for this code working
code :
public class LoadImagesFromSDCardActivity extends Activity implements
OnItemClickListener {

/**
 * Grid view holding the images.
 **/

private GridView sdcardImages;
/**
 * Image adapter for the grid view.
 **/
private ImageAdapter imageAdapter;
/**
 * Display used for getting the width of the screen. 
 **/
private Display display;
ImageView imgView;

/**
 * Creates the content view, sets up the grid, the adapter, and the click listener.
 * 
 * @see android.app.Activity#onCreate(android.os.Bundle)
 **/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    // Request progress bar
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.main);

    display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    imgView=(ImageView)findViewById(R.id.imgView);
    setupViews();
    setProgressBarIndeterminateVisibility(true); 
    loadImages();
}

/**
 * Free up bitmap related resources.
 **/
protected void onDestroy() {
    super.onDestroy();
    final GridView grid = sdcardImages;
    final int count = grid.getChildCount();
    ImageView v = null;
    for (int i = 0; i < count; i++) {
        v = (ImageView) grid.getChildAt(i);
        ((BitmapDrawable) v.getDrawable()).setCallback(null);
    }
}
/**
 * Setup the grid view.
 **/
private void setupViews() {
    sdcardImages = (GridView) findViewById(R.id.sdcard);
    sdcardImages.setNumColumns(display.getWidth()/95);
    sdcardImages.setClipToPadding(false);
    sdcardImages.setOnItemClickListener(LoadImagesFromSDCardActivity.this);
    imageAdapter = new ImageAdapter(getApplicationContext()); 
    sdcardImages.setAdapter(imageAdapter);
}
/**
 * Load images.
 */
private void loadImages() {
    final Object data = getLastNonConfigurationInstance();
    if (data == null) {
        new LoadImagesFromSDCard().execute();
    } else {
        final LoadedImage[] photos = (LoadedImage[]) data;
        if (photos.length == 0) {
            new LoadImagesFromSDCard().execute();
        }
        for (LoadedImage photo : photos) {
            addImage(photo);
        }
    }
}
/**
 * Add image(s) to the grid view adapter.
 * 
 * @param value Array of LoadedImages references
 */
private void addImage(LoadedImage... value) {
    for (LoadedImage image : value) {
        imageAdapter.addPhoto(image);
        imageAdapter.notifyDataSetChanged();
    }
}

/**
 * Save bitmap images into a list and return that list. 
 * 
 * @see android.app.Activity#onRetainNonConfigurationInstance()
 */
@Override
public Object onRetainNonConfigurationInstance() {
    final GridView grid = sdcardImages;
    final int count = grid.getChildCount();
    final LoadedImage[] list = new LoadedImage[count];

    for (int i = 0; i < count; i++) {
        final ImageView v = (ImageView) grid.getChildAt(i);
        list[i] = new LoadedImage(((BitmapDrawable) v.getDrawable()).getBitmap());
    }

    return list;
}
/**
 * Async task for loading the images from the SD card. 
 * 
 * @author Mihai Fonoage
 *
 */
class LoadImagesFromSDCard extends AsyncTask<Object, LoadedImage, Object> {

    /**
     * Load images from SD Card in the background, and display each image on the screen. 
     *  
     * @see android.os.AsyncTask#doInBackground(Params[])
     */
    @Override
    protected Object doInBackground(Object... params) {
        //setProgressBarIndeterminateVisibility(true); 
        Bitmap bitmap = null;
        Bitmap newBitmap = null;
        Uri uri = null;            

        // Set up an array of the Thumbnail Image ID column we want
        String[] projection = {MediaStore.Images.Thumbnails._ID};
        // Create the cursor pointing to the SDCard
        Cursor cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                projection, // Which columns to return
                null,       // Return all rows
                null,       
                null); 
        int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
        int size = cursor.getCount();
        // If size is 0, there are no images on the SD Card.
        if (size == 0) {
            //No Images available, post some message to the user
        }
        int imageID = 0;
        for (int i = 0; i < size; i++) {
            cursor.moveToPosition(i);
            imageID = cursor.getInt(columnIndex);
            uri = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID);
            try {
                bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
                if (bitmap != null) {
                    newBitmap = Bitmap.createScaledBitmap(bitmap, 70, 70, true);
                    bitmap.recycle();
                    if (newBitmap != null) {
                        publishProgress(new LoadedImage(newBitmap));
                    }
                }
            } catch (IOException e) {
                //Error fetching image, try to recover
            }
        }
        cursor.close();
        return null;
    }
    /**
     * Add a new LoadedImage in the images grid.
     *
     * @param value The image.
     */
    @Override
    public void onProgressUpdate(LoadedImage... value) {
        addImage(value);
    }
    /**
     * Set the visibility of the progress bar to false.
     * 
     * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
     */
    @Override
    protected void onPostExecute(Object result) {
        setProgressBarIndeterminateVisibility(false);
    }
}

/**
 * Adapter for our image files. 
 * 
 * @author Mihai Fonoage
 *
 */
class ImageAdapter extends BaseAdapter {

    private Context mContext; 
    private ArrayList<LoadedImage> photos = new ArrayList<LoadedImage>();

    public ImageAdapter(Context context) { 
        mContext = context; 
    } 

    public void addPhoto(LoadedImage photo) { 
        photos.add(photo); 
    } 

    public int getCount() { 
        return photos.size(); 
    } 

    public Object getItem(int position) { 
        return photos.get(position); 
    } 

    public long getItemId(int position) { 
        return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
        final ImageView imageView; 
        if (convertView == null) { 
            imageView = new ImageView(mContext); 
        } else { 
            imageView = (ImageView) convertView; 
        } 
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        imageView.setPadding(8, 8, 8, 8);
        imageView.setImageBitmap(photos.get(position).getBitmap());
        return imageView; 
    } 
}

/**
 * A LoadedImage contains the Bitmap loaded for the image.
 */
private static class LoadedImage {
    Bitmap mBitmap;

    LoadedImage(Bitmap bitmap) {
        mBitmap = bitmap;
    }

    public Bitmap getBitmap() {
        return mBitmap;
    }
}
/**
 * When an image is clicked, load that image as a puzzle. 
 */
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {        
    int columnIndex = 0;
    String[] projection = {MediaStore.Images.Media.DATA};
    Cursor cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
            projection,
            null, 
            null, 
            null);
    if (cursor != null) {
        columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToPosition(position);
        String imagePath = cursor.getString(columnIndex); 

        FileInputStream is = null;
        BufferedInputStream bis = null;
        try {
            is = new FileInputStream(new File(imagePath));
            bis = new BufferedInputStream(is);
            Bitmap bitmap = BitmapFactory.decodeStream(bis);
            Bitmap useThisBitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, true);
            Log.i("called","called");
            imgView.setImageBitmap(useThisBitmap);
            bitmap.recycle();
            //Display bitmap (useThisBitmap)
        } 
        catch (Exception e) {
            //Try to recover
        }
        finally {
            try {
                if (bis != null) {
                    bis.close();
                }
                if (is != null) {
                    is.close();
                }
                cursor.close();
                projection = null;
            } catch (Exception e) {
            }
        }
    }
  }

}
  <GridView  
    android:id="@+id/sdcard"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp" 
    android:stretchMode="columnWidth"
    android:gravity="center" />
    <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imgView"
    ></ImageView>
</LinearLayout>  
Java Optional if object is not null - returns the method result, if null - returns default value

Java Optional if object is not null - returns the method result, if null - returns default value


By : Tomas E. Lopez
Date : March 29 2020, 07:55 AM
To fix this issue Is it possible to transform this code to java 8 Optional one-line expression? , A few forms:
code :
long lastPollTime = Optional.ofNullable(object).map(o -> o.getTime()).orElse(0L);

long lastPollTime = Optional.ofNullable(object).map(YouObjectClass::getTime).orElse(0L);

long lastPollTime = Optional.ofNullable(object).isPresent() ? object.getTime() : 0;

long lastPollTime = object != null ? object.getTime() : 0;
long lastPollTime = object == null ? 0 : object.getTime();
public <T,U> U mapWithFallback(T obj, Function<T,U> function, U fallback) {
    if(obj == null) {
        return fallback;
    } else {
        return function.apply(obj);
    }
}
long lastPollTime = mapWithFallback(object, o -> o.getTime(), 0);
public <T,U> U ifElse( Supplier<Boolean> a, Supplier<U> ifTrue, Supplier<U> ifFalse) {
     if(a.get()) {
          return ifTrue.get();
     } else {
          return ifFalse.get();
     }
}

long lastPollTime = ifElse( () -> object == null, () -> object.getTime(), () -> 0);
Curl returns a null string and curl_error also returns null

Curl returns a null string and curl_error also returns null


By : D. Yordanov
Date : March 29 2020, 07:55 AM
this one helps. In my case, curl was only showing this behavior on https URLs, whether CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER are set to false for testing, or not, just as you have here.
I had recently run a yum update which updated Name Service Switch, which was the only change to the server I could think of. I updated via yum on another server, and that server started to show the same failure in curl.
Printing contents of array just returns [null, null, null, null]

Printing contents of array just returns [null, null, null, null]


By : user3209108
Date : March 29 2020, 07:55 AM
To fix this issue , Change the first line of your main() method to:
code :
    PresidentNames =  new String[] {"George Bush", "William J. Clinton", "George W. Bush", "Barrack H. Obama", "Donald J. Trump"};
Why does null||null return a null value but concat(null,null) returns an empty string in postgres?

Why does null||null return a null value but concat(null,null) returns an empty string in postgres?


By : Rima
Date : March 29 2020, 07:55 AM
hop of those help? I'm trying to understand the differences between concat() and || in postgres when using nulls. Why does concat() return an empty string if both sides of the concat are null? , in concat() function:
code :
text concat(str "any",...)  Concatenate all arguments. NULL arguments are ignored.
Related Posts Related Posts :
  • App crashes while converting to Objective-C ARC
  • When updating the TestFlight SDK do you need to delete the old version?
  • How to read file by sector,and not rely on the OS cache in Cocoa
  • Convert from NStimeInterval to CMTime accurately
  • How can I continue my count from the correct spot once I load the saved count?
  • instance method 'connect:' not found (return type defaults to 'id'
  • Does an object initialize automatically if it is the synthesized property of another object?
  • What reasons are there to pass an argument to an initializer in objective C?
  • NSLogging UILabel's text outputs null
  • undefined reference to '__objc_class_name_Fraction'
  • Move UIView above UITableView when user Scrolls Down
  • adding object to nsmutablearray with custom delegate function giving error
  • Cocoa editing NSBezierPath
  • Perform a action on specific time using Parse
  • Objective-C: How to convert json value to BOOL?
  • How to make an int counter for the days
  • Assigning Label Value with Selected Table View Cell
  • SpriteKit - Preloader using GCD
  • Can dependency injection like Typhoon replace multiple singletons?
  • Objective C - How to determine if a folder is a package?
  • How can one draw a background in the elastic portion of an NSScrollView?
  • A solution for my issue with sending some info from an array to Parse
  • Swift Extension fails adding overloaded methods to Objective-C class
  • Determine if key is incorrect with CCCrypt kCCOptionPKCS7Padding-Objective C
  • self.navigationController? is nil when pushing from a objective-c viewController to a Swift ViewController
  • Where to add subViews that I want floating in an NSScrollView using AutoLayout?
  • 'User' in 'User-defined classes'
  • How to get value of a key in NSDictionary?
  • Adding Border Line to UITableView in StoryBoard
  • Mac App Storyboard - Access Document in NSViewController
  • Objective c, reposition a view above the keyboard in one single animation
  • Dismiss modal segue
  • Error message is saying my data is NULL - NSKeyedUnArchiver - I've followed all the steps - still won't work
  • Remove apostrophe in CFStringTransform results
  • Label showing wrong values while NSLog shows the right ones in SpriteKit
  • How to work with locally modified Cocoapod which don't include podspec?
  • What does kCGWindowSharingState actually do?
  • It is possible to copy a CFTypeRef?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org