AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[android](coding)

Martin Hope
Hritik Gupta
Asked: 2023-09-26 23:12:11 +0800 CST

MutableStateOf 未在 Jetpack Compose 中重新初始化

  • 5

下面是一个简单的可组合函数,当我记录 pd 对象时,它会打印保留(布尔)字段的当前值。但初始化 isChecked 变量后,该值始终为 !pd.retained。因此,我的开关状态总是不正确。

@Composable
fun DocumentModalSheet( pd: PrintDocument,
onSwitchSelected: (id: Long, status: Boolean) -> Unit,
) {
Log.i("DocumentModalSheet", "DocumentModalSheet: ${pd.retained}")
// This prints the correct value of pd.retained
var isChecked by remember {
    mutableStateOf(pd.retained)
}
Log.i("DocumentModalSheet", "DocumentModalSheet: $isChecked") 
// This prints the incorrect value of pd.retained       
Column(
    modifier = Modifier.fillMaxWidth()
) {
    Switch(checked = isChecked, onCheckedChange = {
        isChecked = it,
        onSwitchSelected(pd.id, it)
    } )
}}

这就是我从 PrintDocumentScreen 可组合项调用上述函数的方式。当调用 DocumentCard 的 lambda 时,我将更新 clickedPD 变量并显示模式表。

@Composable
fun PrintDocumentScreen(viewModel: PrintDocumentViewModel) {
val pdListFlow = viewModel.pdListFlow.collectAsState()
var clickedPD by remember { mutableStateOf(PrintDocument()) }
val modalSheetState = rememberModalBottomSheetState(..)

ModalBottomSheetLayout(
    sheetContent = {
        DocumentModalSheet(clickedPD){
         viewModel.doSomething(id, status)
        }
    },
    content = {
        Scaffold(modifier = Modifier.fillMaxSize()) { paddingValues ->
            Column(modifier = Modifier.fillMaxSize().padding(paddingValues)
            ) {
                pdListFlow.value?.let { it ->
                    when (it) {
                        is Resource.Success -> {
                            if (it.data.printDocuments.isNotEmpty()) {
                                LazyColumn(modifier = Modifier.fillMaxSize()) {
                                    items(it.data.printDocuments.size) { index ->
                                        DocumentCard(it.data.printDocuments[index]) {
                                            clickedPD = it
                                            coroutineScope.launch {
                                                modalSheetState.show()
                                            }
                                        }
                                    }
                                }

                            } else {
                                NoDocumentPresent()
                            }
                        }
                    }
                }
            }}})}

到目前为止我已经尝试过...

我尝试将 isChecked 初始化部分提升到 PrintDocumentScreen 但没有帮助。

我还使用衍生状态()来初始化 PrintDocumentScreen 中的 isChecked 变量

var clickedPD by remember { mutableStateOf(PrintDocument()) }
val isChecked by remember {
    derivedStateOf { clickedPD.retained }
}

我注意到开关的状态由所有文档卡共享,因为当我检查开关、隐藏模式表、点击另一张卡时,开关已被选中。

图片参考

android
  • 1 个回答
  • 31 Views
Martin Hope
Евгений s
Asked: 2023-09-24 23:25:09 +0800 CST

Android 定期 WorkManager 不起作用

  • 5

我想使用 Dagger Hilt 依赖注入运行PeriodicWork。但是,它不会定期工作。我已经检查过我的代码很多次了。尽管我希望每秒收到一条消息,但最多只有一条成功完成工作的消息。

这是 MainActivity 的代码:

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            RunARepeatableWorkUsingWorkManagerTheme {

            val lifecycleOwner = LocalLifecycleOwner.current

            LaunchedEffect(key1 = Unit ){

                val workRequest = PeriodicWorkRequestBuilder<CustomWorker>(
                    repeatInterval = 1,
                    repeatIntervalTimeUnit = TimeUnit.SECONDS,)
                    .setBackoffCriteria(
                        backoffPolicy = BackoffPolicy.LINEAR,
                        duration = Duration.ofSeconds(5))
                    .build()

                    val workManager = WorkManager.getInstance(applicationContext)
                    workManager.enqueueUniquePeriodicWork("myWork", ExistingPeriodicWorkPolicy.KEEP, workRequest)

                     workManager.getWorkInfosForUniqueWorkLiveData("myWork")
                    .observe(lifecycleOwner){ it ->
                        it.forEach {workInfo ->
                        Log.d("MyWorker: MainActivity", "${workInfo.state}")
                    }
                }
            }
            }
        }
    }
}   

我的工人看起来像这样:

@HiltWorker
class CustomWorker @AssistedInject constructor(
    @Assisted context: Context,
    @Assisted workerParameters: WorkerParameters
) : CoroutineWorker(context, workerParameters){
        override suspend fun doWork(): Result {
            try {
                println("MyWorker : The result or the worker is Success")
                return Result.success()
            } catch (e: Exception) {
                Log.e("MyWorker: CustomWorker", "Worker failed: ${e.message}", e)
                return Result.failure()
            }
        }
}

HiltAndroidApp是:

@HiltAndroidApp
class AppInstance : Application(), Configuration.Provider{
    @Inject lateinit var workerFactory: HiltWorkerFactory

    override fun getWorkManagerConfiguration() =
        Configuration.Builder()
            .setWorkerFactory(workerFactory)
            .build()

}

另外,我在清单文件中添加了:

<provider
    android:name="androidx.startup.InitializationProvider"
    android:authorities="${applicationId}.androidx-startup"
    android:exported="false"
    tools:node="merge"
    >
    <meta-data
        android:name="androidx.work.impl.WorkManagerInitializer"
        android:value="androidx.startup"
        tools:node="remove" />
</provider>

Logcat 仅显示:

 2023-09-24 18:16:46.712  4819-4819  MyWorker: MainActivity  com...epeatableworkusingworkmanager  D  ENQUEUED
2023-09-24 18:17:47.375  4819-4854  System.out              com...epeatableworkusingworkmanager  I  MyWorker : The result or the worker is Success
2023-09-24 18:17:47.429  4819-4819  MyWorker: MainActivity  com...epeatableworkusingworkmanager  D  RUNNING
2023-09-24 18:17:47.437  4819-4819  MyWorker: MainActivity  com...epeatableworkusingworkmanager  D  ENQUEUED

