Skip to main content
se añadieron 1932 caracteres en el cuerpo
Origen Enlace
scorpions
  • 455
  • 2
  • 10
  • 25

Acabo de ver mi problema:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.practicadesarrollo, PID: 22083
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.practicadesarrollo/com.example.practicadesarrollo.Database}; have you declared this activity in your AndroidManifest.xml?
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2065)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727)
    at android.app.Activity.startActivityForResult(Activity.java:5320)
    at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
    at android.app.Activity.startActivityForResult(Activity.java:5278)
    at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
    at android.app.Activity.startActivity(Activity.java:5664)
    at android.app.Activity.startActivity(Activity.java:5617)
    at com.example.practicadesarrollo.Activity2$onCreate$1.onClick(Activity2.kt:34)
    at android.view.View.performClick(View.java:7448)
    at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)
    at android.view.View.performClickInternal(View.java:7425)
    at android.view.View.access$3600(View.java:810)
    at android.view.View$PerformClick.run(View.java:28305)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Acabo de ver mi problema:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.practicadesarrollo, PID: 22083
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.practicadesarrollo/com.example.practicadesarrollo.Database}; have you declared this activity in your AndroidManifest.xml?
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2065)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727)
    at android.app.Activity.startActivityForResult(Activity.java:5320)
    at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
    at android.app.Activity.startActivityForResult(Activity.java:5278)
    at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
    at android.app.Activity.startActivity(Activity.java:5664)
    at android.app.Activity.startActivity(Activity.java:5617)
    at com.example.practicadesarrollo.Activity2$onCreate$1.onClick(Activity2.kt:34)
    at android.view.View.performClick(View.java:7448)
    at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)
    at android.view.View.performClickInternal(View.java:7425)
    at android.view.View.access$3600(View.java:810)
    at android.view.View$PerformClick.run(View.java:28305)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
se añadieron 4493 caracteres en el cuerpo
Origen Enlace
scorpions
  • 455
  • 2
  • 10
  • 25
    package com.example.practicadesarrollo

import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.widget.Toast

val DATABASE_NAME = "pacDesarrollo"
val NOMBRE_TABLA = "usuarios"
val COL_NOMBRE = "nombre"
val COL_APELLIDOS = "apellidos"
val COL_ID = "id"

class Database(var context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null,1){

    // función para crear la base de datos
    override fun onCreate(db: SQLiteDatabase?) {
        val createTable = "CREATE TABLE " + NOMBRE_TABLA + " (" +
                COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                COL_NOMBRE + " VARCHAR(256), " +
                COL_APELLIDOS + " VARCHAR(256)";VARCHAR;";
     
    if (db != null) {
            db.execSQL(createTable)

            if( createTable == null)
                Toast.makeText(context, "Ocurrió un error!", Toast.LENGTH_SHORT).show()
            else
                Toast.makeText(context, "Dato Insertado!", Toast.LENGTH_SHORT).show()
        }
    }

    // esta función se deja así
    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        TODO("Not yet implemented")
    }


    // función para insertar en la BD
    fun insertData(user : User) {
        val db = this.writableDatabase
        var cv = ContentValues()
        cv.put(COL_NOMBRE, user.nombre)
        cv.put(COL_APELLIDOS, user.apellidos)

        //insertamos
        var result = db.insert(NOMBRE_TABLA, null, cv)

        // comprobamos que se ha insertado bien

        if( result == -1.toLong())
            Toast.makeText(context, "Ocurrió un error!", Toast.LENGTH_SHORT).show()
        else
            Toast.makeText(context, "Dato Insertado!", Toast.LENGTH_SHORT).show()
    }
}

Como digo, ha hacer click en este botón, se me cierra la aplicación volviendome al activity1 que es mi menu principal, no se si lo ha hecho bien, si no... No me aparece el Toast

Actualización (Salida LogCat)

