I am trying to parse an XML file in a stream inside a fragment.
A partial snippet of my code:
public void onCreate(Bundle savedInstanceState)
{
mAdapter = new ListItemNearbyStoresAdapter(getActivity().getApplicationContext(), mStoresByKey);
setListAdapter(mAdapter);
loadStoresByThread(getActivity().getApplicationContext());
}
private void loadStoresByThread(final Context ctx)
{
Thread t = new Thread()
{
public void run()
{
try
{
Log.d(TAG, "In the thread");
String[] files = ctx.getResources().getStringArray(R.array.storefiles);
for (int i = 0; i < files.length; i++)
{
try
{
InputStream stream = getActivity().getAssets().open(files[i]);
NearbyItemDomFeedParser parser = new NearbyItemDomFeedParser(stream);
ArrayList<Store> stores = parser.parse();
Log.e("no of fioles read","asd :"+stores.size());
mStores.addAll(stores);
cache.setItems(mStores);
}
catch (Exception e)
{
Log.d(TAG, "Exception caught" + e);
}
}
}
}
Note that this entire class extends the list fragment.
Is access to resources correct inside the fragment?
The reason I can not read the file.
There are no exceptions, so I can not determine the exact error.
But finally, after parsing using the builder, I get 0 elements.
Any suggestions?
source
share