就这样。问题是:为什么我看不到每秒都在完成工作的消息?我将不胜感激任何帮助!

android
  • 1 个回答
  • 14 Views
Martin Hope
Alpha Gaming
Asked: 2023-09-24 17:06:31 +0800 CST

从前台服务的通知中恢复被终止的活动

  • 5

Stack Overflow 上有一些类似的问题,但它们是通过单击通知来恢复暂停的活动。这已经对我有用了。

我正在开发一个视频/音频通话应用程序,如果我在前台服务运行时最小化我的应用程序,那么如果我单击通知,我的活动将恢复并运行良好。

我通过这段代码实现了这种行为:

val notificationIntent = Intent(this, VoiceCallActivity::class.java)
        notificationIntent.setAction(Intent.ACTION_MAIN)
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER)
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        notificationIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
        val notificationPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)

        val notification = NotificationCompat.Builder(this, "call")
            .setSmallIcon(R.drawable.logo_talkify)
            .setContentTitle(title)
            .setContentIntent(notificationPendingIntent)
            .setContentText("Ongoing call")
            .setUsesChronometer(true)
            .build()

        startForeground(1, notification)

现在的问题是,假设用户在通话正在进行时关闭了最近使用的应用程序(这将破坏通话活动)。现在,如果用户单击通知,它应该恢复活动而不是重新创建它。因为这是预期的行为。但我无法实现这一点,我尝试寻找解决方案,但尚未找到任何解决方案。

我怎样才能实现这个目标?

android
  • 1 个回答
  • 21 Views
Martin Hope
Matias Chiaia
Asked: 2023-09-24 04:54:04 +0800 CST

使用预填充的房间数据库时应用程序崩溃

  • 5

我正在尝试使用预先填充的 Room 数据库,但在尝试使用该数据库时出现崩溃,并出现以下错误: java.lang.NullPointerException: cursor.getString(toColumnIndex) must not be null

一切正常,直到我添加该createFromAsset("databses/test.db")方法,当它崩溃时。如果我不执行该getAllCocktails()方法,则不会发生任何崩溃。我已经检查了我插入的数据库是否完全相同,并且找不到任何差异(我还检查了使用 AppInspection 加载的数据)

我不仅进行了测试,getAllCocktails()还尝试使用完全参数化的构造函数进行插入

我将发布(一些)我的代码和日志,以便更容易诊断我尝试使用 Room 的版本 2.5.1 和 2.5.2

测试.db文件

活动:

public class PedirTragoActivity extends AppCompatActivity {

    AppDatabase db;

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

        db = AppDatabase.getInstance(this.getApplication());

        db.cocktailDAO().getAllCocktails();
    }
}

房间数据库:

@Database(entities = {
        BottleEntity.class,
        BottleIngredientEntity.class,
        CocktailEntity.class,
        CocktailIngredientEntity.class,
        IngredientTypeEntity.class
},
        version = 7)
public abstract class AppDatabase extends RoomDatabase {
    public static AppDatabase INSTANCE;

    public abstract BottleDAO bottleDAO();

    public abstract BottleIngredientDAO bottleIngredientDAO();

    public abstract CocktailDAO cocktailDAO();

    public abstract CocktailIngredientDAO cocktailIngredientDAO();

    public abstract IngredientTypeDAO ingredientTypeDAO();
    public static AppDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(context, AppDatabase.class, "barbotApp.db")
                    .allowMainThreadQueries()
                    .fallbackToDestructiveMigration()
                    .createFromAsset("databases/test.db")
                    .build();

        }
        return INSTANCE;
    }
}

瓶子实体:

@Entity(tableName = "bottles")
public class BottleEntity {
    @PrimaryKey
    @NonNull
    private int position;//Del 0 al 7 son alcoholes, el 8 es shaker y del 9 al 16 son mezclas
    private String name;
    @NonNull
    private int capacity;
    @NonNull
    private int currentAmount;

    public BottleEntity() {
    }

    public BottleEntity(int position, String name, int capacity, int currentAmount) {
        this.position = position;
        this.name = name;
        this.capacity = capacity;
        this.currentAmount = currentAmount;
    }
    @Ignore
    public BottleEntity(int position, String name, int capacity) {
        this.position = position;
        this.name = name;
        this.capacity = capacity;
        this.currentAmount = capacity;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCapacity() {
        return capacity;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }

    public int getCurrentAmount() {
        return currentAmount;
    }

    public void setCurrentAmount(int currentAmount) {
        this.currentAmount = currentAmount;
    }
}

瓶子成分实体:

@Entity(tableName = "bottle_ingredient",
        foreignKeys = {
                @ForeignKey(entity = BottleEntity.class, parentColumns = "position", childColumns = "bottlePos"),
                @ForeignKey(entity = IngredientTypeEntity.class, parentColumns = "id", childColumns = "ingredientId")
        })
public class BottleIngredientEntity {

    @PrimaryKey(autoGenerate = true)
    @NonNull
    private int id;

    @NonNull
    private int bottlePos;


    @NonNull
    private int ingredientId;


    public BottleIngredientEntity() {
    }

    public BottleIngredientEntity(int bottlePos, int ingredientId) {
        this.bottlePos = bottlePos;
        this.ingredientId = ingredientId;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getBottlePos() {
        return bottlePos;
    }

    public void setBottlePos(int bottlePos) {
        this.bottlePos = bottlePos;
    }

    public int getIngredientId() {
        return ingredientId;
    }

    public void setIngredientId(int ingredientId) {
        this.ingredientId = ingredientId;
    }
}

鸡尾酒成分实体:

@Entity(tableName = "cocktail_ingredients",
        foreignKeys = {
                @ForeignKey(entity = IngredientTypeEntity.class, parentColumns = "id", childColumns = "typeId"),
                @ForeignKey(entity = CocktailEntity.class, parentColumns = "id", childColumns = "cocktailId")
        })
public class CocktailIngredientEntity {
    @PrimaryKey(autoGenerate = true)
    @NonNull
    private int id;
    @NonNull
    private int typeId;
    @NonNull
    private int quantity;
    @NonNull
    private int cocktailId;

