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 8629983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:56:49+00:00 2026-06-12T08:56:49+00:00

i have an arraylist that do this : ArrayList<Integer> id = new ArrayList<Integer>(); for

  • 0

i have an arraylist that do this :

     ArrayList<Integer> id = new ArrayList<Integer>(); 
     for (int i = 0; i <= 20; i++) {
     id.add(getResources().getIdentifier("q"+i, "raw", getPackageName()));}

this method before a little change is working good but now have force close!
and i get this logcat:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{yaAli.package313.hossein110/yaAli.package313.hossein110.know}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)at android.app.ActivityThread.access$600(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at yaAli.package313.hossein110.know.onCreate(know.java:33)
at android.app.Activity.performCreate(Activity.java)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
... 12 more

Here is my OnCreate():

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.basetxt);        
    SharedPreferences   settings=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    ln=settings.getString("LASTREADln", null);
    if(ln.equals("-1")){ln="0";}
    if(ln!=null){
    final ScrollView s1=(ScrollView) findViewById(R.id.sV1);
    s1.post(new Runnable() {@Override
    public void run() {s1.scrollTo(0, Integer.valueOf(ln));} });}

    final MediaPlayer mp1=MediaPlayer.create(getBaseContext(), R.raw.arza);  

    String pos = getIntent().getStringExtra("key");
    String arr = getIntent().getStringExtra("list");


    TextView tvfa = (TextView)findViewById(R.id.TEXT313);

    String fontPath = "fonts/font1.ttf";
    String fontPath1 = "fonts/font2.ttf";

    Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
    Typeface tf1 = Typeface.createFromAsset(getAssets(), fontPath1);

    SharedPreferences sharedpreferences =    PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    tvfa.getRootView().setKeepScreenOn(sharedpreferences.getBoolean("scrnon", false));
    String sizefa=   sharedpreferences.getString("fontsizefa",null);
    String colorfa=   sharedpreferences.getString("fontcolorfa",null);        
    boolean style=   sharedpreferences.getBoolean("appfont", false);
    boolean music=   sharedpreferences.getBoolean("musictype", false);
    boolean curr=   sharedpreferences.getBoolean("currputfont", false);

String t = read(file(pos,arr,null)); {

if (curr){tvfa.setText(PersianReshape.reshape(t));}else{tvfa.setText(t);} // Txt 
tvfa.setTextSize(1, Float.valueOf(sizefa).floatValue());                    // Size
tvfa.setTextColor(Color.parseColor(colorfa));                               // Color
if (style) { tvfa.setTypeface(tf1); }  else {tvfa.setTypeface(tf);}         // Type
if (music) { mp1.start(); } else { mp1.stop(); }  }}                          // Play
//---------------------------------------------------------------------------- 
  • 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-12T08:56:51+00:00Added an answer on June 12, 2026 at 8:56 am

    best practice for java development is to have the literal string do the .equals call. so instead of:

    var.equals("string")
    

    you do:

    "string".equals(var)
    

    This guarantees you will NEVER have a null pointer exception when doing string comparison.

    Also, it looks like you are storing numeric values as strings. Any particular reason you aren’t storing them as ints?

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

Sidebar

Related Questions

I have a two-dimension ArrayList that contains double values: ArrayList<ArrayList<Double>> data = new ArrayList<ArrayList<Double>>();
I have a method that returns an IEnumerable<KeyValuePair<string, ArrayList>> , but some of the
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i <
It is known that arraylist init. should be like this ArrayList<A> a = new
Will this work? public void setRepeatingAlarm() { ArrayList<Integer> AlarmDays = datasource.getDays(); final int _id
I have an arraylist that gets different type of values in it, 1st value->
I have an ArrayList that I want to use to hold RaceCar objects that
I have an ArrayList that has a nested ArrayList of Strings and I want
I have a stringtoList ArrayList that needs to return tokens from a StreamTokenizer but
I have a two dimensional ArrayList that I need to filter the duplicates out

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.