2020-11-19 10:25:12.761 21359-21359/? I/cticadesarroll: Not late-enabling -
Xcheck:jni (already on)
2020-11-19 10:25:12.782 21359-21359/? I/cticadesarroll: Unquickening 12 vdex files!
2020-11-19 10:25:12.784 21359-21359/? W/cticadesarroll: Unexpected CPU variant for X86 using defaults: x86
2020-11-19 10:25:13.151 21359-21359/com.example.practicadesarrollo D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2020-11-19 10:25:13.152 21359-21359/com.example.practicadesarrollo D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2020-11-19 10:25:13.178 21359-21381/com.example.practicadesarrollo D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2020-11-19 10:25:13.182 21359-21381/com.example.practicadesarrollo D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2020-11-19 10:25:13.190 21359-21381/com.example.practicadesarrollo D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2020-11-19 10:25:13.422 21359-21359/com.example.practicadesarrollo W/cticadesarroll: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2020-11-19 10:25:13.423 21359-21359/com.example.practicadesarrollo W/cticadesarroll: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2020-11-19 10:25:13.647 21359-21379/com.example.practicadesarrollo D/HostConnection: HostConnection::get() New Host Connection established 0xeb2f6c60, tid 21379
2020-11-19 10:25:13.656 21359-21379/com.example.practicadesarrollo D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
2020-11-19 10:25:13.659 21359-21379/com.example.practicadesarrollo W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2020-11-19 10:25:13.666 21359-21379/com.example.practicadesarrollo D/EGL_emulation: eglCreateContext: 0xeb2f6090: maj 3 min 0 rcv 3
2020-11-19 10:25:13.685 21359-21379/com.example.practicadesarrollo D/EGL_emulation: eglMakeCurrent: 0xeb2f6090: ver 3 0 (tinfo 0xeb63ca30) (first time)
2020-11-19 10:25:13.709 21359-21379/com.example.practicadesarrollo I/Gralloc4: mapper 4.x is not supported
2020-11-19 10:25:13.709 21359-21379/com.example.practicadesarrollo D/HostConnection: createUnique: call
2020-11-19 10:25:13.710 21359-21379/com.example.practicadesarrollo D/HostConnection: HostConnection::get() New Host Connection established 0xeb2f6790, tid 21379
2020-11-19 10:25:13.710 21359-21379/com.example.practicadesarrollo D/goldfish-address-space: allocate: Ask for block of size 0x100
2020-11-19 10:25:13.730 21359-21379/com.example.practicadesarrollo D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fdd78000 size 0x2000
2020-11-19 10:25:13.736 21359-21379/com.example.practicadesarrollo D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
    package com.example.practicadesarrollo

import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.widget.Toast

val DATABASE_NAME = "pacDesarrollo"
val NOMBRE_TABLA = "usuarios"
val COL_NOMBRE = "nombre"
val COL_APELLIDOS = "apellidos"
val COL_ID = "id"

class Database(var context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null,1){

    // función para crear la base de datos
    override fun onCreate(db: SQLiteDatabase?) {
        val createTable = "CREATE TABLE " + NOMBRE_TABLA + " (" +
                COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                COL_NOMBRE + " VARCHAR(256), " +
                COL_APELLIDOS + " VARCHAR(256)";
        if (db != null) {
            db.execSQL(createTable)

            if( createTable == null)
                Toast.makeText(context, "Ocurrió un error!", Toast.LENGTH_SHORT).show()
            else
                Toast.makeText(context, "Dato Insertado!", Toast.LENGTH_SHORT).show()
        }
    }

    // esta función se deja así
    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        TODO("Not yet implemented")
    }


    // función para insertar en la BD
    fun insertData(user : User) {
        val db = this.writableDatabase
        var cv = ContentValues()
        cv.put(COL_NOMBRE, user.nombre)
        cv.put(COL_APELLIDOS, user.apellidos)

        //insertamos
        var result = db.insert(NOMBRE_TABLA, null, cv)

        // comprobamos que se ha insertado bien

        if( result == -1.toLong())
            Toast.makeText(context, "Ocurrió un error!", Toast.LENGTH_SHORT).show()
        else
            Toast.makeText(context, "Dato Insertado!", Toast.LENGTH_SHORT).show()
    }
}

Como digo, ha hacer click en este botón, se me cierra la aplicación volviendome al activity1 que es mi menu principal, no se si lo ha hecho bien, si no... No me aparece el Toast

    package com.example.practicadesarrollo

import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.widget.Toast

val DATABASE_NAME = "pacDesarrollo"
val NOMBRE_TABLA = "usuarios"
val COL_NOMBRE = "nombre"
val COL_APELLIDOS = "apellidos"
val COL_ID = "id"

class Database(var context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null,1){