    public CocktailIngredientEntity(int typeId, int quantity, int cocktailId) {
        this.typeId = typeId;
        this.quantity = quantity;
        this.cocktailId = cocktailId;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getTypeId() {
        return typeId;
    }

    public void setTypeId(int typeId) {
        this.typeId = typeId;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public int getCocktailId() {
        return cocktailId;
    }

    public void setCocktailId(int cocktailId) {
        this.cocktailId = cocktailId;
    }
}

成分类型实体:

@Entity(tableName = "ingredient_types")
public class IngredientTypeEntity {
    @PrimaryKey(autoGenerate = true)
    @NonNull
    private int id;
    private String name;

    public IngredientTypeEntity() {
    }

    public IngredientTypeEntity(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

鸡尾酒实体:

@Entity(tableName = "cocktails")
public class CocktailEntity {
    @PrimaryKey(autoGenerate = true)
    @NonNull
    private int id;

    private String name;

    @NonNull
    private boolean isOnStock;
    @NonNull
    private boolean hasIce;

    private String imgName;

    public CocktailEntity(String name, boolean isOnStock, boolean hasIce, String imgName) {
        this.name = name;
        this.isOnStock = isOnStock;
        this.hasIce = hasIce;
        this.imgName = imgName;
    }

    @Ignore
    public CocktailEntity(String name, boolean hasIce, String imaName) {
        this.name = name;
        this.isOnStock = false;
        this.hasIce = hasIce;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isOnStock() {
        return isOnStock;
    }

    public void setOnStock(boolean onStock) {
        isOnStock = onStock;
    }

    public boolean isHasIce() {
        return hasIce;
    }

    public void setHasIce(boolean hasIce) {
        this.hasIce = hasIce;
    }

    public String getImgName() {
        return imgName;
    }

    public void setImgName(String imgName) {
        this.imgName = imgName;
    }
}

鸡尾酒道:

@Dao
public interface CocktailDAO {

    @Insert
    long insertCocktail(CocktailEntity cocktail);

    @Query("SELECT id FROM cocktails WHERE name = :name")
    int getCocktailId(String name);

    @Query("SELECT c.* FROM cocktails AS c WHERE c.id = :id")
    CocktailEntity getCocktail(int id); //Need to use a repository, separate this 2 parts

    @Query("SELECT * FROM cocktails")
    List<CocktailEntity> getAllCocktails();

    @Query("SELECT cocktails.id FROM cocktails")
    List<Integer> getAllCocktailIds();

    @Query("SELECT * FROM cocktails" +
            " WHERE cocktails.isOnStock = 1")
    List<CocktailEntity> getAllCocktailsInStock();

    @Query("SELECT isOnStock FROM cocktails WHERE id = :id")
    boolean isCocktailInStock(int id);

    @Query("UPDATE cocktails SET isOnStock = :isOnStock WHERE id = :id")
    void updateCocktailStock(int id, boolean isOnStock);
}

Logcat:

2023-09-23 17:17:20.600  8250-8250  Choreographer           com.mecatronica.barbot               I  Skipped 67 frames!  The application may be doing too much work on its main thread.
2023-09-23 17:17:20.801  8250-8594  AdrenoGLES-0            com.mecatronica.barbot               I  QUALCOMM build                   : 03e27f8, I326e6aff90
                                                                                                    Build Date                       : 11/02/20
                                                                                                    OpenGL ES Shader Compiler Version: EV031.32.02.04
                                                                                                    Local Branch                     : mybrancheb1d781c-1a78-f1f4-8c78-ac1f6bcc2cee
                                                                                                    Remote Branch                    : quic/gfx-adreno.lnx.1.0.r116-rel
                                                                                                    Remote Branch                    : NONE
                                                                                                    Reconstruct Branch               : NOTHING
2023-09-23 17:17:20.801  8250-8594  AdrenoGLES-0            com.mecatronica.barbot               I  Build Config                     : S P 10.0.7 AArch64
2023-09-23 17:17:20.801  8250-8594  AdrenoGLES-0            com.mecatronica.barbot               I  Driver Path                      : /vendor/lib64/egl/libGLESv2_adreno.so
2023-09-23 17:17:20.813  8250-8594  AdrenoGLES-0            com.mecatronica.barbot               I  PFP: 0x016ee190, ME: 0x00000000
2023-09-23 17:17:21.019  8250-8594  LB                      com.mecatronica.barbot               E  fail to open file: No such file or directory
2023-09-23 17:17:21.021  8250-8594  OpenGLRenderer          com.mecatronica.barbot               I  Davey! duration=1547ms; Flags=1, IntendedVsync=42335033169415, Vsync=42336149836037, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=42336161943432, AnimationStart=42336162004370, PerformTraversalsStart=42336162065047, DrawStart=42336409293120, SyncQueued=42336445054213, SyncStart=42336445465515, IssueDrawCommandsStart=42336445624838, SwapBuffers=42336577074578, FrameCompleted=42336581385203, DequeueBufferDuration=272760, QueueBufferDuration=682187, GpuCompleted=1893829464, 
2023-09-23 17:17:21.027  8250-8250  Looper                  com.mecatronica.barbot               W  PerfMonitor doFrame : time=424ms vsyncFrame=0 latency=1127ms procState=2 historyMsgCount=10 (msgIndex=1 wall=1223ms seq=4 running=1128ms runnable=12ms late=2999ms h=android.app.ActivityThread$H w=159) (msgIndex=5 wall=1007ms seq=8 running=2ms runnable=1ms io=4ms late=3591ms h=android.app.ActivityThread$H w=127)
2023-09-23 17:17:21.154  8250-8250  Looper                  com.mecatronica.barbot               W  PerfMonitor doFrame : time=35ms vsyncFrame=0 latency=459ms procState=2 historyMsgCount=4 (msgIndex=1 wall=424ms seq=14 running=255ms runnable=1ms late=1127ms h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver) (msgIndex=4 wall=78ms seq=17 running=70ms runnable=2ms late=413ms h=android.view.ViewRootImpl$ViewRootHandler c=androidx.appcompat.app.AppCompatDelegateImpl$2)
2023-09-23 17:17:28.708  8250-8250  MiuiFrameworkFactory    com.mecatronica.barbot               V  get AllImpl object = android.common.MiuiFrameworkFactoryImpl@b038154
2023-09-23 17:17:28.726  8250-8250  MirrorManager           com.mecatronica.barbot               W  this model don't Support
2023-09-23 17:17:28.773  8250-8250  Timeline                com.mecatronica.barbot               I  Timeline: Activity_launch_request time:42344334
2023-09-23 17:17:28.996  8250-8250  DecorView[]             com.mecatronica.barbot               D  getWindowModeFromSystem  windowmode is 1
2023-09-23 17:17:28.997  8250-8250  DecorView               com.mecatronica.barbot               D  createDecorCaptionView windowingMode:1 mWindowMode 1 isFullscreen: true
2023-09-23 17:17:30.631  8250-8250  AndroidRuntime          com.mecatronica.barbot               D  Shutting down VM
2023-09-23 17:17:30.646  8250-8250  AndroidRuntime          com.mecatronica.barbot               E  FATAL EXCEPTION: main
                                                                                                    Process: com.mecatronica.barbot, PID: 8250
                                                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mecatronica.barbot/com.mecatronica.barbot.PedirTragoActivity}: java.lang.NullPointerException: cursor.getString(toColumnIndex) must not be null
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3550)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3710)
                                                                                                        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
                                                                                                        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
                                                                                                        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2146)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                        at android.os.Looper.loop(Looper.java:236)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8057)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
                                                                                                    Caused by: java.lang.NullPointerException: cursor.getString(toColumnIndex) must not be null
                                                                                                        at androidx.room.util.TableInfoKt.readForeignKeyFieldMappings(TableInfo.kt:536)
                                                                                                        at androidx.room.util.TableInfoKt.readForeignKeys(TableInfo.kt:488)
                                                                                                        at androidx.room.util.TableInfoKt.readTableInfo(TableInfo.kt:472)
                                                                                                        at androidx.room.util.TableInfo$Companion.read(TableInfo.kt:130)
                                                                                                        at androidx.room.util.TableInfo.read(Unknown Source:2)
                                                                                                        at com.mecatronica.barbot.database.AppDatabase_Impl$1.onValidateSchema(AppDatabase_Impl.java:136)
                                                                                                        at androidx.room.RoomOpenHelper.onCreate(RoomOpenHelper.kt:72)
                                                                                                        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onCreate(FrameworkSQLiteOpenHelper.kt:244)
                                                                                                        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:411)
                                                                                                        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:316)
                                                                                                        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableOrReadableDatabase(FrameworkSQLiteOpenHelper.kt:232)
                                                                                                        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.innerGetDatabase(FrameworkSQLiteOpenHelper.kt:190)
                                                                                                        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getSupportDatabase(FrameworkSQLiteOpenHelper.kt:151)
                                                                                                        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.kt:104)
                                                                                                        at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.kt:71)
                                                                                                        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.kt:638)
                                                                                                        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.kt:457)
                                                                                                        at com.mecatronica.barbot.database.daos.CocktailDAO_Impl.getAllCocktails(CocktailDAO_Impl.java:177)
                                                                                                        at com.mecatronica.barbot.PedirTragoActivity.onCreate(PedirTragoActivity.java:63)
                                                                                                        at android.app.Activity.performCreate(Activity.java:8157)
                                                                                                        at android.app.Activity.performCreate(Activity.java:8129)
                                                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3523)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3710) 
                                                                                                        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
                                                                                                        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
                                                                                                        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2146) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                        at android.os.Looper.loop(Looper.java:236) 
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8057) 
                                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656) 
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967) 
2023-09-23 17:17:30.716  8250-8250  Process                 com.mecatronica.barbot               I  Sending signal. PID: 8250 SIG: 9

