krishnaveni
Well-Known Member
i developed one login form...when am entered username and password then clicked login button means nothing happened in my emulator..my logcat having dis error..how it is cleared...help me friends.
plz reply me....
main.xml:package com.example.login;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class LoginLayoutActivity extends Activity {
EditText username,password;
TextView error;
Button ok;
private static final String url = "jdbc:mysql://localhost/xcart";
private static final String user = "root";
private static final String pass = "";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
username=(EditText)findViewById(R.id.et_un);
password=(EditText)findViewById(R.id.et_pw);
ok=(Button)findViewById(R.id.btn_login);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException ex) {
Logger.getLogger(LoginLayoutActivity.class.getName()).log(Level.SEVERE, null, ex);
}
try {
Connection con = DriverManager.getConnection("jdbc:mysql://dev.mercuryminds.com/xc444test", "xc444tusr", "testxc444");
Statement st = con.createStatement();
String query = "SELECT password FROM xcart_customers where login='"+username+"'";
System.out.println(query);
ResultSet rs = st.executeQuery(query);
if(rs.next())
{
String dbpass = rs.getString(1);
if(dbpass.equals(password)){
error.setText("Correct Username or Password");
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.co.in"));
startActivity(i);
}
else
{
error.setText("Sorry!! Incorrect Username or Password");
}
}
} catch (SQLException ex) {
Logger.getLogger(LoginLayoutActivity.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
}
AndroidManifest.xml:<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="210dip"
android:layout_marginTop="10dip"
android:background="#DDDDDD">
<TextView
android:id="@+id/tv_un"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10pt"
android:textColor="#444444"
android:layout_alignParentLeft="true"
android:layout_marginRight="9dip"
android:layout_marginTop="20dip"
android:layout_marginLeft="10dip"
android:text="User Name:"/>
<EditText
android:id="@+id/et_un"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_toRightOf="@id/tv_un"
android:layout_alignTop="@id/tv_un"/>
<TextView
android:id="@+id/tv_pw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10pt"
android:textColor="#444444"
android:layout_alignParentLeft="true"
android:layout_below="@id/tv_un"
android:layout_marginRight="9dip"
android:layout_marginTop="15dip"
android:layout_marginLeft="10dip"
android:text="Password:"/>
<EditText
android:id="@+id/et_pw"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_toRightOf="@id/tv_pw"
android:layout_alignTop="@id/tv_pw"
android:layout_below="@id/et_un"
android:layout_marginLeft="17dip"
androidassword="true" />
<Button
android:id="@+id/btn_login"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_below="@id/et_pw"
android:layout_alignParentLeft="true"
android:layout_marginTop="15dip"
android:layout_marginLeft="110dip"
android:text="Login" />
<TextView
android:id="@+id/tv_error"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:textSize="7pt"
android:layout_alignParentLeft="true"
android:layout_below="@id/btn_login"
android:layout_marginRight="9dip"
android:layout_marginTop="15dip"
android:layout_marginLeft="15dip"
android:textColor="#AA0000"
android:text=""/>
</RelativeLayout>
...<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.login"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".LoginLayoutActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
plz reply me....
assword="true" />