Cannot get Android Studio to connect to a MySQL database - java

I cannot get my Android app (basic just tutorial style app) to connect to my MySQL database. I can get a basic IntelliJ IDEA program with essentially the same code to connect and display a list of names, but my android app just throws com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure.
When I look at the server logs in MySQL Workbench, the result is Access denied for user '(myname)'#'localhost' (using password: NO).
The weird thing is that when I check the log after I connect using my java program on IntelliJ, the logs show the same thing, several reconnect attempts, then Aborted connection 458 to db: 'mydb' user: 'root' host: 'localhost' (Got an error reading communication packets), then the same Access denied... message, but the names DO print out to the terminal in the IntelliJ app.
I created a user of my username on my Mac account I am using and nothing really matters. Same message. Any idea where I should go?
Here is the Android Studio Code:
package com.addydevelopments.sqlllllll;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class MainActivity extends AppCompatActivity {
TextView text, errorText;
Button show;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.textView2);
errorText = (TextView) findViewById(R.id.textView3);
show = (Button) findViewById(R.id.button);
show.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new Task().execute();
}
});
}
public class Task extends AsyncTask<Void, Void, Void> {
String records="", error="";
String url = "jdbc:mysql://127.0.0.1:3306/mydb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT";
String user = "root";
String password = "student";
#Override
protected Void doInBackground(Void... voids) {
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try{
Connection conn = DriverManager.getConnection(url, user, password);
Statement stat = conn.createStatement();
String sql = "SELECT * from mydb.fruit";
ResultSet rs = stat.executeQuery(sql);
while(rs.next()){
records += rs.getString("name") + "/n";
}
}
catch(Exception e){
error = e.toString();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
text.setText(records);
if(error != ""){
errorText.setText(error);
}
super.onPostExecute(aVoid);
}
}
}
And here is the IntelliJ IDEA version:
package com.addydevelopments.Dahls;
import java.sql.*;
public class Main {
public static void main(String[] args) {
String url = "jdbc:mysql://127.0.0.1:3306/mydb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=GMT";
String user = "root";
String password = "student";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
Connection myConn = DriverManager.getConnection(url, user, password);
Statement myState = myConn.createStatement();
String sql = "SELECT * from mydb.fruit";
ResultSet rs = myState.executeQuery(sql);
while (rs.next()){
System.out.println(rs.getString("name"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

Your code connects to a local sql server. There is not one running on your Android phone whilst I assume there is one running on your computer. You can use httpurlconnection to talk to your external web server and use php/sql on the server side. Just a note if the server doesn’t have a valid ssl certificate it may not work.
https://developer.android.com/reference/java/net/HttpURLConnection

Related

Executing MySQL stored procedure in thread and getting callable statements not supported

I searched about how I can fix this problem but found no solution.
I am trying to execute my stored procedecure in mysql with Android Java. I tried it with just java and it worked well, but with Android I got this error:
08-06 15:21:56.485 4057-4092/com.example.ik.myapplication E/+====/>: S1C00
08-06 15:21:56.485 4057-4092/com.example.ik.myapplication E/+====/>: Callable statments not supported.
08-06 15:21:56.485 4057-4092/com.example.ik.myapplication W/System.err:java.sql.SQLException: Callable statments not supported.
08-06 15:21:56.485 4057-4092/com.example.ik.myapplication W/System.err:at com.mysql.jdbc.Connection.prepareCall(Connection.java:1284)
08-06 15:21:56.485 4057-4092/com.example.ik.myapplication W/System.err:at com.example.ik.myapplication.MainActivity$1$1.run(MainActivity.java:61)
08-06 15:21:56.485 4057-4092/com.example.ik.myapplication W/System.err:at java.lang.Thread.run(Thread.java:761)
This is my code
MainActivity.java :
package com.example.ik.myapplication;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.*;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.*;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
AdminPage test = new AdminPage();
public String md5(String text) throws NoSuchAlgorithmException {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(text.getBytes());
byte[] digest = messageDigest.digest();
BigInteger bigInt = new BigInteger(1, digest);
String hashtext = bigInt.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return (hashtext);
}
#SuppressLint("Assert")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText input_username = (EditText) findViewById(R.id.input_username);
final EditText input_password = (EditText) findViewById(R.id.input_password);
final Button login = (Button) findViewById(R.id.login_button);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (input_username.getText().toString().equals("admin")) {
new Thread(new Runnable() {
#Override
public void run() {
try {
Class.forName("com.mysql.jdbc.Driver");
final dbconnect dbconnect = null;
final Statement statement = dbconnect.dbconnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
Log.e("+===>","before CallableStatement");
String query = "call loginadmin(?,?,?)";
CallableStatement cs=dbconnect.dbconnection().prepareCall(query);
cs.setString(1,input_username.getText().toString());
cs.setString(2,input_password.getText().toString());
cs.registerOutParameter(3,Types.INTEGER);
Log.e("+===>","after CallableStatement");
cs.execute();
final int logging =cs.getInt(3);
Log.e("+====/>", String.valueOf(logging));
runOnUiThread(new Runnable() {
#Override
public void run() {
if(logging==1){
Intent intent = new Intent(getApplicationContext(), AdminPage.class);
Toast.makeText(MainActivity.this, "WELCOME TO ADMIN PAGE", Toast.LENGTH_LONG).show();
intent.putExtra("admin_username",input_username.getText().toString());
startActivity(intent);
finish();
} else {
Toast.makeText(MainActivity.this, "Check Your Informations , Please", Toast.LENGTH_LONG).show();
}
}
});
} catch (SQLException e) {
Log.e("+====/>",e.getSQLState());
Log.e("+====/>",e.getMessage());
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}).start();
} else {
new Thread(new Runnable() {
#Override
public void run() {
try {
Class.forName("com.mysql.jdbc.Driver");
final dbconnect dbconnect = null;
final Statement statement = dbconnect.dbconnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sqlquery = "SELECT * FROM `accounts`";
final ResultSet resultSet = statement.executeQuery(sqlquery);
Account accounts;
String uuid;
final ArrayList<Account> users = new ArrayList<Account>();
while (resultSet.next()) {
accounts = new Account(resultSet.getString(1), resultSet.getString(3), resultSet.getString(4), resultSet.getString(5), resultSet.getString(6), resultSet.getString(7));
users.add(accounts);
}
runOnUiThread(new Runnable() {
#Override
public void run() {
int i = 0;
while (i < users.size()) {
try {
if (users.get(i).getUsername().equals(input_username.getText().toString()) && users.get(i).getPassword().equals(md5(input_password.getText().toString()))) {
Intent intent = new Intent(getApplicationContext(), UsersPage.class);
Toast.makeText(MainActivity.this, "Welcome to your page " + input_username.getText().toString(), Toast.LENGTH_LONG).show();
try {
dbconnect.dbconnection().close();
statement.close();
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
intent.putExtra("uuid", users.get(i).getUuid());
intent.putExtra("username", users.get(i).getUsername());
intent.putExtra("salary", users.get(i).getSalary());
intent.putExtra("statue", users.get(i).getStatue());
startActivity(intent);
finish();
break;
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
i++;
}
if (i == users.size()) {
Toast.makeText(MainActivity.this, "Check your informations please", Toast.LENGTH_SHORT).show();
}
}
});
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
}
}).start();
}
}
});
Button forgotten = (Button) findViewById(R.id.forgot);
forgotten.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent forgotten = new Intent(getApplicationContext(), ForgottenPassword.class);
startActivity(forgotten);
finish();
}
});
}
}
And This my dbconnect class :
package com.example.ik.myapplication;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class dbconnect {
private static String username;
private static String password;
private static String mysql;
public static Connection dbconnection() throws SQLException {
mysql="jdbc:mysql://10.0.2.2:3306/enterprise";
username="root";
password="borni2019";
return DriverManager.getConnection(mysql,username,password);
}
}
And this is my stored procedure :
create procedure loginadmin(IN username varchar(50), IN password varchar(50), OUT confirmed int)
begin
if exists(select * from admin_account where enterprise.admin_account.Username = username AND enterprise.admin_account.Password=password) then
set confirmed=1;
else
set confirmed=0;
end if;
end;
And thanks
From this link:
https://coderanch.com/t/305887/databases/SQLException-Callable-statments-supported
It seems like maybe the version of the MySQL driver you're using on Android is older. Can you try a newer one?

ANDROID DATABASE - Network error IOException [duplicate]

This question already has answers here:
Android ECONNREFUSED (Connection refused)
(2 answers)
Closed 5 years ago.
Hello I am beginner to android.I want to make a database connection to mssql server in my pc. I found example on the net.
I think I have something wrong in connection ip or port. I guess syntax is wrong.
I get this log :
Network error IOException: failed to connect to /127.0.0.1 (port 1433) from /:: (port 55062): connect failed: ECONNREFUSED (Connection refused)
import android.annotation.SuppressLint;
import android.os.StrictMode;
import android.util.Log;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionClass {
String ip = "127.0.0.1:1433";
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = "DBAndroid1";
String un = "TestUser";
String password = "123";
Here is my MainActivity.java.
public class MainActivity extends AppCompatActivity {
ConnectionClass connectionClass;
EditText edtuserid, edtpass;
Button btnlogin;
ProgressBar pbbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
connectionClass = new ConnectionClass();
edtuserid = (EditText) findViewById(R.id.et_username);
edtpass = (EditText) findViewById(R.id.et_password);
btnlogin = (Button) findViewById(R.id.btn_Login);
pbbar = (ProgressBar) findViewById(R.id.pbbar);
pbbar.setVisibility(View.GONE);
btnlogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DoLogin doLogin = new DoLogin();
doLogin.execute("");
}
});
}
public class DoLogin extends AsyncTask<String,String,String>
{
String z = "";
Boolean isSuccess = false;
String userid = edtuserid.getText().toString();
String password = edtpass.getText().toString();
#Override
protected void onPreExecute() {
pbbar.setVisibility(View.VISIBLE);
}
#Override
protected void onPostExecute(String r) {
pbbar.setVisibility(View.GONE);
Toast.makeText(MainActivity.this,r,Toast.LENGTH_SHORT).show();
if(isSuccess) {
Toast.makeText(MainActivity.this,r,Toast.LENGTH_SHORT).show();
}
}
#Override
protected String doInBackground(String... params) {
if(userid.trim().equals("")|| password.trim().equals(""))
z = "Please enter User Id and Password";
else
{
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = "Error in connection with SQL server";
} else {
String query = "select password from User";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if(rs.next())
{
z = "Login successfull";
isSuccess=true;
}
else
{
z = "Invalid Credentials";
isSuccess = false;
}
}
}
catch (Exception ex)
{
isSuccess = false;
z = "Exceptions burda mi ";
}
}
return z;
}
}
}
#SuppressLint("NewApi")
public Connection CONN() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName(classs).newInstance();
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";";
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO0", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO1", e.getMessage());
} catch (Exception e) {
Log.e("ERRO2", e.getMessage());
}
return conn;
}
}
I hope you can help. Thank you.
Are you doing this from an emulator or your device? On your device make sure you are on the wi-fi and not using your cellular data. It needs to be on the same network. Your IP should be 10.0.2.2 not localhost (aka 127.0.0.1) as Android emulator is on a VM. As local host for the emulator is referring to the emulator itself not the actual localhost.