sql dump form test.db:

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "ingredient_types"
(
    id   INTEGER not null
        constraint ingredient_types_pk
            primary key,
    name TEXT
);
INSERT INTO ingredient_types VALUES(1,'SHAKE');
INSERT INTO ingredient_types VALUES(2,'limón');
INSERT INTO ingredient_types VALUES(3,'ron');
INSERT INTO ingredient_types VALUES(4,'tonica');
INSERT INTO ingredient_types VALUES(5,'ginebra');
INSERT INTO ingredient_types VALUES(6,'campari');
INSERT INTO ingredient_types VALUES(7,'naranja');
INSERT INTO ingredient_types VALUES(8,'fernet');
INSERT INTO ingredient_types VALUES(9,'coca');
INSERT INTO ingredient_types VALUES(10,'durazno');
INSERT INTO ingredient_types VALUES(11,'granadina');
INSERT INTO ingredient_types VALUES(12,'vodka');
CREATE TABLE IF NOT EXISTS "bottle_ingredient"
(
    id           INTEGER not null
        constraint bottle_ingredient_pk
            primary key,
    bottlePos    INTEGER not null
        constraint bottle_ingredient_bottles_position_fk
            references bottles,
    ingredientId INTEGER not null
        constraint bottle_ingredient_ingredient_types_id_fk
            references ingredient_types
);
INSERT INTO bottle_ingredient VALUES(1,8,5);
INSERT INTO bottle_ingredient VALUES(2,9,6);
INSERT INTO bottle_ingredient VALUES(3,10,8);
INSERT INTO bottle_ingredient VALUES(4,11,3);
INSERT INTO bottle_ingredient VALUES(5,12,12);
INSERT INTO bottle_ingredient VALUES(7,0,2);
INSERT INTO bottle_ingredient VALUES(8,1,4);
INSERT INTO bottle_ingredient VALUES(9,2,7);
INSERT INTO bottle_ingredient VALUES(10,3,9);
INSERT INTO bottle_ingredient VALUES(11,4,10);
INSERT INTO bottle_ingredient VALUES(12,5,11);
INSERT INTO bottle_ingredient VALUES(13,16,1);
CREATE TABLE IF NOT EXISTS "bottles"
(
    position      INTEGER not null
        constraint bottles_pk
            primary key,
    name          TEXT,
    capacity      INTEGER not null,
    currentAmount INTEGER not null
);
INSERT INTO bottles VALUES(0,'limon',2000,2000);
INSERT INTO bottles VALUES(1,'tonica',2000,2000);
INSERT INTO bottles VALUES(2,'naranja',2000,2000);
INSERT INTO bottles VALUES(3,'coca',2000,2000);
INSERT INTO bottles VALUES(4,'durazno',2000,2000);
INSERT INTO bottles VALUES(5,'granadina',2000,2000);
INSERT INTO bottles VALUES(6,'Mezcla 7',1,1);
INSERT INTO bottles VALUES(7,'Mezcla 8',1,1);
INSERT INTO bottles VALUES(8,'ginebra',700,700);
INSERT INTO bottles VALUES(9,'campari',750,750);
INSERT INTO bottles VALUES(10,'fernet',750,750);
INSERT INTO bottles VALUES(11,'ron',750,750);
INSERT INTO bottles VALUES(12,'vodka',700,700);
INSERT INTO bottles VALUES(13,'Bottle 6',1,1);
INSERT INTO bottles VALUES(14,'Bottle 7',1,1);
INSERT INTO bottles VALUES(15,'Bottle 8',1,1);
INSERT INTO bottles VALUES(16,'Shakeo',1000,1000);
CREATE TABLE IF NOT EXISTS "cocktail_ingredients"
(
    id         INTEGER not null
        constraint cocktail_ingredients_pk
            primary key,
    typeId     INTEGER not null
        constraint cocktail_ingredients_ingredient_types_id_fk
            references ingredient_types,
    quantity   INTEGER not null,
    cocktailId INTEGER not null
        constraint cocktail_ingredients_cocktails_id_fk
            references cocktails
);
INSERT INTO cocktail_ingredients VALUES(1,6,60,1);
INSERT INTO cocktail_ingredients VALUES(2,7,136,1);
INSERT INTO cocktail_ingredients VALUES(3,9,146,2);
INSERT INTO cocktail_ingredients VALUES(4,8,50,2);
INSERT INTO cocktail_ingredients VALUES(5,5,60,3);
INSERT INTO cocktail_ingredients VALUES(6,4,136,3);
INSERT INTO cocktail_ingredients VALUES(7,3,50,4);
INSERT INTO cocktail_ingredients VALUES(8,9,120,4);
INSERT INTO cocktail_ingredients VALUES(9,2,10,4);
INSERT INTO cocktail_ingredients VALUES(10,12,40,5);
INSERT INTO cocktail_ingredients VALUES(11,10,20,5);
INSERT INTO cocktail_ingredients VALUES(12,7,40,5);
INSERT INTO cocktail_ingredients VALUES(13,1,30,5);
INSERT INTO cocktail_ingredients VALUES(14,11,40,5);
CREATE TABLE IF NOT EXISTS "cocktails"
(
    id        INTEGER not null
        constraint cocktails_pk
            primary key,
    name      TEXT,
    isOnStock INTEGER not null,
    hasIce    INTEGER not null,
    imgName   TEXT
);
INSERT INTO cocktails VALUES(1,'campari',1,1,'campari');
INSERT INTO cocktails VALUES(2,'fernet',1,1,'fernet');
INSERT INTO cocktails VALUES(3,'gin tonic',1,1,'gintonic');
INSERT INTO cocktails VALUES(4,'ron cola',1,1,'roncola');
INSERT INTO cocktails VALUES(5,'sex On  the beach',1,1,'sexOnTheBeach');
COMMIT;
android
  • 1 个回答
  • 51 Views
