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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:40:03+00:00 2026-05-25T11:40:03+00:00

I have this code to retrieve data from file then make some treatment, and

  • 0

I have this code to retrieve data from file then make some treatment, and finally set the result in an EditTextPreference.

 try {
                //open the specified input file and create a reader
                FileInputStream fIn = context.openFileInput(fileDir+fileName);
                InputStreamReader ipsr = new InputStreamReader(fIn);
                BufferedReader b = new BufferedReader(ipsr);


                String ligne;

                while ((ligne = b.readLine()) != null) {
                    String prix = ligne.split(" ")[2];
                    //prix = prix.substring(0, prix.length() - 2);
                    Log.d("PRIX",prix);
                    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
                    String prix_total = settings.getString("prix_total", "0");
                        int a= Integer.valueOf(prix_total);
                     int c= Integer.valueOf(prix);
                 a= c + a;
                  String z=String.valueOf(a);
                  Log.d("A",z);

                  EditTextPreference myEditTextPreference = (EditTextPreference) findPreference("prix_total");
                  myEditTextPreference.setText(z); 
}


            //done, cleanup and return
            fIn.close();
            ipsr.close();

        } 
        catch (Exception e) 
        {
            Log.e("blah", "Exception", e);
        }

However, i’m encountering this problem(logcat):

09-12 01:09:10.941: ERROR/blah(10866): Exception
09-12 01:09:10.941: ERROR/blah(10866): java.lang.NumberFormatException: unable to parse '' as integer
09-12 01:09:10.941: ERROR/blah(10866):     at java.lang.Integer.parseInt(Integer.java:362)
09-12 01:09:10.941: ERROR/blah(10866):     at java.lang.Integer.parseInt(Integer.java:332)
09-12 01:09:10.941: ERROR/blah(10866):     at java.lang.Integer.valueOf(Integer.java:506)
09-12 01:09:10.941: ERROR/blah(10866):     at carburant.android.com.Settings.onCreate(Settings.java:46)
09-12 01:09:10.941: ERROR/blah(10866):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-12 01:09:10.941: ERROR/blah(10866):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
09-12 01:09:10.941: ERROR/blah(10866):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-12 01:09:10.941: ERROR/blah(10866):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-12 01:09:10.941: ERROR/blah(10866):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-12 01:09:10.941: ERROR/blah(10866):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-12 01:09:10.941: ERROR/blah(10866):     at android.os.Looper.loop(Looper.java:130)
09-12 01:09:10.941: ERROR/blah(10866):     at android.app.ActivityThread.main(ActivityThread.java:3687)
09-12 01:09:10.941: ERROR/blah(10866):     at java.lang.reflect.Method.invokeNative(Native Method)
09-12 01:09:10.941: ERROR/blah(10866):     at java.lang.reflect.Method.invoke(Method.java:507)
09-12 01:09:10.941: ERROR/blah(10866):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
09-12 01:09:10.941: ERROR/blah(10866):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
09-12 01:09:10.941: ERROR/blah(10866):     at dalvik.system.NativeStart.main(Native Method)

What could be the problem? I debugged “prix” and founding that it outputs '' :.
Thanks for helping.
PS: The data has that form:

data = date + ": " + y + "L/100KM "+ " " + value1 + "dt "+ value2 + "KM\n";
  • 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-25T11:40:03+00:00Added an answer on May 25, 2026 at 11:40 am

    valueOf and parseInt can’t handle empty strings or nulls. Add some checks such as using TextUtils.IsEmpty(string) to verify you are not passing empty data.

    Also I see you are surrounding this with a try block, consider adding a catch (NumberFormatException ex) block and logging the error if it is never supposed to be empty.

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

Sidebar

Related Questions

I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
I'm trying to retrieve data from a POST method, code as follows: -(void)postXMLFeed:(NSString *)XMLStrPost
I am trying retrieve data from a .php file on a server from within
I 'm trying to retrieve data from a datastore by using this (in example)
I have this code in jQuery, that I want to reimplement with the prototype
I have this code that performs an ajax call and loads the results into
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:
I have this code: myVariable which I want to change into trace(myVariable: + myVariable);

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.