i am trying to display an image from net..and i am using ignition library for RemoteImageView..
this is the code..
public class images extends Activity{
public String a,b,c,d;
public java.lang.String url;
RemoteImageView iv;
Bitmap bitmap;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
a= getIntent().getExtras().getString("s1");
b = getIntent().getExtras().getString("s2");
c = getIntent().getExtras().getString("s3");
d = getIntent().getExtras().getString("s4");
setContentView(R.layout.ignition);
iv=(RemoteImageView)findViewById(R.id.image1);
}
public void p(View v) throws MalformedURLException{
String u="http://www.infrabazaar.com/"+a;//<--------(1)
iv.setImageUrl(u);
iv.loadImage();
}}
the images should be displayed based on the info sent from the previous class...
if i give a complete link of the image like "http://www.infrabazaar.com/machinary-client-images/1315201358_0.JPG"... iam able display that image on the screen.. but when i am passing the link as in line (1).. it is showing factory returned null message...can any one tell me what can resolve the problem?
This RemoteImageView solves much of the "Factory Returned null " problem... now i get very few times this error... but once i load other image and then try reloading the image for which i got the error it loads properly..
Related
I am trying to create a wallpaper application. All images will come from internet.
Before of set as background, I need to crop the image. And for this, I am using an API named AndroidImageCropper. This API need of a URI object to execute the crop.
How can I get the Uri from ImageView? Because my image is from internet. The image is not on drawable folder. I am confusing. Maybe you guys can help me.
public class MainActivity extends AppCompatActivity {
private NetworkImageView imageView;
private Uri mCropImageUri;
public static final String URL_PHOTO = "http://cdn.wonderfulengineering.com/wp-content/uploads/2016/02/iron-man-wallpaper-42-610x1084.jpg";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (NetworkImageView) findViewById(R.id.image_view);
// Singleton for Volley API, Load image from internet
ImageLoader loader = MySingleton.getInstance(this).getImageLoader();
loader.get(URL_PHOTO, ImageLoader.getImageListener(imageView, R.drawable.temp_picture, android.R.drawable.ic_dialog_alert));
imageView.setImageUrl(URL_PHOTO, loader);
// Put the image on URI object
// #################################
// ### mCropImageUri = <-- ###
// #################################
}
// Action for my button
public void cropImage(View view) {
// API to crop an image
CropImage.activity(mCropImageUri)
.start(this);
}
}
Do you have any suggestion to me?
Thanks.
So you're using Volley? I'm not very familiar with Volley, both just some of my thoughts.
After image is downloaded to Android device, try to find the absolute path of the file and use android.net.Uri.fromFile to get a uri from the image.
Or else, can you use Bitmap object directly, instead of an uri.
OK, after some investigation, I think you have two solutions.
Using volley to download image as file, without using ImageLoader. In this way it's easy to get file uri of the image.
For Android-Image-Cropper, you can use Activity or use View(refer here). You can get the Bitmap object of the image in method onLoadingComplete of ImageLoadingListener. Then use com.theartofdev.edmodo.cropper.CropImageView to crop the image.
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 7 years ago.
New to android programming - apologies for incorrect jargon.
My app can save data entered to EditText fields.
It then can load this data and set the values of this data to String Variables.
Then it preforms a POST HTTP request with these strings.
I'm loading/saving string files using openFileInput and openFileOutput
I've created Methods:
public String LoadMethod()
public String SaveMethod()
These Methods work fine when the Method is in same class as the Activity calling it.
My problem is that 2 Activities need to be able to run the public String LoadMethod()
So what i did was create 2 java class files for Loading and Saving data.
Some commenting is in the files as I've been trying to debug.
LoadUserDetails.java
public class LoadUserDetails extends AppCompatActivity {
public static String sSavedName;
public static String sSavedCompany;
public static String sSavedPhone;
public static String sSavedCarRegistration;
String sNameFile = "name_file";
//private Context context;
public String LoadMethod(){
/* OPEN DETAILS FROM INTERNAL STORAGE*/
//context = getActivity();
/*NAME*/
try {
String sOpenName;
FileInputStream fileInputStream = openFileInput("name_file");
InputStreamReader inputStreamReaderName = new InputStreamReader(fileInputStream);
BufferedReader bufferedReaderName = new BufferedReader(inputStreamReaderName);
StringBuffer stringBufferName = new StringBuffer();
while ((sOpenName = bufferedReaderName.readLine()) != null) {
stringBufferName.append(sOpenName + "\n");
}
sSavedName = (stringBufferName.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
The code repeats for opening the other 3 string files.
I Launch this method from my UserDetails.java Activity and MainActivity.java Activity using this code:
//Load User Details
LoadUserDetails load = new LoadUserDetails();
load.LoadMethod();
This is the error I get in logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.visitorrego.oem.smartsigninvisitor/com.visitorrego.oem.smartsigninvisitor.UserDetails}: java.lang.NullPointerException
..........
Caused by: java.lang.NullPointerException
at android.content.ContextWrapper.openFileInput(ContextWrapper.java:191)
at com.visitorrego.oem.smartsigninvisitor.LoadUserDetails.LoadMethod(LoadUserDetails.java:31)
at com.visitorrego.oem.smartsigninvisitor.UserDetails.onCreate(UserDetails.java:37)
I've tried using Context and the ContextWrapper error disappears but i still get the others :(
I know its something to do with calling a method using OpenFileInput from a different class.
I don't have an issue with calling the postrequest method in my webrequest class...
Any ideas?
Can post more code if needed.
As I can understand from your code, the class LoadUserDetails is not an activity,
so probably you might need to change the
public class LoadUserDetails extends AppCompatActivity
to
public class LoadUserDetails
Send The Context as parameter from the page you're calling. Because the context is initialized normally onCreate() (usually for activities).
the function will be
public String LoadMethod(Context context){
....
FileInputStream fileInputStream = context.openFileInput("name_file");
....
}
and you can call it by
LoadUserDetails load = new LoadUserDetails();
load.LoadMethod(getApplicationContext());
I'm trying to get images for list view using Volley Library. I created simple HTTP helper with the following method.
/**
* Processing Image request and gets the image with given URL
*/
public Bitmap makeImageRequest(String url) {
ImageLoader il = new ImageLoader(queue, new BitmapLruCache());
il.get(url, new ImageLoader.ImageListener() {
#Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
mBitmap = processImageResponse(response);
}
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(Constants.Global.ERROR, "Error: " + error.getMessage());
mBitmap = null;
}
});
return mBitmap;
}
But problem is that:
new BitmapLruCache()
Method is not recognized.
So i tried to create ImageLoader using the following code which i found on the URL:
http://www.androidhive.info/2014/05/android-working-with-volley-library-1/
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
But in thos code i cannot find out where to get
AppController
Because the method code is triggered from the custom
public class HttpHelperClass
And called from the activity using the:
// Try to load remote image from URL
Bitmap bm = http.makeImageRequest("http://camranger.com/wp-content/uploads/2014/10/Android-Icon.png");
ImageView iv = (ImageView) findViewById(R.id.imageView);
iv.setImageBitmap(bm);
Is it the right approach how to load images and how can i repair my code to make succcessfull request?
Many thanks for any advice.
I think your makeImageRequest method will always return null because it takes some time for the onResponse or onErrorResponse listeners to get called but you return the mBitmap immidately!
If you want to use Volley's ImageLoader you'd better get image inside your activity or ... not from another class like your HttpHelperClass.
Also AppController is a class that extends Application and you should create it yourself. (It's in your AndroidHive link. Section 3. Creating Volley Singleton class)
And also for caching images you should not create a new ImageLoader everytime because in this way the caching gets meaningless. You should get that from your AppController class.
Furthermore I suggest you using Picasso because it's way better that Volley in image loading and a lot easier!
With Picasso you only need to call the following line to load an image from web into an ImageView:
Picasso.with(context).load(urlString).to(imageView);
I'm creating the app where i have to display multiple URI's the user has chosen from their own images, currently i'm just trying to display one:
Current code:
(TouchImageView is just a library i'm used that works exactly like imageview)
TouchImageView img = (TouchImageView) findViewById(R.id.img);
img.setImageURI(Uri.parse("file://storage/emulated/0/DCIM/Camera/1411724483755.jpg"));
I have also tried parsing the URI to a bitmap but i can't get it to work.
You may not want to use setImageURI - as the documentation points out, this will decode the image on the UI thread, which is usually not a good idea.
Depending on the rest of the context, I'd suggest using an AsyncTask to load the file into a Bitmap on a separate thread, then after that is done, you can use ImageView.setImageBitmap on the UI thread.
So for example, something like this:
private class ImageLoadTask extends AsyncTask<Uri, Void, Bitmap> {
#Override
protected Bitmap doInBackground(Uri... uris) {
return BitmapFactory.decodeFile(uris[0].getPath());
}
#Override
protected void onPostExecute(Bitmap bmp) {
mImageView.setImageBitmap(bmp);
}
}
...
mImageView = (TouchImageView)findViewById(R.id.img);
new ImageLoadTask.execute(uri);
okay the answer was to parse it as a file and do a .toString()
This is the code that works:
TouchImageView img = (TouchImageView) findViewById(R.id.img);
img.setImageURI(Uri.parse((new File("file://storage/emulated/0/DCIM/Camer/1411724483755.jpg").toString())));
i need to pick multiple videos from gallery, and I've implemented a custom gallery starting from https://github.com/luminousman/MultipleImagePick .
When i'm loading thumbnails in the adapter, it gives me OutOfMemoryException after i starti the gallery Activity twice sequentially.
The code on adapter:
VideoThumbnailImageLoader thumb=
new VideoThumbnailImageLoader(
thumbPath,
MediaStore.Video.Thumbnails.MICRO_KIND);
holder.imgQueue.setImage(thumb,
R.drawable.no_media);
and the VideoThumbnailImageLoader code:
public class VideoThumbnailImageLoader implements SmartImage {
private String videoPath;
private int thumbnailKind;
public VideoThumbnailImageLoader(String videoPath, int thumbnailKind) {
this.videoPath=videoPath;
this.thumbnailKind=thumbnailKind;
}
#Override
public Bitmap getBitmap(Context ctxt) {
return ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Images.Thumbnails.MICRO_KIND);
}
}
I'm using http://loopj.com/android-smart-image-view/ to load video thumbnail.
How can I avoid that?
Set android:largeHeap="true" in your activity proAndroidManifest.xml