You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vercel无法部署GitHub学生数据库变更及Android登录系统崩溃求助

技术问题求助:Vercel部署失败与Android登录系统异常

问题1:Vercel无法部署GitHub上的学生数据库相关代码变更

无法将GitHub仓库中更新的学生数据库代码部署到Vercel平台,部署流程中断或无明确报错提示。

问题2:Android学生数据库应用登录系统异常

点击登录按钮应用直接崩溃;输入正确用户名和密码后,无法完成登录跳转。

已执行操作步骤

  • 添加用户名、密码输入框(EditText控件)
  • 添加登录按钮
  • 为登录按钮设置点击监听器,用于验证用户输入

相关代码

activity_main.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <EditText
        android:id="@+id/etUsername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Username"/>

    <EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:hint="Password"/>

    <Button
        android:id="@+id/btnLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Login"/>
        
    <Button
        android:id="@+id/btnRegister"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Register"/>
</LinearLayout>

MainActivity.java

package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    EditText etUsername, etPassword;
    Button btnLogin, btnRegister;
    DatabaseHelper dbHelper;

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

        etUsername = findViewById(R.id.etUsername);
        etPassword = findViewById(R.id.etPassword);
        btnLogin = findViewById(R.id.btnLogin);
        btnRegister = findViewById(R.id.btnRegister);
        dbHelper = new DatabaseHelper(this);

        btnRegister.setOnClickListener(v -> {
            String user = etUsername.getText().toString();
            String pass = etPassword.getText().toString();
            if (dbHelper.registerUser(user, pass)) {
                Toast.makeText(this, "用户注册成功!", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "该用户已存在!", Toast.LENGTH_SHORT).show();
            }
        });

        btnLogin.setOnClickListener(v -> {
            String user = etUsername.getText().toString();
            String pass = etPassword.getText().toString();
            if (dbHelper.loginUser(user, pass)) {
                Intent intent = new Intent(MainActivity.this, GradeEntryActivity.class);
                intent.putExtra("username", user);
                startActivity(intent);
                finish();
            } else {
                Toast.makeText(this, "登录失败:用户名或密码错误!", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

activity_grade_entry.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <TextView
        android:id="@+id/tvWelcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/tvGradeDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="你的成绩: -"
        android:paddingTop="8dp"/>

    <EditText
        android:id="@+id/etGrade"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="输入成绩" />

    <Button
        android:id="@+id/btnSave"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="保存成绩" />
</LinearLayout>

GradeEntryActivity.java

package com.example.myapplication;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class GradeEntryActivity extends AppCompatActivity {
    EditText etGrade;
    Button btnSave;
    TextView tvWelcome, tvGradeDisplay;
    DatabaseHelper dbHelper;
    String username;

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

        etGrade = findViewById(R.id.etGrade);
        btnSave = findViewById(R.id.btnSave);
        tvWelcome = findViewById(R.id.tvWelcome);
        tvGradeDisplay = findViewById(R.id.tvGradeDisplay);
        dbHelper = new DatabaseHelper(this);

        username = getIntent().getStringExtra("username");
        tvWelcome.setText("欢迎, " + username);

        String existingGrade = dbHelper.getGrade(username);
        if (existingGrade != null && !existingGrade.isEmpty()) {
            tvGradeDisplay.setText("你的成绩: " + existingGrade);
        }

        btnSave.setOnClickListener(v -> {
            String grade = etGrade.getText().toString();
            if (dbHelper.updateGrade(username, grade)) {
                Toast.makeText(this, "成绩保存成功!", Toast.LENGTH_SHORT).show();
                tvGradeDisplay.setText("你的成绩: " + grade);
            } else {
                Toast.makeText(this, "保存失败,请重试.", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

DatabaseHelper.java

package com.example.myapplication;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "UserGrades.db";
    public static final String TABLE_NAME = "user_table";

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + TABLE_NAME +
                " (username TEXT PRIMARY KEY, password TEXT, grade TEXT)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }

    public boolean registerUser(String username, String password) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put("username", username);
        contentValues.put("password", password);
        contentValues.put("grade", ""); // 初始为空
        long result = db.insert(TABLE_NAME, null, contentValues);
        db.close();
        return result != -1;
    }

    public boolean loginUser(String username, String password) {
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME +
                " WHERE username=? AND password=?", new String[]{username, password});
        int count = cursor.getCount();
        cursor.close();
        db.close();
        return count > 0;
    }

    public boolean updateGrade(String username, String grade) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put("grade", grade);
        int rows = db.update(TABLE_NAME, contentValues, "username=?", new String[]{username});
        db.close();
        return rows > 0;
    }

    public String getGrade(String username) {
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery("SELECT grade FROM " + TABLE_NAME + " WHERE username=?", new String[]{username});
        String grade = null;
        if (cursor.moveToFirst()) {
            grade = cursor.getString(0);
        }
        cursor.close();
        db.close();
        return grade;
    }
}

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
        
        <activity android:name=".GradeEntryActivity" android:exported="true"/>
        <activity android:name=".MainActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
    </application>
</manifest>

问题解决方案

针对Android登录系统异常

  1. 修复Cursor与数据库连接未关闭问题
    原代码中数据库操作后未关闭Cursor和数据库连接,会引发资源泄漏导致崩溃,已在DatabaseHelper的所有方法中添加关闭逻辑。

  2. 添加空输入校验
    在MainActivity的登录点击事件中,先校验用户名和密码是否为空,避免空值触发数据库异常:

    btnLogin.setOnClickListener(v -> {
        String user = etUsername.getText().toString().trim();
        String pass = etPassword.getText().toString().trim();
        if (user.isEmpty() || pass.isEmpty()) {
            Toast.makeText(this, "请输入完整的用户名和密码", Toast.LENGTH_SHORT).show();
            return;
        }
        // 原有登录逻辑
    });
    
  3. 兼容旧版本数据库
    若之前安装过旧版本应用,卸载后重新安装;或修改DatabaseHelper构造方法中的版本号(如从1改为2),触发数据库升级重建表结构。

针对Vercel部署失败

  1. 查看部署日志定位问题
    登录Vercel控制台,进入对应项目的部署记录,查看详细错误日志,确认是依赖安装失败、构建命令错误还是环境变量缺失等问题。
  2. 确认GitHub权限
    检查Vercel是否拥有该GitHub仓库的读写权限,权限不足则重新授权。
  3. 验证构建配置
    确认项目根目录的vercel.json或package.json中构建命令正确,前端项目需确保build命令能生成正确的静态文件目录(如dist)。
  4. 检查代码与依赖
    确认代码中文件路径引用正确,后端项目需在Vercel控制台配置好数据库连接等环境变量。

内容的提问来源于stack exchange,提问作者Harsheen Kaur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 09:39:52