Martin Hope
Bob
Asked: 2023-09-22 07:46:42 +0800 CST

Visual Studio 2022、毛伊岛、Android 模拟器:无法更改内存量

  • 6

Visual Studio 2022、Maui 7.0、Android Emulator 32.1.1(一切都是最新的、最新的)

在开发 Maui 应用程序时,我需要该应用程序来播放视频,因此我安装了CommunityToolkit.Maui.MediaElement。

有什么问题?

它运行了大约两次,直到我开始收到此异常,无论使用什么虚拟 Android 设备:

错误:ADB0060:Mono.AndroidTools.InsufficientSpaceException:设备上没有足够的存储空间来存储包:/data/local/tmp/com.aaavisiologix.ems_mobile_maui-Signed.apk。释放一些空间并重试。

谷歌搜索仅引导我如何使用 Android Studio 释放空间,而不是使用 Visual Studio。有一个Microsoft 网站,但如果那里有关于如何解决我的问题的内容,我无法理解。

我尝试了什么?

我在 Visual Studio 中打开Android 设备管理器(工具 -> Android -> Android 设备管理器),很明显我的设备没有太多内存: 在此输入图像描述

那么也许我可以把这个数字调大一些?除非我不知道如何。“编辑特定设备”选项中的任何内容都没有什么帮助,除了第一个选项:disk,dataPartition.size,我尝试了其中的每个值。这并没有改变内存量(仍然是 1 GB)或设备的行为(仍然出现异常)。 在此输入图像描述

我总是确保我的测试程序未安装在计算机上,所以...难道不应该处理我使用SecureStorage或 SQLite 存储的任何数据吗?

在 Microsoft 文档中,它表示当您在 Android 设备管理器中右键单击设备时,选择“在资源管理器中显示”选项。唉,当我这样做时,我收到此错误:

C:\Users...\avd\devicename.avd 不可用。如果该位置在此电脑上,请确保设备或驱动器已连接或光盘已插入...

坦白说,我不知道如何继续前进,而且我的截止日期很快就到了。

android
  • 1 个回答
  • 27 Views
Martin Hope
Ammar Bakr
Asked: 2023-09-22 00:04:23 +0800 CST

XML 中 EditText 的自定义设计

  • 5

我想在 android xml 中得到这个设计,不完全是,但接近它。我对 Android 还很陌生,所以请在您赞赏的答案中更加具体。

自定义编辑文本

尝试使用自定义背景来更接近上面的设计,但无法将该标签保留在输入字段的顶部。

谢谢

android
  • 1 个回答
  • 17 Views
Martin Hope
Dan Gravell
Asked: 2023-09-21 22:39:12 +0800 CST

如何检测 Android Auto 是否正在启动,以便我可以设置初始 PlaybackState?

  • 5

根据Android 汽车应用质量指南 MA-1:

媒体应用程序不得在启动时自动播放,或者在用户未发起选择应用程序或应用程序媒体的操作的情况下。。

该指南建议阅读实现播放命令,它指的是设置初始 PlaybackState 的指令。这指出:

当 Android Automotive OS 或 Android Auto 连接到您的媒体浏览器服务时,您的应用不应自动开始播放音乐。

这似乎很清楚 - 启动 Android Auto 时,音乐不应自动播放。

但是,我看不到一种明显的方法可以检测Android Auto何时启动并连接到应用程序。

我的媒体应用程序具有当您在手机上使用它时自动播放的功能,并且它最后处于“播放”状态。所以我需要在 Android Auto 连接时禁用此功能。

