Mohammedis271
Mohammedis271

Reputation: 185

Android TableView with MSSQL

I am busy with trying to get an array which i get from MSSQL to display in a table view form in my application. I have tried to google it but i cant seem to find an example of this. I have tried it but i am running into one small error. I get the following error Cannot resolve constructor:Simpletabledata adapter[package.mainactivity, package.itemarray]

Here is my mainactivy.java class:

public class MainActivity extends AppCompatActivity {
static String[] spaceProbeHeaders={"Name"};
private ArrayList<ClassListItems> itemArrayList;  //List items Array
private MyAppAdapter myAppAdapter; //Array Adapter
final TableView<String[]> tableView = (TableView<String[]>) findViewById(R.id.tableView);
private boolean success = false; // boolean

Connection conn; // Connection Class Initialization


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tableView.setHeaderBackgroundColor(Color.parseColor("#777777"));
    tableView.setHeaderAdapter(new SimpleTableHeaderAdapter(this,spaceProbeHeaders));
    tableView.setColumnCount(4);

    itemArrayList = new ArrayList<ClassListItems>(); // Arraylist Initialization

    // Calling Async Task
    SyncData orderData = new SyncData();
    orderData.execute("");
}

// Async Task has three overrided methods,
private class SyncData extends AsyncTask<String, String, String>
{
    String msg = "Internet/DB_Credentials/Windows_FireWall_TurnOn Error, See Android Monitor in the bottom For details!";
    ProgressDialog progress;

    @Override
    protected void onPreExecute() //Starts the progress dailog
    {
        progress = ProgressDialog.show(MainActivity.this, "Synchronising",
                "Tableview Loading! Please Wait...", true);
    }

    @Override
    protected String doInBackground(String... strings)  // Connect to the database, write query and add items to array list
    {
        try
        {
            ConnectionClass conStr=new ConnectionClass();
            conn =conStr.connectionclass();
            //Connection Object
            if (conn == null)
            {
                success = false;
            }
            else {
                // Change below query according to your own database.
                String query = "SELECT customer_first_name FROM cc_customer";
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery(query);
                if (rs != null) // if resultset not null, I add items to itemArraylist using class created
                {
                    while (rs.next())
                    {
                        try {
                            itemArrayList.add(new ClassListItems(rs.getString("customer_first_name")));
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                    msg = "Found";
                    success = true;
                } else {
                    msg = "No Data found!";
                    success = false;
                }
            }
        } catch (Exception e)
        {
            e.printStackTrace();
            Writer writer = new StringWriter();
            e.printStackTrace(new PrintWriter(writer));
            msg = writer.toString();
            success = false;
        }
        return msg;
    }

    @Override
    protected void onPostExecute(String msg) // disimissing progress dialoge, showing error and setting up my listview
    {
        progress.dismiss();
        Toast.makeText(MainActivity.this, msg + "", Toast.LENGTH_LONG).show();
        if (success == false)
        {
        }
        else {
            try {
                //myAppAdapter = new MyAppAdapter(itemArrayList, MainActivity.this);


                tableView.setDataAdapter(new SimpleTableDataAdapter(MainActivity.this,itemArrayList ));

            } catch (Exception ex)
            {

            }

        }
    }
}

and here is my classlist.java file:

    public class ClassListItems
{


    public String name; //Name

    public ClassListItems(String name)
    {

        this.name = name;
    }



    public String getName() {
        return name;
    }

Upvotes: 0

Views: 305

Answers (1)

Amit K. Saha
Amit K. Saha

Reputation: 5951

Update

N.B: OP is using SortableTableView Library.

You need to import the following to solve Cannot resolve constructor:SimpleTableDataAdapter-

import de.codecrafters.tableview.toolkit.SimpleTableDataAdapter;

Original

Do you have SimpleTableDataAdapter class in your project? It seems it can't find the class so it is not in the same package. If it is in different package, you need to import it. And on a different note, your .java file names should match the class name

And on another different note, have you tested that itemArrayList is actually populating? For Android-MSSQL, here is a tutorial pointer -

https://parallelcodes.com/connect-android-to-ms-sql-database-2/

There are many tutorials if you google it.

Upvotes: 1

Related Questions