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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:18:13+00:00 2026-05-18T12:18:13+00:00

Basic question here, can I put String variables into a position in a string

  • 0

Basic question here, can I put String variables into a position in a string array along with more text?

Here’s what I’m trying to do

public static final String CAT_BUD_TAB = "CAT_BUD_TAB";
public static final String inI = "INSERT INTO ";
public static final String val = " VALUES ";

public static final String[] catInsertArray = new String[13];

catInsertArray[0] = inI + CAT_BUD_TAB + val + "(null, 'Student Loan', 'in', 0.00, 0.00, 0.00, 0, 0 );";

But obviously that’s not going to work because it’s expecting ” to mark the start of the string to be contained. Is there anyway this will work?

EDIT

Nope its not the SQL im concerned with, I’m just trying to combine a bit of text with text from a string variable and hold them all as one long string in an array. Might have just made it more confusing, if so ignore this edit and just re-read the original question.

Got rid of the parenthesis as suggested and updated the code block above with all the relevant code.

but eclipse is still saying there’s a “syntax error on tokens, delete these tokens” And has squiggly red lined the whole line of code (catInsertArray[0] = ….)

pastebin of the class here if you’d be good enough to take a look http://pastebin.com/cKa0sKEj

  • 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-18T12:18:13+00:00Added an answer on May 18, 2026 at 12:18 pm

    I suspect your original problem was having code that was outside of a method body. This demo class will compile and run, and has comments pointing out what you might have been doing vs. what would be correct.

    public class StringTest 
    {
    
        public static final String crT = "CREATE TABLE ";
        public static final String inI = "INSERT INTO ";
        public static final String val = " VALUES ";
    
        public static final String[] catInsertArray = new String[13];
    
        // you were probably doing this, which is not allowed in Java because you are writing code outside of a method body or static initializer block
        //catInsertArray[0] = inI + val + "(null, 'Student Loan', 'in', 0.00, 0.00, 0.00, 0, 0 );"; 
    
        static
        {
             // static initialize your static member
             catInsertArray[0] = inI + val + "(null, 'Student Loan', 'in', 0.00, 0.00, 0.00, 0, 0 );"; 
        }
    
        public static void main(String [] args)
        {
            // You can put code in a method
            //catInsertArray[0] = inI + val + "(null, 'Student Loan', 'in', 0.00, 0.00, 0.00, 0, 0 );"; 
    
        }
    }
    

    From your new comment – the code you have in your pastebin link has a few issues. One thing I have is why you are declaring a nested interface inside your DatabaseConstants class? It seems unnecessary since you’re making a class for constants.

    Additionally, you still leave out a static initializer block to put things into your String array. See the code below.

    package com.geistware.studentbudgetapp;
    
    import android.provider.BaseColumns;
    
    public class  DatabaseConstants {
    
        //Variables for DDL statements and such
        public static final String crT = "CREATE TABLE ";
        public static final String inI = "INSERT INTO ";
        public static final String val = " VALUES ";
    
        //Table Names
        public static final String CAT_BUD_TAB = "CAT_BUD_TAB";
        public static final String TWO_WEE_TAB = "TWO_WEE_TAB";
    
        //columns from the category_budget_table
        public static final String CAT_ITEM = "CAT_ITEM";
        public static final String IN_OUT = "IN_OUT";
        public static final String BUDGET_AMOUNT = "BUDGET_AMOUNT";
        public static final String ACTUAL_AMOUNT = "ACTUAL_AMOUNT";
        public static final String AMOUNT_STRAYED = "AMOUNT_STRAYED";
        public static final String OVERBUDGET_TF = "OVERBUDGET_TF";
        public static final String AUTOSPEND_TF = "AUTOSPEND_TF";
    
        //Initial DDL Statements and Initial INSERT statements to populate table
        public static final String createCATBUDTAB = (crT + CAT_BUD_TAB + 
                "(_id INTEGER PRIMARY KEY, CAT_ITEM TEXT, IN_OUT TEXT, BUDGET_AMOUNT REAL, ACTUAL_AMOUNT REAL, AMOUNT_STRAYED REAL, OVERBUDGET_TF INTEGER, AUTOSPEND_TF INTEGER);");
        public static final String createTWOWEETAB = (crT + TWO_WEE_TAB + 
                "(_id INTEGER PRIMARY KEY, SUB_CAT_ITEM TEXT, CAT_ITEM TEXT, COST REAL, ESSENTIAL_TF INTEGER, CURRENT_LAST TEXT, WEEK_ID INTEGER);");
    
        public static String[] catInsertArray = new String[13];
    
        // you still need to to put this code into a static initializer block
        static
        {
            catInsertArray[0] = inI + CAT_BUD_TAB + val + "(null, 'Student Loan', 'in', 0.00, 0.00, 0.00, 0, 0 );";
        }
    
    }
    

    However, for something like a list of constants, I’d prefer to use an enumeration, but hopefully this gets you on the right track to at least getting a working build.

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

Sidebar

Related Questions

It's a really basic question but i can't think at the second. How do
I know this is a basic question, but I can't seem to find an
Basic question : How to I create a bidirectional one-to-many map in Fluent NHibernate?
My basic question is, in .NET, how do I clone WebControls? I would like
Very basic question: how do I write a short literal in C++? I know
Sorry for the basic question - I'm a .NET developer and don't have much
Kind of a basic question but I'm having troubles thinking of a solution so
This is a fairly basic question, which for some reason, a proper solution escapes
This is a really basic question but this is the first time I've used
This is a really basic question but... I have some code like this var

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.