没有得到listview.i中的显示数据完全解析器列表成功但与listview的服装适配器集成得到挫折。我不认为解析器中的问题它在logcat中获得成功但是现在延迟加载和显示问题都会提高。
错误:
11-02 12:10:58.470: WARN/PackageManager(613): Failure retrieving icon 0x7f020000 in package com.SAXParser1
11-02 12:10:58.470: WARN/PackageManager(613): android.content.res.Resources$NotFoundException: Resource ID #0x7f020000
11-02 12:10:58.470: WARN/PackageManager(613): at android.content.res.Resources.getValue(Resources.java:846)
11-02 12:10:58.470: WARN/PackageManager(613): at android.content.res.Resources.getDrawable(Resources.java:534)
11-02 12:10:58.470: WARN/PackageManager(613): at android.app.ApplicationContext$ApplicationPackageManager.getDrawable(ApplicationContext.java:1923)
11-02 12:10:58.470: WARN/PackageManager(613): at android.content.pm.ComponentInfo.loadIcon(ComponentInfo.java:88)
11-02 12:10:58.470: WARN/PackageManager(613): at com.android.launcher.LauncherModel.updateApplicationInfoTitleAndIcon(LauncherModel.java:452)
11-02 12:10:58.470: WARN/PackageManager(613): at com.android.launcher.LauncherModel.updateAndCacheApplicationInfo(LauncherModel.java:257)
11-02 12:10:58.470: WARN/PackageManager(613): at com.android.launcher.LauncherModel.updatePackage(LauncherModel.java:242)
11-02 12:10:58.470: WARN/PackageManager(613): at com.android.launcher.Launcher$ApplicationsIntentReceiver.onReceive(Launcher.java:1865)
11-02 12:10:58.470: WARN/PackageManager(613): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:664)
11-02 12:10:58.470: WARN/PackageManager(613): at android.os.Handler.handleCallback(Handler.java:587)
11-02 12:10:58.470: WARN/PackageManager(613): at android.os.Handler.dispatchMessage(Handler.java:92)
11-02 12:10:58.470: WARN/PackageManager(613): at android.os.Looper.loop(Looper.java:123)
11-02 12:10:58.470: WARN/PackageManager(613): at android.app.ActivityThread.main(ActivityThread.java:3948)
11-02 12:10:58.470: WARN/PackageManager(613): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 12:10:58.470: WARN/PackageManager(613): at java.lang.reflect.Method.invoke(Method.java:521)
11-02 12:10:58.470: WARN/PackageManager(613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
11-02 12:10:58.470: WARN/PackageManager(613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
11-02 12:10:58.470: WARN/PackageManager(613): at dalvik.system.NativeStart.main(Native Method)
代码::
package com.SAXParser1;
import java.net.URL;
import java.util.ArrayList;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class SAXParser1 extends Activity implements OnItemClickListener {
/** Called when the activity is first created. */
String RequestID;
String Status;
String URL1;
String ActivityName;
String AudioScript;
ListView lview;
String[] Arr_RequestID;
String[] Arr_Status;
String[] Arr_ActivityName;
String[] Arr_AudioScript;
ArrayList<String> al_RequestID;
ArrayList<String> al_Status;
ArrayList<String> al_ActivityName;
ArrayList<String> al_AudioScript;
ListViewAdapter lviewAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String url = "URL";
SaxParser(url);
try {
lview = (ListView) findViewById(R.id.listView2);
lviewAdapter = new ListViewAdapter(this, Arr_ActivityName,
Arr_AudioScript);
System.out.println("adapter => " + lviewAdapter.getCount());
lview.setAdapter(lviewAdapter);
lview.setOnItemClickListener(this);
} catch (Exception e) {
// TODO: handle exception
}
}
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long id) {
}
public void SaxParser(String url) {
try {
URL sourceUrl = new URL(url);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
Handler1 dataHandler = new Handler1();
xr.setContentHandler(dataHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
Dataset dataset = dataHandler.getParsednewJobdtl_DataSet();
Toast.makeText(getBaseContext(), "sourceUrl" + sourceUrl,
Toast.LENGTH_LONG);
RequestID = dataset.getRequestID();
/*System.out.println(RequestID);*/
al_ActivityName = dataHandler.getActivityName();
al_AudioScript = dataHandler.getAudioScript();
al_RequestID = dataHandler.getRequestId();
al_Status = dataHandler.getStatus();
Arr_ActivityName = al_ActivityName
.toArray(new String[al_ActivityName.size()]);
Arr_AudioScript = al_AudioScript.toArray(new String[al_AudioScript
.size()]);
Arr_RequestID = al_RequestID
.toArray(new String[al_RequestID.size()]);
Arr_Status = al_Status.toArray(new String[al_Status.size()]);
Toast.makeText(getBaseContext(), "al_Status " + al_RequestID,
Toast.LENGTH_LONG);
Status = dataset.getStatus();
Toast.makeText(getBaseContext(), "al_Status " + al_Status,
Toast.LENGTH_LONG);
ActivityName = dataset.getActivityName();
Toast.makeText(getBaseContext(), "al_ActivityName " + al_ActivityName,
Toast.LENGTH_LONG);
AudioScript = dataset.getAudioScript();
Toast.makeText(getBaseContext(), "al_AudioScript " + al_AudioScript,
Toast.LENGTH_LONG);
} catch (Exception e) {
e.printStackTrace();
}
}
}
ListViewAdapter ::
package com.SAXParser1;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class ListViewAdapter extends BaseAdapter {
Activity context;
String title[];
String description[];
public ListViewAdapter(Activity context, String[] title,
String[] description) {
super();
this.context = context;
this.title = title;
this.description = description;
}
public int getCount() {
// TODO Auto-generated method stub
return title.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
private class ViewHolder {
TextView txtViewTitle;
TextView txtViewDescription;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.listitem_row, null);
holder = new ViewHolder();
holder.txtViewTitle = (TextView) convertView
.findViewById(R.id.textView1);
holder.txtViewDescription = (TextView) convertView
.findViewById(R.id.textView2);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtViewTitle.setText(title[position]);
holder.txtViewDescription.setText(description[position]);
return convertView;
}
}
答案 0 :(得分:4)
带图像的惰性列表的简单演示。可能对某人有帮助。它在后台线程中下载图像。图像正在缓存在SD卡和内存中。我只创建一个线程并将下载任务放入队列。我认为这比多个线程同时下载和解码图像更有效。缓存实现非常简单,足以用于演示。我用inSampleSize解码图像以减少内存消耗。我也尝试正确处理回收的视图。
答案 1 :(得分:3)
使用project->clean
清理项目,并确保已在项目菜单中选中“自动构建”。
仅供参考,只需检查Resources.NotFoundException,就会明确写出,只要找不到请求资源,就会引发此异常,因此检查您必须尝试在代码中使用的图标会更好。如果在R.java文件中找不到相同图标的id,则按上述方式重新生成R.java。
答案 2 :(得分:2)
为了避免混淆,如果你遵循普通的Java命名约定可能会有所帮助 - 这只是一个建议,但你的包名com.SAXParser1
非标准(以大写字母开头并包含大写字母,仅使用com
而不是您的完整域名,但更重要的是,它与您的类名称相同,这可能会导致混淆(至少让我感到困惑,我试图阅读您的代码......; - )。
您发布的堆栈跟踪似乎表明Android期望ID为0x7f020000
的资源,即如下所示的行:
public static final int <some_name>=0x7f020000
在您的R文件中(public static final class drawable
内的某处)。尝试打开该文件(Ctrl + Shift + T,然后键入“com.SAXParser1.R”)并对0x7f020000
进行文本搜索。如果您的R文件已损坏,请尝试右键单击该项目并转到“Android工具” - &gt; “修复项目属性”。
修改:查看this post以获取其他一些建议。如果通过右键单击项目并选择Refresh
(在Indigo中没有必要,我相信,但在Helios及以下版本中始终存在问题)确保您的文件和Eclipse同步,这也可能有所帮助。