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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:18:03+00:00 2026-06-15T11:18:03+00:00

Here is my table setup: public static final String TABLE_DEBT = debt; public static

  • 0

Here is my table setup:

public static final String TABLE_DEBT = "debt";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_DEBT_NAME = "debt_name";
public static final String COLUMN_DEBT_TOTAL = "debt_total";
public static final String COLUMN_APR = "apr";
public static final String COLUMN_PAYMENT = "payment";
public static final String COLUMN_SPECIAL_RATE = "s_rate";
public static final String COLUMN_SPECIAL_TIME = "s_time";
public static final String COLUMN_FIRST_FEE = "first_apr_fee";
public static final String COLUMN_PAY_DATE = "pay_date";
private static final String DATABASE_NAME = "debt.db";
private static final int DATABASE_VERSION = 1;


private static final String DATABASE_CREATE = "create table " + TABLE_DEBT + "( " + COLUMN_ID + " integer primary key autoincrement, " + COLUMN_DEBT_NAME + " text not null, " + COLUMN_DEBT_TOTAL
            + " text not null, " + COLUMN_APR + " text not null, " + COLUMN_PAYMENT + " text not null, " + COLUMN_SPECIAL_RATE + " text, " + COLUMN_SPECIAL_TIME + " text, " + COLUMN_FIRST_FEE + " text, " + COLUMN_PAY_DATE + " text)";

I am using thse queries in this conditional format to sort by user selection:

    if (DebtPlanner.PlanType.equals("highint")) {
         c = database.rawQuery("SELECT *  FROM debt ORDER BY apr DESC;", null);
         Log.d("TAG", "DebtPlanner.PlanType is " + DebtPlanner.PlanType);
    } else if (DebtPlanner.PlanType.equals("lowbal")) {
         c = database.rawQuery("SELECT *  FROM debt ORDER BY debt_total ASC;", null);
         Log.d("TAG", "DebtPlanner.PlanType is " + DebtPlanner.PlanType);
    } else if (DebtPlanner.PlanType.equals("highbal")) {
         c = database.rawQuery("SELECT *  FROM debt ORDER BY debt_total DESC;", null);
         Log.d("TAG", "DebtPlanner.PlanType is " + DebtPlanner.PlanType);
    }

Added Code:

for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            indName[j++] = c.getString(c.getColumnIndex("debt_name"));
            indBal[k++] = c.getDouble(c.getColumnIndex("debt_total"));
            indPay[l++] = c.getDouble(c.getColumnIndex("payment"));
            indApr[m++] = c.getDouble(c.getColumnIndex("apr"));
            indSRate[e++] = c.getString(c.getColumnIndex("s_rate"));
            indSTime[f++] = c.getInt(c.getColumnIndex("s_time"));
            indDay[d++] = c.getString(c.getColumnIndex("pay_date"));

            rowCounter[n++] = n;
        }


    for (int i : rowCounter) { 

       nameList.add(indName[r++]); // This is the name of each debt that shows out of order.
       // lots of edited calucaltion here

     }

However, they sort, but not by the expected values. For example, when I say to sort by debt_toal (either ASC or DESC), it sorts by debt_name (it gets the ASC or DESC part correct).

I looked at the actual table in the phone and all the data is in the correct columns. I am not even sure where to go from here?

Extra code:

public class DebtPlanner extends Application {

    public static String PlanType = "highint";


    public static String highIntPlan() {
        return DebtPlanner.PlanType = "highint";
    }

    public static String lowBalPlan() {
        return DebtPlanner.PlanType = "lowbal";
    }

    public static String highBalPlan() {
        return DebtPlanner.PlanType = "highbal";
    }

}

  • 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-15T11:18:04+00:00Added an answer on June 15, 2026 at 11:18 am

    When comparing String in Java you must use equals(), not ==:

    if (DebtPlanner.PlanType.equals("default")) {
    

    There are great explanations about this in How do I compare strings in Java?


    Also you should use else if on your subsequent queries because they are mutually exclusive thoughts.


    It has been sorting correctly all along. The problem is, the column is String. So, technically, 2 is larger than 1000000. Now I just need to figure out how to correct this…

    Ok, use CAST to sort the column as an Integer rather than Text:

    SELECT * FROM debt ORDER BY CAST(apr AS INTEGER) DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have the following setup: abstract class Parent { public static String
Here's my toy setup. I have 3 tables. One table is a guest list
## Sample Table ## Here are some particulars concerning proposed problem. ROWID = _id;
Setup Using MVC 3 + Code First Here are my classes public class Member
Lets say we have a table here, populated with the following data: acc_id1 acc_id2
i m having following type of simple sql server table Here I want to
http://logging.apache.org/log4net/release/config-examples.html Given the log table here: CREATE TABLE [dbo].[Log] ( [Id] [int] IDENTITY (1,
Here is my table in comma-delimited form: date, number 2010-09-02, 2 2010-10-01, 3 2011-01-01,
Here is my table in the dataset: SELECT tag_work_field.* FROM tag_work_field I created this
Here is my table: id int(11) name varchar(255) description text highest_bidder int(11) value varchar(255)

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.