Android :: Loading Raw Resource Text File / Out Of Memory Error

Sep 15, 2010

I use this method couples of occasion to load text file to display as help file. But I don't know why the following code didn't work. It seems to hang and logcat says "OutOfMemoryError"? All I did was break this out as an separate activity.

---xml---
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/helptab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/helptext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>

---code---
import java.io.DataInputStream;
import java.io.IOException; import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Help extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
InputStream iFile = getResources().openRawResource(R.raw.help);
try { TextView helpText = (TextView) findViewById(R.id.helptext);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
} }
public String inputStreamToString(InputStream is) throws IOException {
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = "";
while ((strLine = dataIO.readLine()) != "") {
sBuffer.append(strLine + " ");
} dataIO.close();
is.close();
return sBuffer.toString();
}

Android :: Loading Raw Resource Text File / Out of Memory Error


Android :: Android Out Of Memory Error - Loading JSON File

May 22, 2010

The app I am working on needs to read a JSON file that may be anywhere from 1.5 to 3 MB in size. It seems to have no problem opening the file and converting the data to a string, but when it attempts to convert the string to a JSONArray, OutOfMemoryErrors are thrown. The exceptions look something like this:

E/dalvikvm-heap( 5307): Out of memory on a 280-byte allocation.
W/dalvikvm( 5307): Exception thrown (Ljava/lang/OutOfMemoryError;
) while throwing internal exception (Ljava/lang/OutOfMemoryError;)

One strange thing about this is that the crash only occurs every 2nd or 3rd time the app is run, leaving me to believe that the memory consumed by the app is not being garbage collected each time the app closes. I'm not quite sure what the best approach is for such a task.

View 2 Replies View Related

Android :: Read Text File As Resource

Sep 14, 2010

I am trying to read a file "words.txt" from a resource. It is a very simple, but large (2 MB), text file that I want to read line by line. I have put the file into /res/raw/words.txt, and try to open it with the following code:

CODE:...................

However, I get a java.io.IOException. This is not a "resource not found" exception, so the resource is opened correctly, but the readLine() produces the error.

I tried using the InputStream itself, with the result that read() produces -1, which stands for EOF, as if the file was empty.

View 1 Replies View Related

Android :: Read Text Raw Resource File?

Nov 3, 2010

I have a text file added as a raw resource. The text file contains text like:

a) IF APPLICABLE LAW REQUIRES ANY WARRANTIES WITH RESPECT TO THE SOFTWARE, ALL SUCH WARRANTIES ARE LIMITED IN DURATION TO NINETY (90) DAYS FROM THE DATE OF DELIVERY.


b) NO ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY VIRTUAL ORIENTEERING, ITS DEALERS, DISTRIBUTORS, AGENTS OR EMPLOYEES SHALL CREATE A WARRANTY OR IN ANY WAY INCREASE THE SCOPE OF ANY WARRANTY PROVIDED HEREIN.

c) (USA only) SOME STATES DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY
NOT APPLY TO YOU. THIS WARRANTY GIVES YOU SPECIFIC LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER LEGAL RIGHTS THAT VARY FROM STATE TO STATE.

On my screen I have a layout like this:

CODE:........

The code to read the raw resource is:

CODE:....

The text get's showed but after each line I get a strange character [] How can I remove that character ? I think it's New Line.

WORKING SOLUTION

CODE:....................

View 1 Replies View Related

Android :: Droid Eclipse Resource Strings Error / Alter XML File (like Suggested In Tutorials)?

Sep 6, 2010

When I make a new android project and I go to res/values/string.xml I get a screen to add android resources instead of a XML document. I keeps getting the error about : java.lang.NullPointerException.

Is there a way to just alter a XML file (like suggested in tutorials)?

View 2 Replies View Related

Android :: Out Of Memory Error .. Trying To Parse XML File

Nov 5, 2009