当 Android Auto 连接时,MediaSessionCompat.Callback:onPlay将被调用。onPlay但是,如果用户单击“播放”图标,则会进行相同的回调。显然,如果用户单击“播放”图标,则应该播放音乐。

那么我如何知道用户是否手动按下了播放,或者 Android Auto 是否已连接到应用程序?

android
  • 1 个回答
  • 11 Views
Martin Hope
Eduard Unruh
Asked: 2023-09-19 23:16:52 +0800 CST

Android Kotlin - 计费 - 从应用内购买获取productId

  • 6

我正在尝试从购买中获取productId:

private fun queryPurchases(purchases: List<Purchase>){

    for (purchase in purchases) {

        Log.d("pikaboo", purchase.toString())

        when (purchase.purchaseState) {
            Purchase.PurchaseState.PURCHASED -> {

                val purchaseTime = (purchase.purchaseTime / 1000).toInt()

                when (purchase.productId) {
                    "no_ads_in_app_month" -> {

                    }
                    "no_ads_in_app_3_months" -> {

                    }
                }
            }
        }
    }
} 

这是日志:

Purchase. Json: {"orderId":"GPA.333.333.333","packageName":"de.bla.foo","productId":"no_ads_in_app_3_months","purchaseTime":1694810217354,"purchaseState":0,"purchaseToken":"xxxxxxxxxxxx","quantity":1,"acknowledged":true}

在是productId_purchase.productIdUnresolved reference

其他一切都像purchase.purchaseTime purchase.purchaseState purchase.packageName作品一样。

为什么不呢purchase.productId?这是一个错误吗?怎么解决这个问题呢?

android
  • 1 个回答
  • 16 Views
Martin Hope
vilnius19
Asked: 2023-09-17 21:40:46 +0800 CST

如何使recyclerviews在android中从右到左和从左到右水平滚动?

  • 5

我在一个片段中有 3 个 recyclerview,我希望每个 recyclerview 都位于另一个之下,然后当我滚动时,它们应该从左到左滚动。他们都不应该干扰其他回收者的观点。以下是我的片段的 xml 布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="@drawable/flash_tablebar"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        android:layout_alignParentTop="true">

        <ImageView
            android:id="@+id/back_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:src="@drawable/ic_arrow_back" />

        <RelativeLayout
            android:layout_marginLeft="20dp"
            android:id="@+id/relativeFlashcard"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_toRightOf="@id/back_icon">
            <TextView
                android:id="@+id/title_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:layout_marginStart="30dp"
                android:text="Flashcards"
                android:textSize="40sp"
                android:textColor="#FFF" />
            <TextView
                android:id="@+id/subtext_flash"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:layout_below="@id/title_text"
                android:layout_marginStart="30dp"
                android:text="Pick a set to practice"
                android:textSize="20sp"
                android:textColor="#FFF" />
        </RelativeLayout>
    </androidx.appcompat.widget.Toolbar>

    <LinearLayout
        android:layout_below="@id/toolbar"
        android:layout_width="match_parent"
        android:id="@+id/linear1"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewFlashcardsEasy"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:layout_below="@id/toolbar"
            android:layout_alignParentBottom="true"
            android:scrollbars="horizontal">
        </androidx.recyclerview.widget.RecyclerView>
    </LinearLayout>


    <LinearLayout
        android:layout_below="@id/linear1"
        android:id="@+id/linear2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewFlashcardsMedium"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:layout_below="@id/toolbar"
            android:layout_alignParentBottom="true"
            android:scrollbars="horizontal">
        </androidx.recyclerview.widget.RecyclerView>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/linear3"
        android:layout_below="@id/linear2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewFlashcardsHard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:layout_below="@id/toolbar"
            android:layout_alignParentBottom="true"
            android:scrollbars="horizontal">
        </androidx.recyclerview.widget.RecyclerView>
    </LinearLayout>
</RelativeLayout>

item_flashcards.xml是Recylerviews中声明元素的布局文件

<androidx.core.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <androidx.cardview.widget.CardView
            android:layout_width="270dp"
            android:layout_height="150dp"
            android:layout_margin="10dp"
            android:layout_gravity="center"
            android:id="@+id/cardFlashCards"
            app:cardCornerRadius="25dp"
            app:cardElevation="4dp"
            >
            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="200dp"
                android:gravity="center"
                android:layout_gravity="center"
                android:background="@drawable/flashcard_color"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/imageViewFlashcards"
                    android:layout_width="90dp"
                    android:layout_height="90dp"
                    android:layout_marginTop="20dp"
                    android:layout_gravity="center"
                    android:scaleType="fitXY"
                    android:background="@drawable/circular_flashcardview" />

                <TextView
                    android:id="@+id/textflashCardName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Text1"
                    android:textColor="@color/white"
                    android:layout_marginTop="10dp"
                    android:gravity="center"
                    android:textStyle="bold"
                    android:textSize="18sp" />
                <TextView
                    android:id="@+id/textflashCardLithuanian"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Text2"
                    android:textColor="@color/white"
                    android:layout_marginBottom="10dp"
                    android:gravity="center"
                    android:textStyle="bold"
                    android:textSize="18sp" />
            </LinearLayout>
        </androidx.cardview.widget.CardView>
    </FrameLayout>

</androidx.core.widget.NestedScrollView>

