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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:59:23+00:00 2026-06-04T12:59:23+00:00

I am using this code to insert the details in to TwoDimensional Array. But

  • 0

I am using this code to insert the details in to TwoDimensional Array. But while retrieving the data from the array the first element value changes to null.

    Cursor consultancy = db.getConsultancy(this);
        if(consultancy!=null)
        {
            consultancy.moveToFirst(); 
            consultancy.moveToNext();  
            consultancynames = new String[(int) db.getConsultancyCount()-1];
            for(int i=0;i<db.getConsultancyCount()-1;i++)
            { 
                consultancynames[i] = consultancy.getString(2);  
                int consultantid = Integer.parseInt(consultancy.getString(consultancy.getColumnIndex(TimeAndExpensesLocalDB.CT_CONSULTANCYID))); 
                Cursor project_namecur = db.getProjectCode(this, consultantid);
                if(project_namecur!=null)
                {
                    project_namecur.moveToFirst();  
                    projectname = new String[(int) db.getConsultancyCount()][project_namecur.getCount()];
                    for(int j=0;j<project_namecur.getCount();j++)
                    {  
                        projectname[i][j] = project_namecur.getString(3);    
                        project_namecur.moveToNext();  
                    } 
                }
                consultancy.moveToNext();
            }  

        }  

        //... Print array  
        for (int i =0; i < consultancynames.length; i++) {
        for (int j = 0; j < projectname.length; j++) {
        System.out.print(" " + projectname[i][j]);
        }
        System.out.println("");
        }

Output

       05-25 12:58:22.700: I/System.out(2373):  null null null
       05-25 12:58:22.700: I/System.out(2373):  Other-1 Other-2 Other-3

I am not sure what is happening.

Thanks for your help guys..

  • 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-04T12:59:25+00:00Added an answer on June 4, 2026 at 12:59 pm

    You’re creating a new array on each iteration of the loop:

    projectname = new String[(int) db.getConsultancyCount()][project_namecur.getCount()];
    

    So on the first iteration you’re creating an array and filling in the first “row” of the array. On the second iteration you’re creating a new array (which will default to having null elements) and filling in the second row.

    I suspect you need to allocate the “outer” array once before the loop, then allocate the “inner” array based on how many project names there are for that consultant:

     // Note: more idiomatic names would be consultancyNames and
     // projectNames. It's also unclear why you're subtracting one from the count...
     consultancynames = new String[(int) db.getConsultancyCount() - 1];
     projectnames = new String[consultancynames.length][];
     for (int i = 0;i< consultancenames.length; i++) {
         ...
         projectnames[i] = new String[project_namecur.getCount())];
         ...
     }
    

    Then you’ll need to change your display code too, e.g. to

    for (int i =0; i < projectname.length; i++) {
        for (int j = 0; j < projectname[i].length; j++) {
            System.out.print(" " + projectname[i][j]);
        }
        System.out.println("");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this line of code to insert a value from an array into
I'm using code-first EF 4.1 to insert data into a SQL Server database. When
Using This code: I am tring to fill the page with the data and
While using this code to serialize an object: public object Clone() { var serializer
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
While using this code, i can't get any results... Ext.define('Teste.view.Main', { extend: 'Ext.Container', initialize:
I'm trying to build a dynamic table using PHP to insert data from a
Using this code to zip a folder and it works perfect on small files
Using this code var html='<div class=somediv></div>'; var target=document.getElementById('contentArea'); target.appendChild(html); I'm getting Uncaught Error: NOT_FOUND_ERR:
Im using this code for mysql connection $con = mysql_connect(localhost:/var/lib/mysql/mysql.sock, abc , xyz); if

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.