In my application. I tried to parse XML file. First time it executed correctly. Second time it is showing Out Of Memory Error.

My XML file contains 15000 lines.

can any one know about this?...

My log cat is given below:

CODE:................................

View 2 Replies View Related

Android :: How To Use Resource Within A Custom Xml Resource File?

Aug 3, 2010

I have an XML resource file:
<resources> <section>
<category value="1" resourceId="@xml/categoryData1" />
<category value="2" resourceId="@xml/categoryData2" />
<category value="3" resourceId="@xml/categoryData3" />
</section> </resources>
Using XmlPullParser, on the START_TAG, I can use:
int value = parser.getAttributeIntValue(null, "value", 0);
to get values 1, 2, 3...however:
int resourceId = parser.getAttributeIntValue(null, "resourceId", 0);
doesn't work...it just yields the default value 0, or whatever I change the default value (3rd parameter) to be. Does anyone know what I am doing wrong or if this is possible?

View 1 Replies View Related

Android :: Dynamic Resource Loading

Sep 5, 2010

I'm trying to find a way to open resources which name is determined at runtime only. Let me explain in more details. I want to have a XML that references a bunch of other XML files in the application apk. for the purpose of explaining lets say the main XML is main.xml and the other XML are file1.xml file2.xml...fileX.xml...

what i want is to read main.xml, extract the name of the xml I want (fileX.xml) for example. and then read fileX.XML. the problem I face is that what I extract form main.xml is a string and I can't find a way to change that to R.raw.nameOfTheFile

View 2 Replies View Related

Android :: Loading A Resource To A Mutable Bitmap

Sep 11, 2010

I am loading a bitmap from a resource like so:

Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image);

What I want to do is make some changes to the bitmap before It gets drawn to the main canvas in my draw method (As it would seem wasteful to repeat lots of drawing in my main loop when it isn't going to change). I am making the changes to the bitmap with the following:

Canvas c = new Canvas(mBackground);
c.drawARGB(...); // etc

So naturally I get an exception

java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor

So to avoid that I made a copy of the bitmap so that it is mutable

Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image).copy(Bitmap.Config.ARGB_8888, true);

Which avoid the problem however it sometimes causes OutOfMemoryExceptions, do know any better ways of achieving what I want?

View 2 Replies View Related

Android :: Loading & Displaying Image From A Resource

Apr 29, 2010

Currently I'm successfully loading and displaying an image from a webserver using the code below.

URL imgURL = new URL("http://www.xxx.com/myimage.png"); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm= BitmapFactory.decodeStream(bis); bis.close(); is.close();

canvas.drawBitmap(bm, 0, 0, null);

What I want to do is load it from a resource. I've put myimage.png into res/drawable and referenced the bitmap as follows :-

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.myimage);

However when I try to display it with canvas.drawBitmap(bm, 0, 0, null); I get a Force Close. What am I missing?

View 2 Replies View Related

Android :: Loading Resource Represented By R.attr.*

Nov 6, 2010

I want to load resource that is located in android.R.attr class.Next code failed to load resource with Resources$NotFoundException exception:

getResources().getString(android.R.attr.action); //action is a string resource

Also tried to load resource using:

getResources().obtainAttributes(android.R.attr.action)

No exception is thrown, but returned TypedArray array has nothing valuable inside it. At least I couldn't find anything that is connected to actual resource id or resource I'm interested in.So, how to load resources represented by android.R.attr.* ids?

View 1 Replies View Related

Android :: Will Threaded Resource Loading Improve Throughput - Or Just Responsiveness

Oct 13, 2010

Are there any Android phones that are multi-processor (multi-core/ cpu), where application threads execute concurrently on different processors?

There doesn't seem to be any explicit way of doing asynchronous file I/ O or asynchronous resource loading. So, suppose I put BitmapFactory.decodeResource() or Resources.openRawResource() into a separate thread. Will those methods play nice with the other threads, yielding during blocking I/O operations so those other threads can run?

