Autore Topic: Impossibile creare Database  (Letto 426 volte)

Offline E.Musso

  • Utente junior
  • **
  • Post: 80
  • Respect: +16
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy GT-S5660
  • Market Developer Name:
    Emiliano Musso
  • Sistema operativo:
    Windows / Ubuntu
Re:Impossibile creare Database
« Risposta #15 il: 16 Gennaio 2012, 14:25:21 CET »
0
Ciao yoshi,
credo avresti dovuto aprire un nuovo topic per il tuo problema, ad ogni modo provo a risponderti: il problema risiede nella parte finale indicata dal tuo logcat, ossia:

Codice (Java): [Seleziona]
01-16 13:00:25.068: E/AndroidRuntime(21880): Caused by: java.lang.NullPointerException
01-16 13:00:25.068: E/AndroidRuntime(21880):         at it.lap2.project.Aprof.Database.MyDatabase.createTables(MyDatabase.java:46)
01-16 13:00:25.068: E/AndroidRuntime(21880):         at it.lap2.project.Aprof.AprofActivity.onCreate(AprofActivity.java:73)

L'errore è nella classe MyDatabase, alla riga 46, richiamata dalla riga 73 della AprofActivity.
Prova a dare un'occhiata in quei due punti, eventualmente puoi postare le due classi per un controllo.
COFFEE.EXE Missing - Insert Cup and Press Any Key
--
È stata trovata una soluzione al tuo problema?Evidenzia il post più utile premendo . È un ottimo modo per ringraziare chi ti ha aiutato

Offline yoshi

  • Nuovo arrivato
  • *
  • Post: 30
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    LG Optimu Black (P970)
  • Sistema operativo:
    Mac OS X 10.7
Re:Impossibile creare Database
« Risposta #16 il: 16 Gennaio 2012, 14:27:52 CET »
0
intanto grazie mille per la risposta.... ecco la classe MyDatabase

Codice: [Seleziona]
package it.lap2.project.Aprof.Database;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

public class MyDatabase {
       
        //gestione database
                private static SQLiteDatabase db;
                //utilizzato per le insert nel db
                private static ContentValues cValues;
               
                //identificatore delle preferenze dell'applicazione
                private SharedPreferences pref;
                private SharedPreferences.Editor editor;
                public static final String MY_PREFERENCES ="AprofPreferences";
                //intero che viene utilizzato per differenziare i nomi delle variabili che rappresentano i db creati all'interno delle preferenze
                public static int num_db =0;
                //nome del db di default
                private static String db_default="";
               
                public static void setNameDb(String dbName){
                        db_default = dbName;
                }
               
                public static String getNameDb(){
                        return db_default;
                }
               
                //definisco le tabelle che devono essere create ogni volta che creo un nuovo database
                public static void createTables(){               
                        db.openOrCreateDatabase("data/data/it.lap2.project.Aprof/databases/"+db_default, null);//.openOrCreateDatabase(getNameDb(), null);
                        try{
                                //tabella STUDENTI
                                db.execSQL("create table if not exists Studenti" +
                                                "(_id nvarchar(4) not null, nome nvarchar(15), " +
                                                "cognome nvarchar(15), classe nvarchar(5), indirizzo nvarchar(100), " +
                                                "telefono nvarchar(30), email nvarchar(50),  varie nvarchar(100), " +
                                                "foto nvarchar(100), primary key(_id));");
                               
                                //tabella ASSENZE
                                db.execSQL("create table if not exists Assenze " +
                                                "(alunno nvarchar(5) not null, data date not null, " +
                                                "lezione nvarchar(5) not null, numOre smallint);");
                                //        "primary key(idAlunno, data, idLezione));");
                               
                                //tabella CLASSI
                                db.execSQL("create table if not exists Classi " +
                                                "(anno numeric, sezione nchar(5), " +
                                                "corso nvarchar(15), idClasse nvarchar(5) not null, " +
                                                "primary key(idClasse));");
                               
                                //tabella LEZIONI
                                db.execSQL("create table if not exists Lezioni " +
                                                "(idLezione nvarchar(5) not null, classe nvarchar(5), materia nvarchar(5), " +
                                                "descrizione nvarchar(50), data date, " +
                                                "primary key(idLezione));");
                               
                                //tabella MATERIE
                                db.execSQL("create table if not exists Materie " +
                                                "(idMateria nvarchar(5) not null, nome nvarchar(20), " +
                                                "primary key(idMateria));");
                               
                                //tabella ORARIO
                                db.execSQL("create table if not exists Orario" +
                                                "(giornoTextViewSett nvarchar(10) not null, numOra nvarchar(2) not null, " +
                                                "tot int, classe nvarchar(5), materia nvarchar(5), " +
                                                "primary key(giornoTextViewSett, numOra));");
                               
                                //tabella PERIODI
                                db.execSQL("create table if not exists Periodi " +
                                                "(periodo nvarchar(20), idPeriodo nvarchar(5) not null, " +
                                                "scadenza nvarchar(10), inizio nvarchar(10), " +
                                                "primary key(idPeriodo));");
                               
                                //tabella SETTING ORARIO
                                db.execSQL("create table if not exists SettingOrario" +
                                                "(numOra varchar(2) not null, o_inizio int, " +
                                                "m_inizio int, o_fine int, m_fine int, " +
                                                "primary key(numOra));");
                               
                                //tabella VERIFICHE
                                db.execSQL("create table if not exists Verifiche " +
                                                "(data date not null, voto float, alunno nvarchar(5) not null, " +
                                                "materia nvarchar(5) not null, tipo nvarchar(15) not null, argomento nvarchar(50), periodo nvarchar(5) not null, " +
                                                "primary key(data, alunno, materia, tipo));");
                               
                                //tabella ATTIVITA
                                db.execSQL("create table if not exists Attività " +
                                                "(idAttività int not null, descrizione nvarchar(100), " +
                                                "data date, classe nvarchar(5), materia nvarchar(5), " +
                                                "primary key(idAttività));");
                        }
                        catch(SQLiteException e){
                                e.printStackTrace();
                        }
                        db.close();
                }
}

