gpt4 book ai didi

java - app-debuk.apk停止工作

转载 作者:行者123 更新时间:2023-12-03 05:56:57 25 4
gpt4 key购买 nike

我是Android编程的新手,这是我在Gradle的第一个项目。过去,我使用Maven for Java。因此,我使用Android Studio制作了一个应用程序,如果我单击,请运行并选择我的手机,它将构建并安装apk到我的手机中,然后自动打开并运行正常。

因此,我想与一位 friend 分享我的进度,因此我单击了 Make Project ,它在 /app/build/outputs/apk/app-debug.apk中生成了 app-debug.apk ,但是如果我尝试安装该应用程序,请在启动后使用以下文本关闭自身的应用程序强制:“不幸的是,该应用程序停止了的工作”。

这是我的 build.gradle (Module:app):

Overview

和我的 build.gradle (项目:Autosiskola):Overview

错误代码:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.androidports.autosiskola/com.androidports.‌​autosiskola.MainActi‌​vity}: java.lang.ClassNotFoundException: Didn't find class "com.androidports.autosiskola.MainActivity" on path: DexPathList[[zip file "/data/app/com.androidports.autosiskola-1/base.apk"],nativeL‌​ibraryDirectories=[/‌​data/app/com.android‌​ports.autosiskola-1/‌​lib/arm64, /vendor/lib64, /system/lib64]]

我的主要 Activity :

    package com.androidports.autosiskola;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;

import android.widget.Toast;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MainActivity extends AppCompatActivity {

EditText username, password;
Button login;
ProgressBar progressBar;

Connection conn = null;
PreparedStatement pst = null;
ResultSet rs = null;

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

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

username = (EditText) findViewById(R.id.txtUsername);
password = (EditText) findViewById(R.id.txtPassword);

login = (Button) findViewById(R.id.btnLogin);

progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);

conn = DBConnect.Connector();

login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (username.toString().trim().isEmpty() && password.toString().isEmpty()) {
Toast.makeText(MainActivity.this, "Nincs felhasználónév / jelszó megadva!", Toast.LENGTH_SHORT).show();
} else {
switch (v.getId()) {
case R.id.btnLogin:
new doMySQL().execute();
break;
}
}
}
});
}

public class doMySQL extends AsyncTask<Void, Void, String> {

final String uname = username.getText().toString();
final String passwd = password.getText().toString();
String getUsername = null;
String getPassword = null;
String getPermission = null;
String resValue = "undone";
int exists = 0;

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

protected String doInBackground(Void... params) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
conn = DBConnect.Connector();

try {
pst = conn.prepareStatement("SELECT username FROM userList WHERE username=?");
pst.setString(1, String.valueOf(uname));
rs = pst.executeQuery();
if (rs.next()) {
getUsername = rs.getString(1);
}
pst = conn.prepareStatement("SELECT username FROM userList WHERE username=?");
pst.setString(1, String.valueOf(uname));
rs = pst.executeQuery();
if (rs.wasNull()) {
Toast.makeText(MainActivity.this, "Hibás felhasználónév / jelszó!", Toast.LENGTH_SHORT).show();
resValue = "undone";
}

pst = conn.prepareStatement("SELECT password FROM userList WHERE username=?");
pst.setString(1, String.valueOf(uname));
rs = pst.executeQuery();
if (rs.next()) {
getPassword = rs.getString(1);
}
pst = conn.prepareStatement("SELECT password FROM userList WHERE username=?");
pst.setString(1, String.valueOf(uname));
rs = pst.executeQuery();
if (rs.wasNull()) {
Toast.makeText(MainActivity.this, "Hibás felhasználónév / jelszó!", Toast.LENGTH_SHORT).show();
resValue = "undone";
}

pst = conn.prepareStatement("SELECT username FROM userList WHERE username=? AND password=?");
pst.setString(1, String.valueOf(uname));
pst.setString(2, String.valueOf(passwd));
rs = pst.executeQuery();
if (rs.next()) {
exists = 1;
}
pst = conn.prepareStatement("SELECT username FROM userList WHERE username=? AND password=?");
pst.setString(1, String.valueOf(uname));
pst.setString(2, String.valueOf(passwd));
if (rs.wasNull()) {
Toast.makeText(MainActivity.this, "Hibás felhasználónév / jelszó!", Toast.LENGTH_SHORT).show();
exists = 0;
resValue = "undone";
}

if (exists == 1) {
pst = conn.prepareStatement("SELECT permission FROM userList WHERE username=?");
pst.setString(1, String.valueOf(uname));
rs = pst.executeQuery();
while (rs.next()) {
getPermission = rs.getString(1);
resValue = "Done";
}
}

} catch (SQLException e) {
Toast.makeText(MainActivity.this, "Hibás felhasználónév / jelszó!", Toast.LENGTH_SHORT).show();
}

return resValue;
}

protected void onPostExecute(String result) {
if ("Done".equals(result)) {
progressBar.setVisibility(View.GONE);
if ("teacher".equals(getPermission)) {
Intent openTeacher = new Intent(MainActivity.this, TeacherLogin.class);
progressBar.setVisibility(View.GONE);
startActivity(openTeacher);
} else if ("student".equals(getPermission)) {
Intent openStudent = new Intent(MainActivity.this, StudentLogin.class);
progressBar.setVisibility(View.GONE);
startActivity(openStudent);
}
} else if ("undone".equals(result)) {
Toast.makeText(MainActivity.this, "Hibás felhasználónév / jelszó!", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}
}

}

当我通过USB上的“运行”命令安装该应用程序时,该应用程序可以运行,但是如果我要安装app-debug.apk,则该应用程序将无法运行。

我的lib文件夹中有一个mysql-connector-java依赖项,仅此而已。

最佳答案

有趣的事实:当我使用Windows资源管理器将app-debug.apk复制到SDCard时,应用程序在启动后会自行停止。但是,如果我打开一个新命令行并进行以下操作:

adb install app-debug.apk

输出/ apk / 文件夹中可以正常工作。我认为这就是解决方案。

关于java - app-debuk.apk停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44349065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com