Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6999733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:34:49+00:00 2026-05-27T20:34:49+00:00

I got this following method in an non Activity class, My code is below.

  • 0

I got this following method in an non Activity class, My code is below.

public class ReadTextByLineNo  {

public void setContext(Context _context) {
    if (context == null) {
        context = _context;
    }
}
public String getTextByLine(int Filename,int LineNumber)
{


    String output="";
    String line="";
    int counter=1;
    try
    {
         InputStream in = context.getResources().openRawResource(Filename);
        //InputStream in = assetManager.open(Filename);
        if(in!=null)
        {
            InputStreamReader input = new InputStreamReader(in);
            BufferedReader buff = new BufferedReader(input);
            while((line=buff.readLine())!=null)
            {
                if(counter ==LineNumber){
                    output=line;
                }counter++;
            }in.close();
        }else{
            Log.e("Input STREAM PROBLEM", "TEXT IS NULL NULL NULL NULL NULL");
        }
    }catch(Exception e)
    {
        //log
    }

    return output;
}

**I am calling this method from an NON_ACTIVITY CLASS LIKE THIS **

class sample implements Isample
{
ReadTextByLineNo read = new ReadTextByLineNo();
String subMsg =  read.getTextByLine(R.raw.subtitle, storySceneId);
//the above string is to called from an activity called Layout 


}

How do I use resources/context from an non activity class? I cannot use the context in constructor since I’m also calling the method from an non Activity class.
so I can’t set read.setContent(this); where I got setContext method in my ReadtextByLineNo class, thanks for the help .

Please help me to get the context/resourse in the class sample and example by code is appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:34:49+00:00Added an answer on May 27, 2026 at 8:34 pm
    public class ReadTextByLineNo  {
        private static Context context;
    
        public static void setContext(Context mcontext) {
            if (context == null)
                context = mcontext;
        }
    }
    

    when your application start, just initialize this context, by calling

    ReadTextByLineNo.setContext(getApplicationContext());
    

    from your main activity..

    Enjoy…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following method... public class Image extends Activity { public void onCreate(Bundle
I've got the following method of an public abstract class Model { //impl }
My Problem is the following. I got this code and i guess a corrupt
I've got the following code: Regex.Replace(text, words.ToString(), <dfn title=\ + this.FindDefinition($0) + \>$0</dfn>, RegexOptions.IgnoreCase
Got this line of code here but its not working. private void Button_Click(object sender,
I've got this public static class MyClassHelper { DataContex db = new DataContext(); public
I have a UIViewController subclass called TripViewController. This class has the following method: -
I have the following code in a method. This is the entire method: private
I am updating the data by the following method class xxxxxx { public static
I've got an asmx web service with the following method [WebMethod] public string LoadRegions(Guid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.