以下是片段的代码

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.cardview.widget.CardView
import androidx.navigation.Navigation
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.visuallithuanian.R
import com.example.visuallithuanian.adapter.FlashcardsAdapter
import com.example.visuallithuanian.data.FlashCardInfo
import com.example.visuallithuanian.ui.activities.FirstScreen
import com.google.android.material.bottomnavigation.BottomNavigationView
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class FlashCards : Fragment() {

    lateinit var bottomNav:BottomNavigationView

    @SuppressLint("MissingInflatedId")
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        // Inflate the layout for this fragment
        val view=inflater.inflate(R.layout.fragment_flash_cards, container, false)

        //Taking the bOTTOMNavigation view instance from Activity into Fragment
        bottomNav = (activity as? FirstScreen)?.findViewById(R.id.bottomNavigationView)!!
        bottomNav.visibility = View.VISIBLE

        val back_icon = view.findViewById<ImageView>(R.id.back_icon)
        val recyclerViewCardsEasy = view.findViewById<RecyclerView>(R.id.recyclerViewFlashcardsEasy)
        val recyclerViewCardsMedium = view.findViewById<RecyclerView>(R.id.recyclerViewFlashcardsMedium)
        val recyclerViewCardsHard = view.findViewById<RecyclerView>(R.id.recyclerViewFlashcardsHard)


        recyclerViewCardsHard.layoutManager = LinearLayoutManager(context)
        recyclerViewCardsMedium.layoutManager = LinearLayoutManager(context)
        recyclerViewCardsEasy.layoutManager = LinearLayoutManager(context)

        val navController = Navigation.findNavController(requireActivity(),
            R.id.nav_host_fragment
        )

        val flashCardList = generateFlashCards()
        val adapter = FlashcardsAdapter(flashCardList,navController)
        recyclerViewCardsHard.adapter = adapter

        val easyFlashCardsList = generateEasyFlashCards()
        val adapter1 = FlashcardsAdapter(easyFlashCardsList,navController)
        recyclerViewCardsEasy.adapter = adapter1

        val mediumFlashCardsList = generateMediumFlashCards()
        val adapter2 = FlashcardsAdapter(mediumFlashCardsList,navController)
        recyclerViewCardsMedium.adapter = adapter2



        // setting up listener
        back_icon.setOnClickListener {
            activity?.onBackPressed()
        }

        return view
    }

    private fun generateMediumFlashCards(): List<FlashCardInfo> {
        return listOf(
            FlashCardInfo(R.drawable.clothing,"Clothing",""),
            FlashCardInfo(R.drawable.village,"Towns and Villages",""),
            FlashCardInfo(R.drawable.nature,"Nature",""),

        )

    }

    private fun generateEasyFlashCards(): List<FlashCardInfo> {

        return listOf(
            FlashCardInfo(R.drawable.talking,"Daily Conversation",""),
            FlashCardInfo(R.drawable.food,"Food",""),
            FlashCardInfo(R.drawable.relatives,"Relatives",""),
        )

    }

    private fun generateFlashCards():List<FlashCardInfo> {
        return listOf(

            FlashCardInfo(R.drawable.doctorvisit,"Questions and Pronouns",""),
            FlashCardInfo(R.drawable.verbs,"Popular Verbs",""),
        )

    }


}

以下是适配器类的代码

package com.example.visuallithuanian.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import com.example.visuallithuanian.data.FlashCardInfo
import com.example.visuallithuanian.ui.activities.fragments.FlashCardsDirections


class FlashcardsAdapter(private val imageList: List<FlashCardInfo>
,  private val navController: NavController
) :RecyclerView.Adapter<FlashcardsAdapter.ViewHolder>(){

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val imageViewFlashcards = itemView.findViewById<ImageView>(com.example.visuallithuanian.R.id.imageViewFlashcards)
        val textViewFlashcards = itemView.findViewById<TextView>(com.example.visuallithuanian.R.id.textflashCardName)
        val textViewFlashcardsLithuanian = itemView.findViewById<TextView>(com.example.visuallithuanian.R.id.textflashCardLithuanian)

        val cardviewFlashcard = itemView.findViewById<CardView>(com.example.visuallithuanian.R.id.cardFlashCards)

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(com.example.visuallithuanian.R.layout.item_flashcards, parent, false)
        return ViewHolder(view)

    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val current_item = imageList[position]

        holder.imageViewFlashcards.setImageResource(current_item.imageId)
        holder.textViewFlashcards.text = current_item.name
        holder.textViewFlashcardsLithuanian.text = current_item.translation
        
        holder.cardviewFlashcard.setOnClickListener {
            val action = when(position){
                    1 ->FlashCardsDirections.actionFlashCardsToQuestionsFragment()

                else -> return@setOnClickListener
            }
            action.let {
                navController.navigate(it)
            }

        }


    }


    override fun getItemCount(): Int {
        return imageList.size
    }
}

我哪里错了?我什至使那些父线性布局方向水平

android
  • 1 个回答
  • 22 Views
Martin Hope
christopher
Asked: 2023-09-17 07:24:09 +0800 CST

apk 构建成功,但应用程序在启动时崩溃

  • 5

应用程序在开发中工作正常,并且在使用“eas build -p android --profile Preview”构建到 apk 时工作正常,应用程序构建成功,没有指定错误,但应用程序在生产中中断,甚至没有通过启动屏幕。

运行 npx expo-env-info 时:

expo-env-info 1.0.5 environment info:
System:
OS: Windows 10 10.0.19045
Binaries:
Node: 20.5.0 - ~\AppData\Roaming\npm\node.CMD
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 9.8.1 - ~\AppData\Roaming\npm\npm.CMD
IDEs:
Android Studio: AI-222.4459.24.2221.9971841
npmPackages:
@expo/webpack-config: ^19.0.0 => 19.0.0
expo: ^49.0.0 => 49.0.11
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.72.4 => 0.72.4
react-native-web: ~0.19.6 => 0.19.8
Expo Workflow: managed

运行 npx expo-doctor 时:

✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check npm/ yarn versions
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check that packages match versions required by installed Expo SDK
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check that native modules use compatible support package versions for installed Expo SDK

Didn't find any issues with the project!

错误输出 在 andriod 设备上启动时返回此错误:

在此输入图像描述

我尝试使用 andriod studio 进行调试,并进行构建,它构建成功,但仍然存在同样的问题。

我也尝试过更新和升级所有软件包同样的问题

这是我的 package.json 文件:

{
  "name": "yoris",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@aws-sdk/client-s3": "^3.341.0",
    "@expo-google-fonts/lato": "^0.2.2",
    "@expo-google-fonts/oswald": "^0.2.2",
    "@expo/vector-icons": "^13.0.0",
    "@expo/webpack-config": "^19.0.0",
    "@gorhom/bottom-sheet": "^4.4.5",
    "@material-tailwind/react": "^1.4.2",
    "@miblanchard/react-native-slider": "*",
    "@react-md/divider": "^5.1.3",
    "@react-native-async-storage/async-storage": "1.18.2",
    "@react-native-community/datetimepicker": "7.2.0",
    "@react-native-community/geolocation": "^3.0.6",
    "@react-native-community/netinfo": "9.3.10",
    "@react-native-community/progress-bar-android": "^1.0.5",
    "@react-native-community/slider": "4.4.2",
    "@react-native-community/viewpager": "5.0.11",
    "@react-native-picker/picker": "2.4.10",
    "@react-navigation/bottom-tabs": "^6.5.5",
    "@react-navigation/drawer": "^6.6.1",
    "@react-navigation/material-top-tabs": "^6.5.3",
    "@react-navigation/native": "^6.1.4",
    "@react-navigation/native-stack": "^6.9.10",
    "@react-navigation/stack": "^6.2.1",
    "@reduxjs/toolkit": "^1.9.3",
    "@rneui/base": "^4.0.0-rc.7",
    "@rneui/themed": "^4.0.0-rc.7",
    "@sanity/client": "^5.2.1",
    "@sanity/image-url": "^1.0.2",
    "@volkenomakers/react-native-country-picker": "^1.0.0",
    "aws-amplify": "^5.2.2",
    "aws-amplify-react-native": "^7.0.2",
    "aws-sdk": "^2.1381.0",
    "axios": "^1.3.2",
    "babel-plugin-inline-import": "^3.0.0",
    "camelize": "^1.0.0",
    "canvas": "^2.11.0",
    "countries-list": "^2.6.1",
    "country-list": "^2.3.0",
    "crypto-js": "^4.1.1",
    "date-fns": "^2.29.3",
    "dotenv": "^16.0.3",
    "expo": "^49.0.0",
    "expo-av": "~13.4.1",
    "expo-barcode-scanner": "~12.5.3",
    "expo-camera": "~13.4.4",
    "expo-checkbox": "~2.4.0",
    "expo-constants": "~14.4.2",
    "expo-contacts": "~12.2.0",
    "expo-dev-client": "~2.4.8",
    "expo-document-picker": "~11.5.4",
    "expo-image-manipulator": "~11.3.0",
    "expo-image-picker": "~14.3.2",
    "expo-linear-gradient": "~12.3.0",
    "expo-location": "~16.1.0",
    "expo-media-library": "~15.4.1",
    "expo-permissions": "~14.2.1",
    "expo-radio-button": "^1.0.8",
    "expo-splash-screen": "~0.20.5",
    "expo-status-bar": "~1.6.0",
    "firebase": "^9.17.2",
    "formik": "^2.2.9",
    "install": "^0.13.0",
    "jsbarcode": "^3.11.5",
    "lodash": "^4.17.21",
    "lottie-react-native": "5.1.6",
    "moment": "^2.29.2",
    "native-base": "^3.4.25",
    "nativewind": "^2.0.11",
    "pod-install": "^0.1.38",
    "qrcode-generator": "^1.4.4",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-google-autocomplete": "^2.7.3",
    "react-google-places-autocomplete": "^4.0.1",
    "react-hook-form": "^7.33.1",
    "react-md": "^5.1.4",
    "react-native": "0.72.4",
    "react-native-actions-sheet": "^0.8.21",
    "react-native-animatable": "^1.3.3",
    "react-native-animated-splash-screen": "^2.0.5",
    "react-native-art": "^1.0.0",
    "react-native-aws3": "^0.0.9",
    "react-native-ble-manager": "^8.4.3",
    "react-native-ble-plx": "^2.0.3",
    "react-native-calendar": "^0.13.1",
    "react-native-calendars": "^1.1293.0",
    "react-native-canvas": "^0.1.38",
    "react-native-chart-kit": "^6.12.0",
    "react-native-country-codes-picker": "^2.2.2",
    "react-native-country-picker-modal": "^2.0.0",
    "react-native-currency-input": "^1.0.1",
    "react-native-date-picker": "^4.2.2",
    "react-native-datepicker": "^1.7.2",
    "react-native-dotenv": "^3.4.7",
    "react-native-dropdown-picker": "^5.4.4",
    "react-native-dropdown-select-list": "^2.0.4",
    "react-native-eject": "^0.1.2",
    "react-native-fit-image": "^1.5.5",
    "react-native-gesture-handler": "~2.12.0",
    "react-native-google-autocomplete": "^0.2.0",
    "react-native-google-places-autocomplete": "^2.5.1",
    "react-native-heroicons": "^2.2.0",
    "react-native-image-header-scroll-view": "^1.0.0",
    "react-native-image-picker": "^5.0.0",
    "react-native-maps": "1.7.1",
    "react-native-maps-directions": "^1.8.0",
    "react-native-modal-datetime-picker": "^13.1.2",
    "react-native-modal-dropdown": "^1.0.2",
    "react-native-pager-view": "6.2.0",
    "react-native-paper": "^5.2.0",
    "react-native-permissions": "^3.6.1",
    "react-native-phone-code-select": "^1.1.0",
    "react-native-phone-number-input": "^2.1.0",
    "react-native-progress": "^5.0.0",
    "react-native-qrcode-scanner": "^1.5.5",
    "react-native-qrcode-svg": "^6.2.0",
    "react-native-reanimated": "~3.3.0",
    "react-native-responsive-linechart": "^5.7.1",
    "react-native-safe-area-context": "4.6.3",
    "react-native-screens": "~3.22.0",
    "react-native-select-dropdown": "^3.2.1",
    "react-native-sliding-up-down-panels": "^1.0.0",
    "react-native-step-indicator": "^1.0.3",
    "react-native-svg": "13.9.0",
    "react-native-swipe-up-down": "^1.2.0",
    "react-native-swiper": "^1.6.0",
    "react-native-switch": "^1.5.1",
    "react-native-tab-view": "^3.3.4",
    "react-native-uuid": "^2.0.1",
    "react-native-vector-icons": "^9.2.0",
    "react-native-video": "^5.2.1",
    "react-native-view-shot": "3.7.0",
    "react-native-web": "~0.19.6",
    "react-native-webview": "13.2.2",
    "react-redux": "^8.0.5",
    "react-s3": "^1.3.1",
    "redux": "^4.2.0",
    "redux-thunk": "^2.4.1",
    "rn-range-slider": "^2.2.2",
    "rn-sliding-up-panel": "^2.4.6",
    "socket.io-client": "^4.5.4",
    "styled-components": "^5.3.6",
    "tailwind-react-native-classnames": "^1.5.1",
    "twrnc": "^3.6.0",
    "typescript": "^5.1.3",
    "uid": "^2.0.1",
    "watchman": "^1.0.0",
    "webpack-dev-server": "^4.11.1",
    "yup": "^1.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

android
  • 2 个回答
  • 34 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve