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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:23:13+00:00 2026-05-29T11:23:13+00:00

i have a issue making a SQLite edition, basicly, the error is java.lang.NumberFormatException, im

  • 0

i have a issue making a SQLite edition, basicly, the error is java.lang.NumberFormatException, im making Long.parseLong in my data, but i dont know why the program continues sending me that error , the code of my first class is next:

public class SQLiteActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
EditText ecoursename, etopic, ecourse_description, elength, erating, esearch;
Button insert, view, search, edit, delete;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ecoursename = (EditText) findViewById(R.id.cName);
    etopic = (EditText) findViewById(R.id.cTopic);
    ecourse_description= (EditText) findViewById(R.id.cDescription);
    elength= (EditText) findViewById(R.id.cLength);
    erating= (EditText) findViewById(R.id.cRating);
    esearch = (EditText) findViewById(R.id.etSearch);


    insert = (Button) findViewById(R.id.btInsert);
    view = (Button) findViewById(R.id.btView);
    search = (Button) findViewById(R.id.btSearch);
    edit = (Button) findViewById(R.id.btEdit);
    delete = (Button) findViewById(R.id.btDelete);


    search.setOnClickListener(this);
    edit.setOnClickListener(this);
    delete.setOnClickListener(this);
    insert.setOnClickListener(this);
    view.setOnClickListener(this);

}

public void onClick(View v) {
    //TODO Auto-generated method stub
    switch (v.getId()){
    case R.id.btInsert:


        boolean works = true;
        try{
        String course_name = ecoursename.getText().toString();
        String topic = etopic.getText().toString();
        String course_description = ecourse_description.getText().toString();
        String length = elength.getText().toString();
        String rating = erating.getText().toString();

        ecoursename.setText("");
        etopic.setText("");
        ecourse_description.setText("");
        elength.setText("");
        erating.setText("");        

        DBAdapter entry = new DBAdapter (SQLiteActivity.this);
        entry.open();
        entry.createEntry(course_name, topic, course_description, length, rating);
        entry.close();
        }catch(Exception e){
            works = false;
            String error = e.toString();
            Dialog d = new Dialog(this);
            d.setTitle("Dont Works");
            TextView tv = new TextView(this);
            tv.setText(error);
            d.setContentView(tv);
            d.show();


        }finally{
            if(works){

        // make click says inserted text
        Dialog d = new Dialog(this);
        d.setTitle("Works?");
        TextView tv = new TextView(this);
        tv.setText("is Working");
        d.setContentView(tv);
        d.show();

        }

        }

        break;

        case R.id.btView:           

        Intent i = new Intent("com.sqlite.base.data.SQLVista");
        startActivity(i);

        break;

        case R.id.btSearch:
            String s = esearch.getText().toString();
            Long ls = Long.parseLong(s);

            DBAdapter dbase= new DBAdapter(this);

            try{
            dbase.open();
            }catch(Exception e){

                e.printStackTrace();
            }
            String bN = dbase.getN(ls);
            String bT = dbase.getT(ls);
            String bD = dbase.getD(ls);
            String bL = dbase.getL(ls);
            String bR = dbase.getR(ls);

            dbase.close();

            ecoursename.setText(bN);
            etopic.setText(bT);
            ecourse_description.setText(bD);
            elength.setText(bL);
            erating.setText(bR);

            break;

        case R.id.btEdit:
            try{
            String eCo = ecoursename.getText().toString();
            String eTo = etopic.getText().toString();
            String eDe = ecourse_description.getText().toString();
            String eLe = elength.getText().toString();
            String eRa = erating.getText().toString();
            String eRow = esearch.getText().toString();
            long eRowl = Long.parseLong(eRow);
            DBAdapter edit = new DBAdapter(this);

            edit.open();
            edit.edit(eRowl, eCo, eTo, eDe, eLe, eRa);
            edit.close();

            }catch(Exception e) {
                String error = e.toString();
                Dialog d = new Dialog(this);
                d.setTitle("Dont Works!");
                TextView tv = new TextView(this);
                tv.setText(error);
                d.setContentView(tv);
                d.show();
            }

            break;

        case R.id.btDelete:
            break;  


    }
}
}

my DBAdapter class:

public class DBAdapter {

public static final String ID_ROW = "_id";
public static final String ID_COURSENAME = "course_name";
public static final String ID_TOPIC = "topic";
public static final String ID_DESCRIPTION = "course_description";   
public static final String ID_LENGTH = "length";
public static final String ID_RATING = "rating";

private static final String N_DB = "Clases";
private static final String N_TABLE = "Courses";
private static final int VERSION_DB = 1;

private DBHelper nHelper;
private final Context nContext;
private SQLiteDatabase nDB;



private static class DBHelper extends SQLiteOpenHelper{

    public DBHelper(Context context) {
        super(context, N_DB, null, VERSION_DB);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(" CREATE TABLE " + N_TABLE + "(" + ID_ROW + " INTEGER PRIMARY KEY AUTOINCREMENT, " + ID_COURSENAME + " TEXT NOT NULL, " + ID_TOPIC + " TEXT NOT NULL, " + ID_DESCRIPTION + " TEXT NOT NULL, " + ID_LENGTH + " TEXT NOT NULL, " + ID_RATING + " TEXT NOT NULL);"


        );

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + N_TABLE);
        onCreate(db);           
    }

}

public DBAdapter (Context c){

    nContext = c;
}

public DBAdapter open() throws SQLException{
    nHelper = new DBHelper(nContext);
    nDB = nHelper.getWritableDatabase();
    return this;
}

public void close() {
    // TODO Auto-generated method stub
    nHelper.close();
}

public long createEntry(String course_name, String topic, String course_description, String length, String rating ) {
    // TODO Auto-generated method stub
    //insert data
    ContentValues cv = new ContentValues();

    cv.put(ID_COURSENAME, course_name);
    cv.put(ID_TOPIC, topic);
    cv.put(ID_DESCRIPTION, course_description);
    cv.put(ID_LENGTH, length);
    cv.put(ID_RATING, rating);

    //return content in table
    return nDB.insert(N_TABLE, null, cv);

}

public String receive() {
    // TODO Auto-generated method stub
    String[] columns = new String[]{ID_ROW, ID_COURSENAME, ID_TOPIC, ID_DESCRIPTION, ID_LENGTH, ID_RATING};
    Cursor c = nDB.query(N_TABLE, columns, null, null, null, null, null);
    String result = "";

    int iRow = c.getColumnIndex(ID_ROW);
    int cName = c.getColumnIndex(ID_COURSENAME);
    int cTopic = c.getColumnIndex(ID_TOPIC);
    int cDescription = c.getColumnIndex(ID_DESCRIPTION);
    int cLength = c.getColumnIndex(ID_LENGTH);
    int cRating = c.getColumnIndex(ID_RATING);

    //loop
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
        result = result + c.getString(iRow) + " " + c.getString(cName) + " " + c.getString(cTopic) + " " + c.getString(cDescription) + " " + c.getString(cLength) + " " + c.getString(cRating) + "\n ";

    }

    return result;
}

public String getN(Long ls) {
    // TODO Auto-generated method stub
    String[] columns = new String[]{ID_ROW, ID_COURSENAME, ID_TOPIC, ID_DESCRIPTION, ID_LENGTH, ID_RATING};
    Cursor c =nDB.query(N_TABLE, columns, ID_ROW + "=" + ls, null, null, null, null);
    if(c != null){
        c.moveToFirst();
        String ns = c.getString(1);
        return ns;
    }

    return null;
}

public String getT(Long ls) {
    // TODO Auto-generated method stub
    String[] columns = new String[]{ID_ROW, ID_COURSENAME, ID_TOPIC, ID_DESCRIPTION, ID_LENGTH, ID_RATING};
    Cursor c =nDB.query(N_TABLE, columns, ID_ROW + "=" + ls, null, null, null, null);
    if(c != null){
        c.moveToFirst();
        String ts = c.getString(2);
        return ts;
    }

    return null;
}

public String getD(Long ls) {
    // TODO Auto-generated method stub
    String[] columns = new String[]{ID_ROW, ID_COURSENAME, ID_TOPIC, ID_DESCRIPTION, ID_LENGTH, ID_RATING};
    Cursor c =nDB.query(N_TABLE, columns, ID_ROW + "=" + ls, null, null, null, null);
    if(c != null){
        c.moveToFirst();
        String nd = c.getString(3);
        return nd;
    }

    return null;
}

public String getL(Long ls) {
    // TODO Auto-generated method stub
    String[] columns = new String[]{ID_ROW, ID_COURSENAME, ID_TOPIC, ID_DESCRIPTION, ID_LENGTH, ID_RATING};
    Cursor c =nDB.query(N_TABLE, columns, ID_ROW + "=" + ls, null, null, null, null);
    if(c != null){
        c.moveToFirst();
        String nl = c.getString(4);
        return nl;
    }

    return null;
}

public String getR(Long ls) {
    // TODO Auto-generated method stub
    String[] columns = new String[]{ID_ROW, ID_COURSENAME, ID_TOPIC, ID_DESCRIPTION, ID_LENGTH, ID_RATING};
    Cursor c =nDB.query(N_TABLE, columns, ID_ROW + "=" + ls, null, null, null, null);
    if(c != null){
        c.moveToFirst();
        String nr = c.getString(5);
        return nr;
    }

    return null;
}

public void edit(long eRowl, String eCo, String eTo, String eDe,
        String eLe, String eRa) throws SQLException {
    // TODO Auto-generated method stub

    ContentValues cvEdit = new ContentValues();
    cvEdit.put(ID_COURSENAME, eCo);
    cvEdit.put(ID_TOPIC, eTo);
    cvEdit.put(ID_DESCRIPTION, eDe);
    cvEdit.put(ID_LENGTH, eLe);
    cvEdit.put(ID_RATING, eRa);
    nDB.update(N_TABLE, cvEdit, ID_ROW + "=" + eRowl, null);

}}

really would appreciate your help

  • 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-29T11:23:14+00:00Added an answer on May 29, 2026 at 11:23 am

    Thanks for your screenshot.Could you please improve your code to this:

    }catch(Exception e) {
                String error = e.getMessage(); //instead of String error = e.toString();
    ...
    

    So we can see the actual cause.
    Can you please make the “don’t works” dialog large? I think some text is being trimmed.

    I believe you are trying to parse an empty string “”.

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

Sidebar

Related Questions

I have a pretty basic assignment, but am having an issue making my main
Please have a look at this page www.pixeli.ca/issue. I have begun making a page
We have an issue related to a Java application running under a (rather old)
I have an issue. I am making an extension class for a Collection and
I have an issue with a 3rd party DLL, which is NOT thread-safe, but
I have an issue in IE6 and 7 where I am making an ajax
I have an issue in making datepicker regional. <script type=text/javascript> $(document).ready(function () { $(function
I have an issue similar to Select incremented integer but I'm trying to take
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I have an issue that is driving me a bit nuts: Using a UserProfileManager

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.