在我的代码中我只使用了两个listview和两个CustomAdapter用于这两个listView,其中第一个listview是通过CustomAdapter实现的,从这个CustomAdapter我只想调用另一个(Activity / Other自定义适配器用于第二个listview).It给出像
这样的例外java.lang.IllegalStateException: 无法使用的系统服务 onCreate()之前的活动
private LayoutInflater mInflater;
ViewFlipper vfWall;
ImageView ivComments;
TextView tvComments;
ListView lvComments;
WallCustom2 adapterForComments;
ImageDownloader imageDownloader = new ImageDownloader();
private static final String[] URLS =
{
"http://lh5.ggpht.com/_mrb7w4gF8Ds/TCpetKSqM1I/AAAAAAAAD2c/Qef6Gsqf12Y/s144-c/_DSC4374%20copy.jpg",
};
String[] itms={"hey dude kya kar raha hai.........."};
public WallCustom(Context context,ViewFlipper vfWall,ImageView ivComments,TextView tvComments,ListView lvComments)
{
this.ivComments=ivComments;
this.tvComments=tvComments;
this.lvComments=lvComments;
this.mInflater = LayoutInflater.from(context);
this.vfWall=vfWall;
}
public int getCount()
{
return URLS.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.wallcustom, null);
holder = new ViewHolder();
holder.Image = (ImageView) convertView.findViewById(R.id.ivImageWallCustom);
holder.Message= (TextView) convertView.findViewById(R.id.tvMessageWallCustom);
holder.comments= (TextView) convertView.findViewById(R.id.tvExtraWallCustom);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
if(imageDownloader.download(URLS[position],holder.Image)!=null)
{
holder.Image.setImageBitmap( imageDownloader.download(URLS[position],holder.Image));
}
holder.Message.setText("hey dude kya kar raha hai..........");
holder.comments.setText("Comments ");
holder.comments.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(imageDownloader.download(URLS[position],ivComments)!=null)
{
ivComments.setImageBitmap( imageDownloader.download(URLS[position],ivComments));
}
tvComments.setText(itms[position]);
Wall wallobj=new Wall();
adapterForComments=wallobj.ListViewForComments(); // gives object of second custom adapter
lvComments.setAdapter(adapterForComments); // lvComments my second list view in which i want to set second custom adapter
vfWall.showNext();
}
});
return convertView;
}
class ViewHolder
{
ImageView Image;
TextView Message;
TextView comments;
}
答案 0 :(得分:1)
java.lang.IllegalStateException: System services not available to Activities before onCreate()
该错误消息非常简单。您正尝试从活动的构造函数或初始值设定项中使用系统服务,例如LayoutInflater
。最早在LayoutInflater
之前不要尝试使用onCreate()
。
答案 1 :(得分:0)
您可能正在使用无法使用的systemServide(InflaterService),直到调用oncreate()事件。所以控制台错误信息很容易理解。