Android Application working on emulator but not on device

I created an Android Application that connects to a local MySQL database to retrieve some sample data through JDBC.
When i run the application with the emulator,it works fine and loads the data.
When I run the application from my device,it freezes on loading the data,without errors from the logcat.
Here's the code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
Button bottone;
boolean connected = false;
private TextView nome1;
private TextView cognome1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bottone = (Button)findViewById(R.id.button1);
bottone.setOnClickListener(this);
nome1 = (TextView) findViewById(R.id.text_name);
cognome1 = (TextView) findViewById(R.id.text_surname);
}
class ConnectAsync extends AsyncTask<String, Void, String> {
private String name;
private String surname;
private ProgressDialog myProgress;
#Override
protected void onPreExecute()
{
super.onPreExecute();
myProgress = ProgressDialog.show(MainActivity.this, "Wait", "Loading..");
}
#Override
protected String doInBackground(String... urls) {
String url = "jdbc:mysql://192.168.56.1/prova";
String user = "myuser";
String password = "mypsw";
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(url,user,password);
} catch (ClassNotFoundException e) {
System.out.println("Driver non caricato");
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
System.out.println("Errore con url e credenziali!");
}
if(connection!= null)
{System.out.println("Connessione riuscita!");
connected = true;}
ResultSet rs = null;
try {
Statement stmt = connection.createStatement();
String sql = "SELECT NOME,COGNOME FROM amici";
rs = stmt.executeQuery(sql);
if(!rs.next())
{System.out.println("Vuota");}
else
{
do{
name = rs.getString("NOME");
surname = rs.getString("COGNOME");
}while(rs.next());}
} catch (SQLException e) {
System.out.println("Query error");
}
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
if(connected)
return "Connessione riuscita";
else return "Connessione non riuscita";
}
#Override
protected void onPostExecute(String result)
{ myProgress.dismiss();
if(result.equals("Connessione riuscita"))
{Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
nome1.setText(name);
cognome1.setText(surname);}
else
Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
}
}
public void connectToDB(View view)
{
ConnectAsync task = new ConnectAsync();
task.execute();}
#Override
public void onClick(View v) {
connectToDB(v);
}
}
The IP address i used in the JDBC string is the one i got typing "ipconfig" in windows cmd (IPv4).
The app simply shows a progress dialog until the connection is up,and then retrieves the data from the database putting it into two textviews.
As i said,when i try to connect using the Android Emulator it connects and runs fine,but when i run the application on my Device the application freezes at getting connection (progress dialog keeps loading) and no errors are given in the logcat.
I checked the minimum SDK required,and it matches with my phone Android version.
I think it's something related to the way MySQL database handles the connection requests from the emulator and from the device...any help is appreciated,thanks.
P.S: MySQL configuration file (my.ini) has the following parameters:
....
[mysqld]
bind-address= *
# skip-networking
...
...
wait_timeout = 30
interactive_timeout = 30
connect_timeout = 30

Android JDBC : Some issues with using MySql JDBC in Eclipse

I am using Eclipse in Windows and i want to connect to a MySql DB.
I know i should use JDBC. But i don't know how to use it!
I have downloaded both msi and zip file from JDBC download page.
In the zip file, a file with this name exsits : mysql-connector-java-5.1.30-bin.jar
What should i do with this?
I mean where i copy/import (in a folder or in eclipse) this file?
Note that i have this code:
import android.os.Bundle;
import android.app.Activity;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import android.os.AsyncTask;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class LearningActivity extends Activity {
private static final String url = "jdbc:mysql://cool/app";
private static final String user = "user";
private static final String pass = "password";
private Button button;
private TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)this.findViewById(R.id.button1);
tv = (TextView)this.findViewById(R.id.textView1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Connect();
}
});
}
public void Connect() {
Connect task = new Connect();
task.execute();
}
private class Connect extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... urls) {
String response = "";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, pass);
String result = "Database connection success\n";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from users");
ResultSetMetaData rsmd = rs.getMetaData();
while(rs.next()) {
result += rsmd.getColumnName(1) + ": " + rs.getInt(1) + "\n";
result += rsmd.getColumnName(2) + ": " + rs.getString(2) + "\n";
result += rsmd.getColumnName(3) + ": " + rs.getString(3) + "\n";
}
tv.setText(result);
}
catch(Exception e) {
e.printStackTrace();
tv.setText(e.toString());
}
return response;
}
#Override
protected void onPostExecute(String result) {
tv.setText(result);
}
}
}
But I get this error : ClassNotFoundException : com.mysql.jdbc.Driver
An offline discussion with #Ali revealed that he was using an old version of the ADT that does not create the libs folder as shown in the folder hierarchy on the android developers web site
Manually creating this folder solved the problem for him.
Note: The name of the folder is libs with a "s" at the end. It is easy to miss that and create lib instead.
I place these in a lib directory inside my eclipse project, then add the jar to my build path.

