dimanche 7 février 2016

Code Help at understand why the application keeps crashing

So I am a starting Programmer and I am slowly learning everything,

My App is crashing because of populateListFromDB();

And another problem I have is that when I debug the Android Studio says

"NullPointerException: null"

If I delete this, The App is launching so.. Thanks for help guys! Here is my MainActivity's onCreate and the function:

public class MainActivity extends Activity {


    DB myDB;
    EditText User, Pass, Acc;
    Button btnAdd;

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

        User = (EditText) findViewById(R.id.EnterUser);
        Pass = (EditText) findViewById(R.id.EnterPass);
        Acc = (EditText) findViewById(R.id.EnterAcc);
        btnAdd = (Button) findViewById(R.id.btnAdd);

        ///Add button
        btnAdd.setOnClickListener(
                new View.OnClickListener() {
                    public void onClick(View view) {
                        if ((CheckErrors())) {
                            myDB.insertRow(User.getText().toString(), Pass.getText().toString(), Acc.getText().toString());
                            Toast.makeText(MainActivity.this, "Account Added!", Toast.LENGTH_SHORT).show();
                            populateListFromDB();
                        } else
                            Toast.makeText(MainActivity.this, "Please Fill All!", Toast.LENGTH_SHORT).show();
                        populateListFromDB();

                    }
                });
    }

and the Function:

   private void populateListFromDB() {
        Cursor cursor = myDB.getAllRows();
        startManagingCursor(cursor);

        // Setup mapping from cursor to view fields:
        String[] fromFieldNames = new String[]
                {DB.KEY_USER, DB.KEY_PASS, DB.KEY_ACC};
        int[] toViewIDs = new int[]
                {R.id.user_insert, R.id.pass_insert, R.id.acc_insert};

        // Create adapter to may columns of the DB onto elemesnt in the UI.
        SimpleCursorAdapter myCursorAdapter =
                new SimpleCursorAdapter(
                        this,       // Context
                        R.layout.listlayout,    // Row layout template
                        cursor,                 // cursor (set of DB records to map)
                        fromFieldNames,         // DB Column names
                        toViewIDs               // View IDs to put information in
                );

        // Set the adapter for the list view
        ListView myList = (ListView) findViewById(R.id.ListViewFromDB);
        myList.setAdapter(myCursorAdapter);
    }

LogCat:

? E/ActivityManager: checkUser: useridlist=null, currentuser=0
? E/ActivityManager: checkUser: useridlist=null, currentuser=0
? E/Zygote: MountEmulatedStorage()
? E/Zygote: v2
? I/libpersona: KNOX_SDCARD checking this for 10034
? I/libpersona: KNOX_SDCARD not a persona
? I/ActivityManager: Start proc com.sec.spp.push:RemoteNotiProcess for broadcast http://ift.tt/1Q3yBKq: pid=7735 uid=10034 gids={50034, 9997, 3003, 1028, 1015, 1023} abi=armeabi-v7a
? I/SELinux: Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-G900F_5.0_0011
? E/SELinux: [DEBUG] get_category: variable seinfo: samsung sensitivity: NULL, cateogry: NULL
? I/SecureStorage: [INFO]: SPID(0x00002228)Credentials: uid 10003, gid 10003, pid 12722
? I/SecureStorage: [INFO]: SPID(0x00002228)Received function mask & code: 0x00000106
? D/TimaKeyStoreProvider: TimaSignature is unavailable
? D/ActivityThread: Added TimaKeyStore provider
? D/ResourcesManager: creating new AssetManager and set to /system/priv-app/SPPPushClient_Prod/SPPPushClient_Prod.apk
? W/SecureStorage: [WARN]: SPID(0x00000000)internal error
? W/SecureStorage: [WARN]: SPID(0x00000000)Can`t load ss_id for app com.samsung.android.providers.context
? W/SecureStorage: [WARN]: SPID(0x00002228)Wrong ready flag
? I/SecureStorage: [INFO]: SPID(0x00002228)Secure Storage Daemon finished processing with result: -3
? W/SecureStorage: [WARN]: SPID(0x00000000)Could not connect to Secure Storage Daemon
? I/SecureStorage: [INFO]: SPID(0x00002228)PID: 12722, TID: 12722
? W/SecureStorage: [WARN]: SPID(0x00002229)Processing of client command finished with error
? D/ResourcesManager: creating new AssetManager and set to /data/app/com.erelbiran.accountsaver-1/base.apk
? E/SPPClientService: ============PushLog. commonIsShipBuild. stop!
? E/SPPClientService: [PushClientApplication] Push log off : This is Ship build version
? D/SPPClientService: PushLog.txt file is not deleted.
? D/SPPClientService: PushLog.txt file is not deleted.
? D/SPPClientService: ============PushLog. stop!
? E/SMD: DCD ON
? E/ActivityManager: checkUser: useridlist=null, currentuser=0
? E/ActivityManager: checkUser: useridlist=null, currentuser=0
? E/ActivityManager: checkUser: useridlist=null, currentuser=0
? E/ActivityManager: checkUser: useridlist=null, currentuser=0
? E/Zygote: MountEmulatedStorage()
? E/Zygote: v2

Aucun commentaire:

Enregistrer un commentaire