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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:43:24+00:00 2026-05-25T06:43:24+00:00

This is a bit of code from a section of my app where I

  • 0

This is a bit of code from a section of my app where I am trying to allow people to view the sections that they favorites. I have it working for that part. Now I’m trying to make it so that when onLongClick it allows the option to delete one. I do not know whether that part works yet because I am currently experiencing an error in the array section from what I have narrowed it down to. Its very weird because from what I can see the difference from it working and not there really shouldn’t be any problem. Maybe I need some fresh eyes looking at this if you will. Thanks

public class Favorites extends ListActivity{

    public static final String PREFS_NAME = "Favorites";
    String[] title;
    int favNum, num;
    int[] category, member;

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      grabFav();
      num = favNum;
      num++;
      if(favNum > -1){
          title = new String[num];
          category = new int[num];
          member = new int[num];
          allFavs();

          setListAdapter(new ArrayAdapter<String>(this, R.layout.item_list, title));

          ListView lv = getListView();
          lv.setTextFilterEnabled(true);      
      }
    }

    public void grabFav(){
         SharedPreferences saved = this.getSharedPreferences(PREFS_NAME, 0);
         favNum = saved.getInt("FavoriteNum", -1);
    }

    public void allFavs(){
        SharedPreferences saved = this.getSharedPreferences(PREFS_NAME, 0);

        for(int i = 0; i< favNum; i++){
            title[i] = saved.getString("Title"+i, "");
        }

        for(int n = 0; n< favNum; n++){
            category[n] = saved.getInt("Category"+n, 0);
        }

        for(int m = 0; m< favNum; m++){
            member[m] = saved.getInt("Member"+m, 0);
        }
    }
}

When that top part looks like this

grabFav();
  favNum++;

  if(favNum > 0){
      title = new String[favNum];
      category = new int[favNum];
      member = new int[favNum];
      allFavs();

It works fine (not sure about the onLongItemClick because I normally have it commented out so I can find the error). From what I can tell it should be working just fine. I posted the whole class incase you notice another error in it that will likely cause problems. Here is the log cat if you want to look

09-04 11:09:20.576: ERROR/AndroidRuntime(18769): FATAL EXCEPTION: main
09-04 11:09:20.576: ERROR/AndroidRuntime(18769): java.lang.NullPointerException
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.AbsListView.obtainView(AbsListView.java:1315)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.ListView.makeAndAddView(ListView.java:1727)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.ListView.fillDown(ListView.java:652)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.ListView.fillFromTop(ListView.java:709)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.ListView.layoutChildren(ListView.java:1580)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.AbsListView.onLayout(AbsListView.java:1147)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.view.View.layout(View.java:7035)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.view.View.layout(View.java:7035)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.view.View.layout(View.java:7035)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.view.View.layout(View.java:7035)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.os.Looper.loop(Looper.java:123)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at java.lang.reflect.Method.invokeNative(Native Method)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at java.lang.reflect.Method.invoke(Method.java:521)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
09-04 11:09:20.576: ERROR/AndroidRuntime(18769):     at dalvik.system.NativeStart.main(Native Method)

Any help is greatly appreciated. Thanks

  • 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-25T06:43:25+00:00Added an answer on May 25, 2026 at 6:43 am

    Have you checked, that all the title strings you get from your preferences actually exist, i.e. that this line does not assign null to title[i]:

    title[i] = saved.getString("Title"+i, "");
    

    Maybe you’re missing the zeroth title “Title0” and start only at “Title1”?

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

Sidebar

Related Questions

I use this bit of code to feed some data i have parsed from
How do I change this bit of code so that I only allow pdf
This bit of code comes with new classes that are subclasses of UITableViewController... -
I have this bit of code, public static List<string> GetSentencesFromWords(List<string> words, string fileContents) {
I have the following bit of code. I'm trying to dynamically add drop-down options
This bit of code is taking almost a half second to execute. Could somebody
To this bit of code I pass the string kellogs special k and I
IS this bit of code in PHP/mysql considered a stored procedure? $sql = 'SELECT
What does this bit of code represent? I know it's some kind of if
I saw this bit of code on the interents somewhere. I'm wondering what the

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.