BoardiesITSolutions / Android-MySQL-Connector

Native MySQL Connector for Android
MIT License
51 stars 15 forks source link

The library is not being added to the project #4

Closed alexju555 closed 5 years ago

alexju555 commented 5 years ago

Hi,

I am afraid this si something very basic, but I am not able to go ahead. I would say, that the library is not being added to the project. I think I have followed carefully all steps:

1- Added to build.gradle (Module: app): repositories { maven { url 'https://jitpack.io' } }

dependencies { implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.24' }

2- I have had to increase minSdkVersion to 19

At this point everything works and I can run one simple app in one device (buttons, text views... ).

3- Add functions under OnCreeate as follows, but cannot resolve symbol 'Connection' nor 'IConnectionInterface' nor 'InvalidSQLPacketException'... .

package com.example.alexju.myapplication;

import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

Button button;
TextView textView;
String cadena;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button button = findViewById(R.id.button);
    final TextView textView = findViewById(R.id.textView2);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            //Coneción a BD
            Connection mysqlConnection = new Connection("localhost", "root",
                    "letmein", 3306, "my_database", new IConnectionInterface()
            {
                @Override
                public void actionCompleted()
                {
                    //You are now connected to the database
                    Toast.makeText(getBaseContext(), "Conectado", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void handleInvalidSQLPacketException(InvalidSQLPacketException e)
                {
                    //Handle the error
                }

                @Override
                public void handleMySQLException(MySQLException e)
                {
                    //Handle the error
                }

                @Override
                public void handleIOException(IOException e)
                {
                    //Handle the error
                }

                @Override
                public void handleMySQLConnException(MySQLConnException e)
                {
                    //Handle the error
                }

                @Override
                public void handleException(Exception e)
                {
                    //Handle the error
                }
            });

            //Lectura Dato
            cadena = "titi";
            Toast.makeText(getBaseContext(), "Dato leido", Toast.LENGTH_SHORT).show();
            //Mostrar dato leido
            textView.setText(cadena);
            Toast.makeText(getBaseContext(), "dato escrito", Toast.LENGTH_SHORT).show();

        }
    });

}

}

boardy commented 5 years ago

Hi,

It does sound like the library isn't being included as you say. Did the gradle project sync complete OK as if it couldn't find the library for some reason gradle should have failed.

I'd probably try doing a gradle resync and a clean and build of your project and see if that helps.

If no joy would it be possible for you to send me a copy of your apps build.gradle and let me know which Android version you are using?

Thanks

Chris

On Tue, 1 Jan 2019, 19:20 alexju555 <notifications@github.com wrote:

Hi,

I am afraid this si something very basic, but I am not able to go ahead. I would say, that the library is not being added to the project. I think I have followed carefully all steps:

1- Added to build.gradle (Module: app): repositories { maven { url 'https://jitpack.io' } }

dependencies { implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.24' }

2- I have had to increase minSdkVersion to 19

At this point everything works and I can run one simple app in one device (buttons, text views... ).

3- Add functions under OnCreeate as follows, but cannot resolve symbol 'Connection' nor 'IConnectionInterface' nor 'InvalidSQLPacketException'... .

package com.example.alexju.myapplication;

import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

Button button;

TextView textView;

String cadena;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button button = findViewById(R.id.button);

final TextView textView = findViewById(R.id.textView2);

button.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View view) {

        //Coneción a BD

        Connection mysqlConnection = new Connection("localhost", "root",

                "letmein", 3306, "my_database", new IConnectionInterface()

        {

            @Override

            public void actionCompleted()

            {

                //You are now connected to the database

                Toast.makeText(getBaseContext(), "Conectado", Toast.LENGTH_SHORT).show();

            }

            @Override

            public void handleInvalidSQLPacketException(InvalidSQLPacketException e)

            {

                //Handle the error

            }

            @Override

            public void handleMySQLException(MySQLException e)

            {

                //Handle the error

            }

            @Override

            public void handleIOException(IOException e)

            {

                //Handle the error

            }

            @Override

            public void handleMySQLConnException(MySQLConnException e)

            {

                //Handle the error

            }

            @Override

            public void handleException(Exception e)

            {

                //Handle the error

            }

        });

        //Lectura Dato

        cadena = "titi";

        Toast.makeText(getBaseContext(), "Dato leido", Toast.LENGTH_SHORT).show();

        //Mostrar dato leido

        textView.setText(cadena);

        Toast.makeText(getBaseContext(), "dato escrito", Toast.LENGTH_SHORT).show();

    }

});

}

}

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BoardiesITSolutions/Android-MySQL-Connector/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/AEUtM0HW9Xb9XMHdxbXqruArqKn9sHZ3ks5u-7UOgaJpZM4ZmAEP .

alexju555 commented 5 years ago

Hi Chris,

No way synchronizing, cleaning, building, rebuilding... I think I have tried all combinations. Gradle sync with projects looks OK: capture

Android Studio 3.2.1

Attaching files. Files are actually *.rar, I do not have winzip, sorry. I changed manually .rar to .zip, so you should have to change extension manually to .rar. Otherwishe I could not send them. app.zip gradle.zip

.

Thank you very much

boardy commented 5 years ago

Hi,

I believe its because the imports haven't been included in your activity class where you're trying to create the connection. If you place the cursor over one of the errors such as the IConnectionInterface and press Alt + Enter Android Studio should give you helpers, one of them will be to import class. Do this for each of the errors or you can add the following two lines to the top of your class file (before the class name)

import com.BoardiesITSolutions.AndroidMySQLConnector.*;
import com.BoardiesITSolutions.AndroidMySQLConnector.Exceptions.*;

The above will make all classes within the library available for use within your activity, although you should really only be importing exactly what library classes you need but doing the above will confirm that its referencing the library OK and can build your project.

If you include the above lines you can do Ctrl + Alt + O which will optimise the imports of your class so it only imports what's required instead of doing a wildcard import.

Let me know how you get on.

Thanks

Chris

alexju555 commented 5 years ago

Hi,

Perfect. Thank you very much for your support and even for explaining how to work better with Android Studio .

So before close this issue, how do I know, aside helpers you explained, which imports are needed from library documentation? Do you think it should be added in "Using the Library" section? or it is just too basic?

boardy commented 5 years ago

Hi,

Great news, glad you got it working.

I don't really tend to worry too much myself I just let Android studio do handle it for me instead of adding the imports myself, probably why I never thought of mentioning the imports in the read me file :)

If you start typing a class name and then let the auto complete finish it off, Android Studio will automatically add the import, or if not, then the Ctrl + Alt + Enter on the error to do the import automatically.

I have added a troubleshooting section to the read me file to mention this though.

Thanks

Chris

alexju555 commented 5 years ago

I see it, good. Thanks again and I wish you to have a great year!