Offline E.Musso

  • Utente junior
  • **
  • Post: 80
  • Respect: +16
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy GT-S5660
  • Market Developer Name:
    Emiliano Musso
  • Sistema operativo:
    Windows / Ubuntu
Re:Impossibile creare Database
« Risposta #17 il: 16 Gennaio 2012, 14:33:08 CET »
0
La query che da problemi dovrebbe essere questa:

Codice (Java): [Seleziona]
//tabella ORARIO
                                db.execSQL("create table if not exists Orario" +
                                                "(giornoTextViewSett nvarchar(10) not null, numOra nvarchar(2) not null, " +
                                                "tot int, classe nvarchar(5), materia nvarchar(5), " +
                                                "primary key(giornoTextViewSett, numOra));");
COFFEE.EXE Missing - Insert Cup and Press Any Key
--
È stata trovata una soluzione al tuo problema?Evidenzia il post più utile premendo . È un ottimo modo per ringraziare chi ti ha aiutato

Offline yoshi

  • Nuovo arrivato
  • *
  • Post: 30
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    LG Optimu Black (P970)
  • Sistema operativo:
    Mac OS X 10.7
Re:Impossibile creare Database
« Risposta #18 il: 16 Gennaio 2012, 14:41:07 CET »
0
modificato ma ancora non va bene
Codice: [Seleziona]
01-16 14:40:33.498: D/dalvikvm(23516): GC_EXTERNAL_ALLOC freed 50K, 53% free 2567K/5379K, external 2098K/2137K, paused 71ms
01-16 14:40:33.609: D/AndroidRuntime(23516): Shutting down VM
01-16 14:40:33.609: W/dalvikvm(23516): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-16 14:40:33.629: E/AndroidRuntime(23516): FATAL EXCEPTION: main
01-16 14:40:33.629: E/AndroidRuntime(23516): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.lap2.project.Aprof/it.lap2.project.Aprof.AprofActivity}: java.lang.NullPointerException
01-16 14:40:33.629: E/AndroidRuntime(23516):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at android.os.Looper.loop(Looper.java:123)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at android.app.ActivityThread.main(ActivityThread.java:3683)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at java.lang.reflect.Method.invokeNative(Native Method)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at java.lang.reflect.Method.invoke(Method.java:507)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at dalvik.system.NativeStart.main(Native Method)
01-16 14:40:33.629: E/AndroidRuntime(23516): Caused by: java.lang.NullPointerException
01-16 14:40:33.629: E/AndroidRuntime(23516):         at it.lap2.project.Aprof.Database.MyDatabase.createTables(MyDatabase.java:47)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at it.lap2.project.Aprof.AprofActivity.onCreate(AprofActivity.java:73)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-16 14:40:33.629: E/AndroidRuntime(23516):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-16 14:40:33.629: E/AndroidRuntime(23516):         ... 11 more