    // función para crear la base de datos
override fun onCreate(db: SQLiteDatabase?) {
    val createTable = "CREATE TABLE " + NOMBRE_TABLA + " (" +
            COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            COL_NOMBRE + " VARCHAR, " +
            COL_APELLIDOS + " VARCHAR;";
 
    if (db != null) {
        db.execSQL(createTable)

        if( createTable == null)
            Toast.makeText(context, "Ocurrió un error!", Toast.LENGTH_SHORT).show()
        else
            Toast.makeText(context, "Dato Insertado!", Toast.LENGTH_SHORT).show()
    }
}

    // esta función se deja así
    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        TODO("Not yet implemented")
    }


    // función para insertar en la BD
    fun insertData(user : User) {
        val db = this.writableDatabase
        var cv = ContentValues()
        cv.put(COL_NOMBRE, user.nombre)
        cv.put(COL_APELLIDOS, user.apellidos)

        //insertamos
        var result = db.insert(NOMBRE_TABLA, null, cv)

        // comprobamos que se ha insertado bien

        if( result == -1.toLong())
            Toast.makeText(context, "Ocurrió un error!", Toast.LENGTH_SHORT).show()
        else
            Toast.makeText(context, "Dato Insertado!", Toast.LENGTH_SHORT).show()
    }
}

Como digo, ha hacer click en este botón, se me cierra la aplicación volviendome al activity1 que es mi menu principal, no se si lo ha hecho bien, si no... No me aparece el Toast

Actualización (Salida LogCat)

2020-11-19 10:25:12.761 21359-21359/? I/cticadesarroll: Not late-enabling -
Xcheck:jni (already on)
2020-11-19 10:25:12.782 21359-21359/? I/cticadesarroll: Unquickening 12 vdex files!
2020-11-19 10:25:12.784 21359-21359/? W/cticadesarroll: Unexpected CPU variant for X86 using defaults: x86
2020-11-19 10:25:13.151 21359-21359/com.example.practicadesarrollo D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2020-11-19 10:25:13.152 21359-21359/com.example.practicadesarrollo D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2020-11-19 10:25:13.178 21359-21381/com.example.practicadesarrollo D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2020-11-19 10:25:13.182 21359-21381/com.example.practicadesarrollo D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2020-11-19 10:25:13.190 21359-21381/com.example.practicadesarrollo D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2020-11-19 10:25:13.422 21359-21359/com.example.practicadesarrollo W/cticadesarroll: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2020-11-19 10:25:13.423 21359-21359/com.example.practicadesarrollo W/cticadesarroll: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2020-11-19 10:25:13.647 21359-21379/com.example.practicadesarrollo D/HostConnection: HostConnection::get() New Host Connection established 0xeb2f6c60, tid 21379
2020-11-19 10:25:13.656 21359-21379/com.example.practicadesarrollo D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
2020-11-19 10:25:13.659 21359-21379/com.example.practicadesarrollo W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2020-11-19 10:25:13.666 21359-21379/com.example.practicadesarrollo D/EGL_emulation: eglCreateContext: 0xeb2f6090: maj 3 min 0 rcv 3
2020-11-19 10:25:13.685 21359-21379/com.example.practicadesarrollo D/EGL_emulation: eglMakeCurrent: 0xeb2f6090: ver 3 0 (tinfo 0xeb63ca30) (first time)
2020-11-19 10:25:13.709 21359-21379/com.example.practicadesarrollo I/Gralloc4: mapper 4.x is not supported
2020-11-19 10:25:13.709 21359-21379/com.example.practicadesarrollo D/HostConnection: createUnique: call
2020-11-19 10:25:13.710 21359-21379/com.example.practicadesarrollo D/HostConnection: HostConnection::get() New Host Connection established 0xeb2f6790, tid 21379
2020-11-19 10:25:13.710 21359-21379/com.example.practicadesarrollo D/goldfish-address-space: allocate: Ask for block of size 0x100
2020-11-19 10:25:13.730 21359-21379/com.example.practicadesarrollo D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fdd78000 size 0x2000
2020-11-19 10:25:13.736 21359-21379/com.example.practicadesarrollo D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
etiquetas editadas
Enlace
scorpions
  • 455
  • 2
  • 10
  • 25
Origen Enlace
scorpions
  • 455
  • 2
  • 10
  • 25
Loading