If those methods rely on the thread scheduler to forcibly suspend them, then the separate resource-loading thread isn't going to help me get my application started any faster (although it will help it to be more responsive to user input).

View 5 Replies View Related

Error Trying To Read Text File And Put It Into XML Textview

Sep 13, 2012

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);

[Code]....

There is my code. The problem is with the inputStreamToString(iFile).It says that it is undefined. Im working my way through an android book and that is exactlly out of the book. I have looked around and tried a few different ways but cant seem to make it open the quizhelp file and display it in the TextView_QuizHelp.

View 1 Replies View Related

Android :: Memory / Resource Leak With Application

Nov 24, 2009

I am experiencing a memory / resource leak on a T-Mobile G1 device with my application. I installed the "Task Manager" application from Android market and my memory usage is not monotonically increasing. It stays relatively flat over time. Furthermore, none of the other processes are chewing up tons of memory either (really, I can get into this state with just my app running). I am not experiencing this problem on any of the other Android phones (including Eris, Hero, and Droid).

The interesting thing is that if I kill my application, the phone is *still* very slow and sluggish. The only thing that seems to be able to get me out of this situation is a battery pull. If I run my application for about 3 hours, the phone starts to become very sluggish. Even simple operations like hitting the "home" button take many seconds. I'm not sure what to do at this point and am wondering where I can go from here.

View 3 Replies View Related

Android :: Drawable Resource Loaded To Memory?

Oct 19, 2010

Does all resource (all in res folder if on eclipse IDE), specially drawable image, is loaded to memory during runtime? Or it is just like a file which is available when the application need it?

View 1 Replies View Related

Android :: No Resource Found Error

May 24, 2010

I got "no resource found that matches the given name(at 'id' with value @id+/textview')" my main.xml file looks like this: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android=" http://schemas.android.com /apk/res/android" android:id="@id+/textview" android:layout_width="fill_parent" android:layout_ height="fill_parent" android:text="@string/greetings"/> Any idea what I am missing? You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+ unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com /group/android-developers?hl=en

View 3 Replies View Related

Android :: Error - No Resource Found That Matches Given Name

Jul 16, 2010

I am new to android, I try to create layout so that I have background image, and have a ImageView with animation start from bottom right of screen and along with a TextView stay on top of this ImageView. (Hope my describe make sense).

My problem is when I try use "android:layout_above="@id/flyobject"", the eclipse alway say: error: Error: No resource found that matches the given name (at 'layout_above' with value '@id/flyobject'). But as for sure I have defined flyobject, and I can find it's in my R class.

Here is my XML file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ android"android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@+id/background"android:src = "@drawable/background"android:layout_width="fill_parent"android:layout_height="fill_parent" android:scaleType="centerCrop"/>
<TextViewandroid:id="@+id/flytext"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/flyobject"/>
<ImageViewandroid:id="@+id/flyobject"android:src="@drawable/asteroid01"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_alignParentBottom="true"/> </RelativeLayout>

View 3 Replies View Related

Android :: Error Creating Gen Resource Folder

Nov 13, 2010

My eclipse is not creating gen folder and android compilation creates error missing required gen folder.

View 3 Replies View Related

In-memory DEX Loading Function Removed In Android 4.4

Jan 9, 2014

Noticed in Android 4.4, Google removed one of internal functions in class, DexFile:

native private static int openDexFile(byte[] fileContents);

which is capable of performing loading dex from byte-array without going through reading the dex file on disk, which has proven to be very useful

View 1 Replies View Related

Android :: NinePatchDrawable - Error No Resource Found That Matches The Given Name

Aug 9, 2010

The problem with NinePatchDrawable. Created 9.png file using a utility draw9patch, but when the throw the file in a folder res/drawable error: No resource found that matches the given name.

View 4 Replies View Related

Android : Can SAX Use A Local Resource XML File?

Jul 26, 2010

