Hi, 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...
Can anyone help me to catch the problem?

---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 + "\n");
        }
        dataIO.close();
        is.close();
        return sBuffer.toString();
    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to