• Forumda özel mesajlaşmalar kapalıdır. İstek, öneri, şikayet durumunda buraya konu açabilirsiniz.

Android studio getText(); Hatası

sqayner

Cupcake
Üye
Katılım
20 Kas 2019
Mesajlar
1
Puanları
8
Yaş
14
Konum
İstanbul
Android studioda internetten bulduğum mssql ile giriş uygulaması kodlarında String passwordd = password.getText().toString(); gettext kısmında hata alıyorum yardımcı olabilecek var mı?

Kodun tamamı;

package me.akilliev.app.ui.evebaglan;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.StrictMode;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import me.akilliev.app.R;


public class Evebaglan extends AppCompatActivity {
// Declaring layout button, edit texts
Button login;
EditText username,password;
ProgressBar progressBar;
// End Declaring layout button, edit texts

// Declaring connection variables
Connection con;
String un,pass,db,ip;
//End Declaring connection variables

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

// Getting values from button, texts and progress bar
login = (Button) findViewById(R.id.button_login);
username = (EditText) findViewById(R.id.edittext_username);
password = (EditText) findViewById(R.id.edittext_password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
// End Getting values from button, texts and progress bar

// Declaring Server ip, username, database name and password
ip = "your server ip here";
db = "your database name here";
un = "your username for that database here";
pass = "your password for that database here";
// Declaring Server ip, username, database name and password

// Setting up the function when button login is clicked
login.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
CheckLogin checkLogin = new CheckLogin();// this is the Asynctask, which is used to process in background to reduce load on app process
checkLogin.execute("");
}
});
//End Setting up the function when button login is clicked
}

public class CheckLogin extends AsyncTask<String,String,String>
{
String z = "";
Boolean isSuccess = false;

@Override
protected void onPreExecute()
{
progressBar.setVisibility(View.VISIBLE);
}

@Override
protected void onPostExecute(String r)
{
progressBar.setVisibility(View.GONE);
Toast.makeText(Evebaglan.this, r, Toast.LENGTH_SHORT).show();
if(isSuccess)
{
Toast.makeText(Evebaglan.this , "Login Successfull" , Toast.LENGTH_LONG).show();
//finish();
}
}
@Override
protected String doInBackground(String... params)
{
String usernam = username.getText().toString();
String passwordd = password.getText().toString();
if(usernam.trim().equals("")|| passwordd.trim().equals(""))
z = "Please enter Username and Password";
else
{
try
{
con = connectionclass(un, pass, db, ip); // Connect to database
if (con == null)
{
z = "Check Your Internet Access!";
}
else
{
// Change below query according to your own database.
String query = "select * from login where user_name= '" + usernam.toString() + "' and pass_word = '"+ passwordd.toString() +"' ";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if(rs.next())
{
z = "Login successful";
isSuccess=true;
con.close();
}
else
{
z = "Invalid Credentials!";
isSuccess = false;
}
}
}
catch (Exception ex)
{
isSuccess = false;
z = ex.getMessage();
}
}
return z;
}
}

@SuppressLint("NewApi")
public Connection connectionclass(String user, String password, String database, String server)
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String ConnectionURL = null;
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
ConnectionURL = "jdbc:jtds:sqlserver://" + server + database + ";user=" + user+ ";password=" + password + ";";
connection = DriverManager.getConnection(ConnectionURL);
}
catch (SQLException se)
{
Log.e("error here 1 : ", se.getMessage());
}
catch (ClassNotFoundException e)
{
Log.e("error here 2 : ", e.getMessage());
}
catch (Exception e)
{
Log.e("error here 3 : ", e.getMessage());
}
return connection;
}
}
 

Benzer Konular


Üst