All of the android examples for XmlPullParser pull from a local resource file, and all of the SAX examples pull the XML from a URL. I've been told SAX is faster, so I'm trying to use that to pull data from a local resource file (res/xml/thefile.xml)

The example code I'm working off of is here. So in that example, the code I want to change is:

URL url = new URL("http://example.com/example.xml");
...
xr.parse(new InputSource(url.openStream()));

Instead of using URL, I want to use getXml(R.xml.thefile)
Is that possible, or does SAX need to get data from a URL?

View 1 Replies View Related

Android :: Instantiating A Layout From An Xml File / Resource Id

Jan 28, 2009

I'm interested in instantiating a LinearLayout object from an xml file that has a LinearLayout file configuration. I want to do this within a method of my Activity. I tried findViewById() but that returned null. I've made sure that the LinearLayout id is the one I'm passing. Note that this layout isn't part of my screen, it's stand-alone, so I want to build a LinearLayout object from the xml.

View 3 Replies View Related

Android :: Using Raw Resource Sound File As Ringtone

Dec 11, 2009

I have a problem setting a ringtone from a resource in my app:

Uri uri = Uri.parse("android.resource://com.package.app/" + R.raw.sound1); RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, uri);

I've noticed also some people had the same problem but got no answers. Do any of you guys have any idea of how making this work? (without having to copy the file to the sdcard)

View 2 Replies View Related

Android :: Add ZIP File As A Raw Resource And Read It With ZipFile?

Jan 7, 2010

Is it possible to add ZIP file to APK package as a raw resource and read it with ZipFile class? It looks like it's trivial to open file from SD card, but not from APK.

View 1 Replies View Related

Android : Play A Video File From A Resource

Nov 24, 2010

I am trying to get a video to pop up and play. I can get it to work when I use the first uri (that is commented out in the below code), but when I try to use the second uri (from the resource), I get the following error:

CODE:..........

From researching the error, it looks like I might have to declare an activity in the manifest but I'm not sure if that applies here?? Can someone point me in the right direction?

CODE:............

View 1 Replies View Related

Android : Playing A Video File From Resource

Aug 20, 2009

From weeeks i m trying to play a video file from raw folder .but no success.

I have used this code:..................

View 4 Replies View Related

Android : Use Ninepatch Png Image Via File - Not From Resource?

May 24, 2009

I want to use the ninepatch image in the file system. but seems that it can be referenced via res.

how to get the auto-scale support for the images in file system.

View 2 Replies View Related

Android :: Aapt Error With Standard Menu Icons Resource Is Not Public

Jun 3, 2009

I've been trying to include standard android icons in a menu XML file, as described in Android Icon design guidelines. However the build fails with the following errors : [2009-06-04 00:00:31 - Laser] W/ResourceType(16578): Bad XML block: header size 2475 or total size 0 is larger than data size 0 [2009-06-04 00:00:31 - Laser] /home/niko/dev/workspace/Laser/res/menu/ main.xml:4: ERROR Error: Resource is not public. (at 'icon' with value '@android:drawable/ic_menu_play_clip'). [2009-06-04 00:00:31 - Laser] Unknown error: The only threads I could find with this error were about rebuilding android platform xml files. Any idea about what I could have missed?

View 5 Replies View Related

Android :: Take Text In An Array Which Come From A Resource ?

Sep 5, 2010

This is a part of my code...

i want to replace the "" in the title_t.setText("") by a thing that can work.
I just want to take the title from the listview which come from a resource..

View 1 Replies View Related

Android :: Add Newlines To A Text Resource?

Mar 24, 2010

I have a custom Dialog that contains only a TextView to display some text in my application. The documentation lists that only the b, i, u, tt, big, small, sup, sub, and strike tags are supported. I really need to add some newlines for readability. Do I need to change to a more complicated layout, or is there some way to encode newlines in the resource? I tried adding br tags.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved