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

  • SEARCH
  • Home
  • 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 8200235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:22:22+00:00 2026-06-07T06:22:22+00:00

I’ve had this really annoying problem for a couple of days, and I cannot

  • 0

I’ve had this really annoying problem for a couple of days, and I cannot quite seem to solve it. I am trying to open a .csv file, so I imported it into the res/raw/ folder of my project. Then I am trying to open and read it via the getResources() method, and that’s exactly where I get the NullPointerException. Here’s the method that reads the file and fills an array with the available lines.

Here’s my Activity where I create an Object newwords from the class Words, and then I want to call the PlayWithRawFiles() method from class Words.

public class Swear_Activity extends Activity implements OnInitListener, OnClickListener {

    private Words newwords;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_swear);
    }
    public void onClick(View view){
        try {
            newwords.PlayWithRawFiles();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println("greshka");
            e.printStackTrace();
        }
    }
}

now this is the class where i get the error

public class Words{

    public Word[] wordsArray;
    private String locale = "de";
    
    public Words(String locale) {
        if (locale != null ) {
            this.locale = locale;
        }
    }
    
    Context c;
    public void PlayWithRawFiles() throws IOException  {
        String str="";
        StringBuffer buf = new StringBuffer();          
        int i = 0;
        InputStream is = c.getResources().openRawResource(R.raw.est);
        BufferedReader reader = null;
        try{
            if (is != null) reader = new BufferedReader(new InputStreamReader(is));
        }
        catch(Exception e) {
            System.out.println ("ss");
            e.printStackTrace();
        }
            
        if (is!=null) {                         
            while ((str = reader.readLine()) != null) { 
                Word wd = new Word(1,"str");
                this.wordsArray[i] = wd;
                i++;
            }               
        }       
        is.close();
    }
}

here is class Word

public class Word {
    private int type;
    private String data;

    public Word(int type, String data){
        this.type = type;
        this.data=data;
    }

    public int getType(){
        return this.type;
    }
    public String getData(){
        return this.data;
    }
}

Here is the Stack Trace

07-10 13:28:58.558: E/AndroidRuntime(647): FATAL EXCEPTION: main

07-10 13:28:58.558: E/AndroidRuntime(647): java.lang.NullPointerException

07-10 13:28:58.558: E/AndroidRuntime(647): at de.android.swearapp.Swear_Activity.onClick(Swear_Activity.java:32)

07-10 13:28:58.558: E/AndroidRuntime(647): at >android.view.View.performClick(View.java:2408)

07-10 13:28:58.558: E/AndroidRuntime(647): at android.view.View$PerformClick.run(View.java:8816)

07-10 13:28:58.558: E/AndroidRuntime(647): at android.os.Handler.handleCallback(Handler.java:587)

07-10 13:28:58.558: E/AndroidRuntime(647): at android.os.Handler.dispatchMessage(Handler.java:92)

07-10 13:28:58.558: E/AndroidRuntime(647): at android.os.Looper.loop(Looper.java:123)

07-10 13:28:58.558: E/AndroidRuntime(647): at android.app.ActivityThread.main(ActivityThread.java:4627)

07-10 13:28:58.558: E/AndroidRuntime(647): at java.lang.reflect.Method.invokeNative(Native Method)

07-10 13:28:58.558: E/AndroidRuntime(647): at java.lang.reflect.Method.invoke(Method.java:521)

07-10 13:28:58.558: E/AndroidRuntime(647): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

07-10 13:28:58.558: E/AndroidRuntime(647): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

07-10 13:28:58.558: E/AndroidRuntime(647): at dalvik.system.NativeStart.main(Native Method)

What have I done wrong? I’m really stuck at this one. Thank you in advance!

  • 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-06-07T06:22:24+00:00Added an answer on June 7, 2026 at 6:22 am

    Two things I see here,

    • You are not instantiating newwords as in newwords = new Words("");
    • c is null and not assigned a context.

    I recommend you re-code the class like this:

    public class Words{
       public Word[] wordsArray;
       private String locale = "de";
       private Context c;
       public Words(String locale, Context paramContext) {
          if (locale != null ) {
             this.locale = locale;
          }
          c = paramContext;
       }
    // Rest of code ok.
    //
    // Remove the Context c variable further on as it is declared above!
    }
    

    What is done is, we simply added the Context as part of the constructor for the class Words. Then to instantiate the class Words do this, from your SwearActivity class:

    public void onClick(View view){
        newwords = new Words("", getApplicationContext());
        try {
            newwords.PlayWithRawFiles();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println("greshka");
            e.printStackTrace();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:

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.