- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我得到了错误:
ImageLoader must be init with configuration before using is the error from Illegal State Exception.
我在将 gridview 放在 fragment 中的方法中努力显示图像。至于我的理解,imageLoader
应该首先通过扩展将扩展 BaseActivity
的类 AbsListViewBaseActivity 来初始化。
这两个类用于初始化imageLoader
。我把流程搞砸了,我在运行时遇到错误,两天内一直在处理这个问题。我将包含 LogCat 错误。
我自己的版本
--主类
import com.nostra13.universalimageloader.core.ImageLoader;
import com.folder.folder.AbsListViewBaseActivity;
public class CollectionDemoActivity extends FragmentActivity{
assignImageLoader newAssign;
static AbsListViewBaseActivity absList;
static ImageAdapter m3;
Oncreate()
{
newAssign = assignImageLoader;
m3 = ImageAdapter();
((GridView) absList.listView).setAdapter(m3);
}
}
/**
* A dummy fragment representing a section of the app, but that simply displays dummy text.
*/
public static class DemoObjectFragment extends Fragment {
public static final String ARG_OBJECT = "object";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.ac_image_grid, container, false);
List<Menu> itemsDatabase = db.getItemsAsArray("items");
List<String> items = new ArrayList<String>();
for (Menu cn : itemsDatabase) {
HashMap<String, String> map = new HashMap<String, String>();
items.add(cn.getImagePath().toString());
values2.add(map);
}
imageUrls = items.toArray(new String[items.size()]);
options2 = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheInMemory(true)
.cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
absList.listView = (GridView)rootView.findViewById(R.id.gridview);
((GridView) absList.listView).setAdapter(m3);
absList.listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//startImagePagerActivity(position);
//Toast.makeText(getBaseContext(), "Clieckeed", Toast.LENGTH_SHORT).show();
//Log.d("Inside Onclick:", view.toString());
}
});
return rootView;
}
}
class ImageAdapter extends BaseAdapter {
@Override
public int getCount() {
return imageUrls.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
// Assign Values
holder.name.setText(values2.get(position).get(TAG_NAME2 ).toString());
holder.price.setText("Price: " + values2.get(position).get(TAG_PRICE2).toString());
holder.br.setStepSize(1);
holder.br.setFocusable(false);
Log.d("Image Path Value in GridViewdd: ", values2.get(position).get(TAG_IMAGE_NAME2).toString());
newAssign.getImageLoader("Image Path", holder.image, options2);
return view;
}
class ViewHolder {
public TextView name;
public TextView price;
public ImageView image;
public RatingBar br;
}
}
static class assignImageLoader extends AbsListViewBaseActivity{
static ImageLoader mg;
assignImageLoader()
{
mg = imageLoader;
}
public void getImageLoader(String path, ImageView img, DisplayImageOptions options)
{
imageLoader.displayImage(path, img, options);
}
}
程序的原始实现和流程
--主类
public class ImageGridActivity extends AbsListViewBaseActivity {
onCreate()
{
((GridView) listView).setAdapter(new ImageAdapter());
}
public class ImageAdapter extends BaseAdapter {
public View getView(final int position, View convertView, ViewGroup parent) {
imageLoader.displayImage(path, holder.image, options2);
}
}
}
--AbsListViewBaseActivity
public class AbsListViewBaseActivity extends BaseActivity {
protected static final String STATE_PAUSE_ON_SCROLL = "STATE_PAUSE_ON_SCROLL";
protected static final String STATE_PAUSE_ON_FLING = "STATE_PAUSE_ON_FLING";
public AbsListView listView;
protected boolean pauseOnScroll = false;
protected boolean pauseOnFling = true;
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
pauseOnScroll = savedInstanceState.getBoolean(STATE_PAUSE_ON_SCROLL, false);
pauseOnFling = savedInstanceState.getBoolean(STATE_PAUSE_ON_FLING, true);
}
@Override
public void onResume() {
super.onResume();
applyScrollListener();
}
private void applyScrollListener() {
listView.setOnScrollListener(new PauseOnScrollListener(imageLoader, pauseOnScroll, pauseOnFling));
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(STATE_PAUSE_ON_SCROLL, pauseOnScroll);
outState.putBoolean(STATE_PAUSE_ON_FLING, pauseOnFling);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem pauseOnScrollItem = menu.findItem(R.id.item_pause_on_scroll);
pauseOnScrollItem.setVisible(true);
pauseOnScrollItem.setChecked(pauseOnScroll);
MenuItem pauseOnFlingItem = menu.findItem(R.id.item_pause_on_fling);
pauseOnFlingItem.setVisible(true);
pauseOnFlingItem.setChecked(pauseOnFling);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item_pause_on_scroll:
pauseOnScroll = !pauseOnScroll;
item.setChecked(pauseOnScroll);
applyScrollListener();
return true;
case R.id.item_pause_on_fling:
pauseOnFling = !pauseOnFling;
item.setChecked(pauseOnFling);
applyScrollListener();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
基础 Activity
public abstract class BaseActivity extends Activity {
public ImageLoader imageLoader = ImageLoader.getInstance();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
//Added in the code by me for handling the init error
imageLoader.init(ImageLoaderConfiguration.createDefault(getBaseContext()));
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item_clear_memory_cache:
imageLoader.clearMemoryCache();
return true;
case R.id.item_clear_disc_cache:
imageLoader.clearDiscCache();
return true;
default:
imageLoader.destroy();
return false;
}
}
}
Logcat:
07-19 11:28:26.909: E/AndroidRuntime(24023): FATAL EXCEPTION: main
07-19 11:28:26.909: E/AndroidRuntime(24023): java.lang.IllegalStateException: ImageLoader must be init with configuration before using
07-19 11:28:26.909: E/AndroidRuntime(24023): at com.nostra13.universalimageloader.core.ImageLoader.checkConfiguration(ImageLoader.java:325)
07-19 11:28:26.909: E/AndroidRuntime(24023): at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:170)
07-19 11:28:26.909: E/AndroidRuntime(24023): at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:134)
07-19 11:28:26.909: E/AndroidRuntime(24023): at com.jinisys.restoplusordering.CollectionDemoActivity$assignImageLoader.getImageLoader(CollectionDemoActivity.java:448)
07-19 11:28:26.909: E/AndroidRuntime(24023): at com.jinisys.restoplusordering.CollectionDemoActivity$ImageAdapter.getView(CollectionDemoActivity.java:424)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.widget.AbsListView.obtainView(AbsListView.java:2267)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.widget.GridView.onMeasure(GridView.java:1030)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.View.measure(View.java:15181)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.View.measure(View.java:15181)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1447)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.View.measure(View.java:15181)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.View.measure(View.java:15181)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.View.measure(View.java:15181)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-19 11:28:26.909: E/AndroidRuntime(24023): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.os.Handler.handleCallback(Handler.java:615)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.os.Handler.dispatchMessage(Handler.java:92)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.os.Looper.loop(Looper.java:137)
07-19 11:28:26.909: E/AndroidRuntime(24023): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-19 11:28:26.909: E/AndroidRuntime(24023): at java.lang.reflect.Method.invokeNative(Native Method)
07-19 11:28:26.909: E/AndroidRuntime(24023): at java.lang.reflect.Method.invoke(Method.java:511)
07-19 11:28:26.909: E/AndroidRuntime(24023): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-19 11:28:26.909: E/AndroidRuntime(24023): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-19 11:28:26.909: E/AndroidRuntime(24023): at dalvik.system.NativeStart.main(Native Method)
基于此方法:
最佳答案
尝试在你的 onCreateView 中实现这个:
对于 Activity -
BaseActivity.imageLoader.init(ImageLoaderConfiguration.createDefault(getBaseContext()));
对于 fragment -
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(getActivity()));
关于java - Android - 在 UIL 中使用之前,ImageLoader 必须通过配置初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17737858/
我正在寻找一种使此打印 HTML 代码 fragment 向后兼容旧 Android 版本的简单方法: @TargetApi(Build.VERSION_CODES.KITKAT) private v
我在 GCC 终端 (centos linux) 中为 ATM 项目编译以下 c 和 .h 代码时收到以下错误。请帮忙,因为我是编程新手。 validate_acc.h #ifndef _VALIDA
在写关于 SO 的不同问题的答案时,我制作了这个片段: @import url('https://fonts.googleapis.com/css?family=Shadows+Into+Light'
试图弄清楚我应该如何在 my_div_class 之前放置一个 span 而不是替换所有它。现在它取代了 div,但我不想这样做。我假设它类似于 :before 但不知道如何使用它。 { va
我正在使用选择库 http://github.hubspot.com/select/和 noUiSlider https://refreshless.com/nouislider/ .我面临的问题如下
我是开发新手,独自工作。我正在使用 Xcode 和 git 版本控制。可能我没有适本地组织和做错事,但我通常决定做 promise 只是为了在我破坏一切之前做出安全点。在那一刻,我发现很难恰本地描述我
我想确保在同一个桶和键上读取和写入时,应该更新获取的值,也就是说,应该在对其进行写入操作之后获取它。我怎样才能做到这一点? 我想要的是,如果我更新一个键的值,如果我同时使用不同线程获取值,则更新同一个
我的问题与this有关问题,已经有了答案: yes, there is a happens-before relationship imposed between actionsof the thre
The before and after hook documentation on Relish仅显示 before(:suite) 在 before(:all) 之前调用。 我什么时候应该使用其中
我有 CSV 行,我想在其中检测所有内部双引号,没有文本限定符。这几乎可以正常工作,但我的正则表达式还可以检测双引号后的字符。 CSV 部分: "7580";"Lorem ipsum";"";"Lor
是否可以通过Youtube数据API检查广告是否可以与特定视频一起显示? 我了解contentDetails.licensedContent仅显示视频是否已上传至同一伙伴然后由其声明版权。由于第三者权
考虑一下用漂亮的彩色图表描述的“像素管道” https://developers.google.com/web/fundamentals/performance/rendering/ 我有一个元素(比
之前?
在 MVC3 中,我可以轻松地将 jQuery 脚本标签移动到页面底部“_Layout.vbhtml” 但是,在 ASP.NET MVC3 中,当您使用编辑器模板创建 Controller 时,脚手
悬停时内容被替换,但是当鼠标离开元素时我希望它变回来。我该怎么做? $('.img-wrap').hover(function(){ $(this).find('h4').text('Go
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 9 年前。 有关您编写的代码问题的问题必须在问题本身中描述具体问题 - 并包含有效代码以重现该问题。
版本:qwt 6.0.1我尝试开发频谱的对数缩放。我使用简单的线条来启用缩放plotspectrum->setAxisScaleEngine(QwtPlot::yLeft, new QwtLog10S
我有两个相同的表,I_Subject 和 I_Temp_Subject,我想将 Temp_Subject 表复制到 Subject 表。 I_Temp_Subject 由简单用户使用,I_Subjec
我的印象是第一次绘制发生在触发 DOMContentLoaded 事件之后。特别是,因为我认为为了让第一次绘制发生,需要渲染树,它依赖于 DOM 构造。另外,我知道 DOM 构造完成时会触发 DOMC
我是一名优秀的程序员,十分优秀!