这是我的登录java 登录活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
connectionClass = new ConnectionClass();
edtuserid = (EditText) findViewById(R.id.edtuserid);
edtpass = (EditText) findViewById(R.id.edtpass);
btnlogin = (Button) findViewById(R.id.btnlogin);
pbbar = (ProgressBar) findViewById(R.id.pbbar);
pbbar.setVisibility(View.GONE);
shp = this.getSharedPreferences("UserInfo", MODE_PRIVATE);
String userid = shp.getString("UserId", "none");
if (userid.equals("none") || userid.trim().equals("")) {
} else {
Intent i = new Intent(MainActivity.this, HomeActivity.class);
startActivity(i);
finish();
}
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();
SharedPreferences.Editor edit = shp.edit();
edit.putString("UserId", userid);
edit.commit();
}
@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 * from dbo.demo where slsperid='" + userid + "' and Password='" + password + "'";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if(rs.next())
{
z = "Login successfull";
isSuccess=true;
if (rs.getString("AccountType").equals("Seller")){
Intent i = new Intent(MainActivity.this, HomeActivity.class);
startActivity(i);
} else if (rs.getString("AccountType").equals("Supervisor")){
Intent i = new Intent(MainActivity.this, SupervisorActivity.class);
startActivity(i);
} else if (rs.getString("AccountType").equals("Manager")){
Intent i = new Intent(MainActivity.this, ManagerActivity.class);
startActivity(i);
}
}
else
{
z = "Invalid Credentials";
isSuccess = false;
}
}
}
catch (Exception ex)
{
isSuccess = false;
z = "Exceptions";
}
}
return z;
}
}
这是我的连接类 用于连接ms sql server的连接类
@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);
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";";
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return conn;
}
这是我的清单 在我添加权限互联网后,我的应用程序将崩溃并停止
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:label="@string/title_activity_home"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".SupervisorActivity"
android:label="@string/title_activity_supervisor"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".ManagerActivity"
android:label="@string/title_activity_manager"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Profile"
android:label="@string/title_activity_profile"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Dashboard"
android:label="@string/title_activity_dashboard"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".SupervisorProfile"
android:label="@string/title_activity_supervisor_profile"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".SupervisorDashboard"
android:label="@string/title_activity_supervisor_dashboard"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".ManagerProfile"
android:label="@string/title_activity_manager_profile"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".ManagerDashboard"
android:label="@string/title_activity_manager_dashboard"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>
当我尝试登录我的应用程序时,这是我的logcat错误
12-26 16:29:10.927 22611-22764/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.mi008.lhgroup, PID: 22611
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.VerifyError: net/sourceforge/jtds/jdbc/TdsCore
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:359)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at java.sql.DriverManager.getConnection(DriverManager.java:179)
at java.sql.DriverManager.getConnection(DriverManager.java:144)
at com.example.mi008.lhgroup.ConnectionClass.CONN(ConnectionClass.java:34)
at com.example.mi008.lhgroup.MainActivity$DoLogin.doInBackground(MainActivity.java:90)
at com.example.mi008.lhgroup.MainActivity$DoLogin.doInBackground(MainActivity.java:62)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
有人知道为什么我的应用程序可以在api级别23和级别27中正常运行但在api级别19崩溃 我想知道这件事 所以有人请我帮忙 谢谢你