Calling a function with setContentView(R.layout) from another function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
When I call dbconctfun(view v) method through onclick threads and runnable code it is executing last after executing other code in the dbconctfun(view v) method. In the console it shows:
out of loop out of loop
test####### multiple class.forname
queryexct queryexct
My code:
package com.example.loginandroid;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import android.os.Looper;
public class MainActivity extends Activity{
String username,password; ResultSet rs =null;
boolean temcfag=false,temqfag=true;
public static String tag="Lifecycle activity";
EditText user,pass;
AlertDialog.Builder dialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialog=new AlertDialog.Builder(this);
dialog.setNeutralButton("OK", null);
user=(EditText)findViewById(R.id.editText1);
pass=(EditText)findViewById(R.id.editText2);
}
Thread thrd1,thrd2,thrd3;
Connection con;
String result ="",queryexct;
public void dbconctfun(View v ) throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
Log.v("test#######","multiple class.forname");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
thrd1 = new Thread(new Runnable() {
public void run() {
while (!Thread.interrupted()) {
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
}
if (con == null) {
try {
con = DriverManager.getConnection("jdbc:mysql://111.111.11.11:6666/dyne", "root1", "mysql");
} catch (SQLException e) {
e.printStackTrace();
con = null;
}
if ((thrd2 != null) && (!thrd2.isAlive()))
thrd2.start();
}
}
}
});
if ((thrd1 != null) && (!thrd1.isAlive())) thrd1.start();
thrd2 = new Thread(new Runnable() {
public void run() {
while (!Thread.interrupted()) {
if (con != null) {
if (temqfag) {
try {
Statement st = con.createStatement();
username=user.getText().toString().trim();
password=pass.getText().toString().trim();
queryexct="SELECT * FROM `user_registration` WHERE `email_id` = '"+username+"' AND `password` = '"+password+"'";
rs = st.executeQuery(queryexct);
Log.v("queryexct","queryexct");
temqfag=false;
} catch (SQLException e) {
e.printStackTrace();
con = null;
}
try {
Log.v("test#######","errorrrrrrrrrrr3");
if (temqfag) {Thread.sleep(10);}
} catch (InterruptedException e) {
e.printStackTrace();
}}
} else {
try {
Log.v("test#######","errorrrrrrrrrrr4");
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
});
Log.v("out of loop","out of loop");
if(rs!=null){
if (rs.next()) {
Log.v("test#######","errorrrrrrrrrrr1");
Looper.prepare();
Thread.interrupted();
setContentView(R.layout.activity_main1);
Log.v("test#######","errorrrrrrrrrrr1");
}
else{
Log.v("test#######","errorrrrrrrrrrr2");
Thread.interrupted();
Looper.prepare();
dialog.setMessage("Your username and password are not valid");
dialog.show();
}
}
temqfag=true;
}
}
i didn't exactly get what are you trying but from what i understand if you are trying to change the layout using threads then you won't be able to do that because it is only possible on main thread.
The setContentView is a function of your activity.
So you need to invoke it like this from other funciton:
MainActivity.this.setContentView(R.layout.activity_main1);

Categories