android - Why Imageloader is not working? -
i want show images in view
pager
. have created classpageradapter
, usingimageloader library
fetch images internet nothing appears on screen.my log cat 1 line in red:
02-08 12:34:12.582 3560-3560/? e/libegl: call opengl es api no current context (logged once per thread)
my pager adapter
class:
package autogenie.dg10; import android.content.context; import android.support.v4.view.pageradapter; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import android.widget.linearlayout; import com.nostra13.universalimageloader.core.imageloader; import com.nostra13.universalimageloader.core.imageloaderconfiguration; import java.util.list; public class pageradapter extends pageradapter { context mcontext; layoutinflater mlayoutinflater; list<string> l = mainactivity.list; imageloader mimageloader; public pageradapter(context context) { mcontext = context; mlayoutinflater = (layoutinflater) mcontext.getsystemservice(context.layout_inflater_service); } @override public int getcount() { return 4; } @override public object instantiateitem(viewgroup container, int position) { view itemview = mlayoutinflater.inflate(r.layout.img, container, false); imageloader mimageloader = imageloader.getinstance(); mimageloader.init(imageloaderconfiguration.createdefault(mcontext)); imageview imageview = (imageview) itemview.findviewbyid(r.id.imageview3); mimageloader.displayimage("http://www.airtel.in/4g/images/airtel_4g_hotspot_responsive.jpg", imageview); container.addview(itemview); return itemview; } @override public void destroyitem(viewgroup container, int position, object object) { container.removeview((linearlayout) object); } @override public boolean isviewfromobject(view view, object object) { return view==object; } }
myapplication class:
package autogenie.dg10; import android.app.application; import android.content.context; import android.os.build; import android.os.strictmode; import android.provider.syncstatecontract; import com.nostra13.universalimageloader.cache.disc.naming.md5filenamegenerator; import com.nostra13.universalimageloader.cache.memory.impl.weakmemorycache; import com.nostra13.universalimageloader.core.displayimageoptions; import com.nostra13.universalimageloader.core.imageloader; import com.nostra13.universalimageloader.core.imageloaderconfiguration; import com.nostra13.universalimageloader.core.assist.imagescaletype; import com.nostra13.universalimageloader.core.assist.queueprocessingtype; import com.nostra13.universalimageloader.core.display.fadeinbitmapdisplayer; public class myapplication extends application { @override public void oncreate() { super.oncreate(); initimageloader(getapplicationcontext()); } public static void initimageloader(context context) { // configuration tuning custom. can tune every option, may tune of them, // or can create default configuration // imageloaderconfiguration.createdefault(this); // method. imageloaderconfiguration.builder config = new imageloaderconfiguration.builder(context); config.threadpriority(thread.norm_priority - 2); config.denycacheimagemultiplesizesinmemory(); config.diskcachefilenamegenerator(new md5filenamegenerator()); config.diskcachesize(50 * 1024 * 1024); // 50 mib config.tasksprocessingorder(queueprocessingtype.lifo); config.writedebuglogs(); // remove release app // initialize imageloader configuration. imageloader.getinstance().init(config.build()); } }
mainactivity class:
package autogenie.dg10; import android.content.context; import android.support.annotation.nonnull; import android.support.v4.view.viewpager; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log; import android.widget.gridview; import android.widget.toast; import com.nostra13.universalimageloader.cache.memory.impl.weakmemorycache; import com.nostra13.universalimageloader.core.displayimageoptions; import com.nostra13.universalimageloader.core.imageloader; import com.nostra13.universalimageloader.core.imageloaderconfiguration; import com.nostra13.universalimageloader.core.assist.imagescaletype; import com.nostra13.universalimageloader.core.display.fadeinbitmapdisplayer; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import java.io.file; import java.io.filenotfoundexception; import java.io.ioexception; import java.io.inputstream; import java.util.arraylist; import java.util.collection; import java.util.iterator; import java.util.list; import java.util.listiterator; import java.util.scanner; public class mainactivity extends appcompatactivity { inputstream i; string thestring = ""; static list<string> list = new arraylist<>(); context mcontext = this; jsonarray k; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); try { = getassets().open("swipperesponse.json"); } catch (ioexception e) { } scanner scanner = new scanner(i, "utf-8"); while (scanner.hasnext()) { thestring = thestring + scanner.next(); } try { jsonobject js = new jsonobject(thestring); k = js.getjsonarray("swipe"); (int = 0; < k.length(); i++) { try { jsonobject oneobject = k.getjsonobject(i); // pulling items array // toast.maketext(this,oneobject.getstring("productimageurl"), toast.length_long).show(); string d = oneobject.getstring("productimageurl"); list.add(i, d); int l = 0; int u = 0; } catch (jsonexception e) { // oops } } } catch (exception e) { e.printstacktrace(); } pageradapter p = new pageradapter(this); viewpager mviewpager = (viewpager) findviewbyid(r.id.view); mviewpager.setadapter(p); } }
i unable figure out wrong. no errors have been reported while running
app
.
img.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <imageview android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/imageview3" android:layout_alignparenttop="true" android:layout_alignparentstart="true" android:layout_margintop="225dp" /> </linearlayout>
androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="autogenie.dg10"> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.write_external_storage" /> <application android:name=".myapplication" android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
mainactivity.xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="autogenie.dg10.mainactivity"> <linearlayout android:weightsum="2" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="270dp" android:id="@+id/linearlayout4" android:layout_below="@+id/view" android:layout_alignparentstart="true"> <linearlayout android:layout_weight="1" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="150dp" android:layout_alignparentbottom="true" android:weightsum="2" android:id="@+id/linearlayout3" android:layout_alignend="@+id/linearlayout2" android:layout_alignparentstart="true" android:layout_marginbottom="10dp"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/imageview5" android:background="@drawable/a" android:layout_marginright="10dp" /> <imageview android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/imageview6" android:layout_gravity="bottom" android:background="@drawable/aa" android:layout_marginleft="10dp" /> </linearlayout> <linearlayout android:layout_weight="1" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="150dp" android:weightsum="2" android:layout_alignparentend="true" android:id="@+id/linearlayout" android:layout_alignparentstart="true" android:layout_margintop="10dp"> <imageview android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/imageview" android:background="@drawable/aaa" android:baselinealignbottom="false" android:layout_marginright="10dp" /> <imageview android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/imageview2" android:layout_gravity="bottom" android:background="@drawable/aaaa" android:visibility="visible" android:layout_marginleft="10dp" /> </linearlayout> </linearlayout> <android.support.v4.view.viewpager android:layout_width="wrap_content" android:layout_height="200dp" android:id="@+id/view" android:layout_centerhorizontal="true" /> <horizontalscrollview android:layout_width="match_parent" android:layout_height="20dp" android:id="@+id/horizontalscrollview" android:layout_alignparentbottom="true" android:layout_alignparentstart="true" android:layout_alignend="@+id/linearlayout4" android:layout_below="@+id/linearlayout4" /> </relativelayout>
my log cat:
02-08 12:34:12.374 3560-3560/? w/dalvikvm: vfy: unable find class referenced in signature (landroid/view/searchevent;) 02-08 12:34:12.374 3560-3560/? i/dalvikvm: not find method android.view.window$callback.onsearchrequested, referenced method android.support.v7.view.windowcallbackwrapper.onsearchrequested 02-08 12:34:12.374 3560-3560/? w/dalvikvm: vfy: unable resolve interface method 16217: landroid/view/window$callback;.onsearchrequested (landroid/view/searchevent;)z 02-08 12:34:12.374 3560-3560/? i/dalvikvm: not find method android.view.window$callback.onwindowstartingactionmode, referenced method android.support.v7.view.windowcallbackwrapper.onwindowstartingactionmode 02-08 12:34:12.374 3560-3560/? w/dalvikvm: vfy: unable resolve interface method 16221: landroid/view/window$callback;.onwindowstartingactionmode (landroid/view/actionmode$callback;i)landroid/view/actionmode; 02-08 12:34:12.378 3560-3560/? i/dalvikvm: not find method android.content.res.typedarray.getchangingconfigurations, referenced method android.support.v7.widget.tinttypedarray.getchangingconfigurations 02-08 12:34:12.378 3560-3560/? w/dalvikvm: vfy: unable resolve virtual method 414: landroid/content/res/typedarray;.getchangingconfigurations ()i 02-08 12:34:12.382 3560-3560/? i/dalvikvm: not find method android.content.res.typedarray.gettype, referenced method android.support.v7.widget.tinttypedarray.gettype 02-08 12:34:12.382 3560-3560/? w/dalvikvm: vfy: unable resolve virtual method 436: landroid/content/res/typedarray;.gettype (i)i 02-08 12:34:12.394 3560-3560/? i/dalvikvm-heap: grow heap (frag case) 3.753mb 1125052-byte allocation 02-08 12:34:12.414 3560-3560/? i/dalvikvm-heap: grow heap (frag case) 8.041mb 4500172-byte allocation 02-08 12:34:12.458 3560-3560/? i/dalvikvm-heap: grow heap (frag case) 12.334mb 4500172-byte allocation 02-08 12:34:12.494 3560-3560/? i/dalvikvm-heap: grow heap (frag case) 16.627mb 4500172-byte allocation 02-08 12:34:12.538 3560-3560/? i/dalvikvm-heap: grow heap (frag case) 20.920mb 4500172-byte allocation 02-08 12:34:12.582 3560-3560/? e/libegl: call opengl es api no current context (logged once per thread) 02-08 12:34:12.626 3560-3560/? w/egl_genymotion: eglsurfaceattrib not implemented
why u calling imageloader.init()
twice .
remove line instantiateitem
method
mimageloader.init(imageloaderconfiguration.createdefault(mcontext));
the image u trying load doesnt not exist
http://www.airtel.in/4g/images/airtel_4g_hotspot_responsive.jpg
this path shows 403 error
Comments
Post a Comment