0

Sudden out of nowhere the error below comes up whenever I start my activity. this is the complete logcat: http://pastebin.com/Qdz2BCp4

This is my MainActivity in which the error occurs:

public class MainActivity extends FragmentActivity {
private DataSource _dataSource;

private Spinner _spinner1, _spinner2;

private int _category;

private double _inch;

private List<String> _categoryList = new ArrayList<String>();

private List<String> _sizes = new ArrayList<String>();
private ArrayAdapter<String> _dataAdapter;

private ArrayAdapter<String> _sizesAdapter;

private String _size;

public static User _user = null;

private boolean _inAccountDetails = false;

public final static String EXTRA_MESSAGE = "com.OBO.Bandenanalyse.Soort";

public final static String EXTRA_MESSAGE2 = "com.OBO.Bandenanalyse.Inch";

public final static String EXTRA_MESSAGE3 = "com.OBO.Bandenanalyse.Maat";

public final static String EXTRA_MESSAGE5 = "com.OBO.Bandenanalyse.User";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(savedInstanceState != null && savedInstanceState.getBoolean("Layout")){
        setContentView(R.layout.registration_edit);
        initializeAccountDetails((User) savedInstanceState.getSerializable(EXTRA_MESSAGE5));
        _inAccountDetails = true;
    }else{
        String sql = "SELECT * FROM User";
        createFile();
        if(_dataSource.DbHelper._database != null){
            _dataSource.open();
            Cursor cursor = _dataSource.DbHelper._database.rawQuery(sql,null);                          
            cursor.moveToFirst();
            _dataSource.close();
            if(cursor.getCount() == 0){
                setContentView(R.layout.registration);
                createFile();
            } else {
                setContentView(R.layout.activity_main);
                addListenerOnSpinnerItemSelection();
                addListenerOnSpinner2ItemSelection();
                createFile();
                _user = getUser();
            }
            cursor.close();
        }
    }
}

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
  super.onSaveInstanceState(savedInstanceState);
  savedInstanceState.putBoolean("Layout", _inAccountDetails);
  savedInstanceState.putSerializable(EXTRA_MESSAGE5, (Serializable) _user);
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
  super.onRestoreInstanceState(savedInstanceState);  
  savedInstanceState.getBoolean("Layout");
  _user = (User) savedInstanceState.getSerializable(EXTRA_MESSAGE5);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.account_manager:
            setContentView(R.layout.registration_edit);
            initializeAccountDetails(_user);
            _inAccountDetails = true;
            return true;
        case R.id.delete_account:
            new DeleteDialogFragment().show(getSupportFragmentManager(), "Dialog");
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}

private void initializeAccountDetails(User user){
    try{
        EditText editText1 = (EditText) findViewById(R.id.editText1);
        editText1.setText(user.getFirstName());

        EditText editText2 = (EditText) findViewById(R.id.EditText01);
        editText2.setText(user.getSurname());

        EditText editText3 = (EditText) findViewById(R.id.EditText02);
        editText3.setText(user.getEmail());

        EditText editText4 = (EditText) findViewById(R.id.EditText03);
        editText4.setText(user.getPostalCode());

        EditText editText5 = (EditText) findViewById(R.id.EditText04);
        editText5.setText(user.getHouseNumber());
    } catch(NullPointerException e){
        Toast.makeText(this, getString(R.string.noAccountRegistered), Toast.LENGTH_LONG).show();
    }
}
private boolean RetrieveInfo(){
    String email, voornaam, achternaam, postalCode, housenumber;

    EditText emailTxt = (EditText) findViewById(R.id.EditText02);
    EditText voornaamTxt = (EditText) findViewById(R.id.editText1);
    EditText achternaamTxt = (EditText) findViewById(R.id.EditText01);
    EditText postalCodeTxt = (EditText) findViewById(R.id.EditText03);
    EditText housenumberTxt = (EditText) findViewById(R.id.EditText04);

    if(!emailTxt.getText().toString().matches("") && !voornaamTxt.getText().toString().matches("") 
            && !achternaamTxt.getText().toString().matches("") && !postalCodeTxt.getText().toString().matches("") 
            && !housenumberTxt.getText().toString().matches("")){
        email = emailTxt.getText().toString();      
        voornaam = voornaamTxt.getText().toString();        
        achternaam = achternaamTxt.getText().toString();        
        postalCode = postalCodeTxt.getText().toString();        
        housenumber = housenumberTxt.getText().toString();
        _user = null;
        _user = new User(email,voornaam,achternaam,postalCode,housenumber);
        return true;
    } else {
        return false;
    }
}

private static final String EMAIL_PATTERN = 
        "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
        + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

private boolean CheckInfo(){
    Pattern pattern = Pattern.compile(EMAIL_PATTERN);

    EditText emailTxt = (EditText) findViewById(R.id.EditText02);
    Debug.out(emailTxt.getText().toString());
    if(pattern.matcher(emailTxt.getText().toString()).matches()){
        return true;
    } else {
        Toast.makeText(getApplicationContext(), getString(R.string.noValidEmail), Toast.LENGTH_LONG).show();
        return false;
    }
}

public void toApplicationEdit(View view){
    if(CheckInfo()){
        if(RetrieveInfo()){
            Intent intent = new Intent(this,this.getClass());
            String sql = "UPDATE User SET Email='"+_user.getEmail()+
                    "', Voornaam='"+_user.getFirstName()+
                    "', Achternaam='"+_user.getSurname()+
                    "', PostalCode='"+_user.getPostalCode()+
                    "', Housenumber='"+_user.getHouseNumber()+
                    "' WHERE User_ID="+1+";";
            if(_dataSource.DbHelper._database != null){
                _dataSource.open();
                _dataSource.DbHelper._database.execSQL(sql);
                _dataSource.close();
            }
            startActivity(intent);
        } else {
            Toast.makeText(this, getString(R.string.everyFieldIsMandatory), Toast.LENGTH_LONG).show();
        }
    }
}

public void cancelToApplication(View view){
    Intent intent = new Intent(this, this.getClass());
    startActivity(intent);
}

public void toApplication(View view){
    if(CheckInfo()){
        if(RetrieveInfo()){
            Intent intent = new Intent(this, this.getClass());

            String sql = "INSERT INTO User(Email, Voornaam, Achternaam, PostalCode, Housenumber)" +
                    " VALUES('"+_user.getEmail()+"'," +
                            "'"+_user.getFirstName()+"','"+_user.getSurname()+"'," +
                                    "'"+_user.getPostalCode()+"','"+_user.getHouseNumber()+"');";
            String sql2 = "SELECT User_ID From User WHERE Email = '"+_user.getEmail()+"';";
            _dataSource = new DataSource(this);
            if(_dataSource.DbHelper._database != null){
                _dataSource.open();
                _dataSource.DbHelper._database.execSQL(sql);
                Cursor cursor = _dataSource.DbHelper._database.rawQuery(sql2,null);                         
                cursor.moveToFirst();
                _dataSource.close();

                while (!cursor.isAfterLast()) {
                    cursor.moveToNext();
                }
                cursor.close();
            }
            startActivity(intent);
        } else {
            Toast.makeText(this, getString(R.string.everyFieldIsMandatory), Toast.LENGTH_LONG).show();
        }
    }
}

private User getUser(){
    String sql = "SELECT * FROM User";
    String email = "", voornaam = "", achternaam = "", postalCode = "", housenumber = "";
    if(_dataSource.DbHelper._database != null){
        _dataSource.open();
        Cursor cursor = _dataSource.DbHelper._database.rawQuery(sql,null);                          
        cursor.moveToFirst();
        _dataSource.close();

        while (!cursor.isAfterLast()) {
            email = cursor.getString(1);
            voornaam = cursor.getString(2);
            achternaam = cursor.getString(3);
            postalCode = cursor.getString(4);
            housenumber = cursor.getString(5);
            cursor.moveToNext();
        }
        cursor.close();
    }
    return new User(email,voornaam,achternaam,postalCode,housenumber);
}

public void createFile(){
    _dataSource = new DataSource(this);
}

public void addItemsOnSpinner2(List<String> list) {
    _spinner2 = (Spinner) findViewById(R.id.spinner2);
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    _spinner2.setAdapter(dataAdapter);
    _sizesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
}

public void addItemsToAdapter(List<String> list){
    _dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
}

public void addListenerOnSpinnerItemSelection() {
    _spinner1 = (Spinner) findViewById(R.id.spinner1);

    _spinner1.setOnItemSelectedListener(
            new OnItemSelectedListener() {
                public void onItemSelected(
                        AdapterView<?> parent, View view, int position, long id) {
                    _inch = Double.parseDouble(parent.getItemAtPosition(position).toString());
                    String sql = "SELECT Maat, Category FROM Band Where Inch = "+_inch;                     
                    _spinner2 = (Spinner) findViewById(R.id.spinner2);

                    if(_dataSource.DbHelper._database != null){
                        _dataSource.open();
                        Cursor cursor = _dataSource.DbHelper._database.rawQuery(sql,null);                          
                        cursor.moveToFirst();
                        _dataSource.close();
                        if(_categoryList.size() != 0){
                            _categoryList.clear();
                        }
                        if(_sizes.size() != 0){
                            _sizes.clear();
                        }
                        while (!cursor.isAfterLast()) {
                            _sizes.add(cursor.getString(0));

                            if(cursor.getString(1) !=null){
                                _categoryList.add(cursor.getString(1));
                            }
                            cursor.moveToNext();
                        }
                        cursor.close();
                    }
                    addItemsOnSpinner2(_sizes); 
                    addItemsToAdapter(_categoryList);
                }

                public void onNothingSelected(AdapterView<?> parent) {

                }
            });
  }

public void addListenerOnSpinner2ItemSelection() {
    _spinner2 = (Spinner) findViewById(R.id.spinner2);
    _spinner2.setOnItemSelectedListener(
            new OnItemSelectedListener() {
                public void onItemSelected(
                        AdapterView<?> parent, View view, int position, long id) {
                    if(_categoryList != null){
                        _category = Integer.parseInt(_dataAdapter.getItem(position));
                    }
                    if(_sizes != null){
                        _size = _sizesAdapter.getItem(position);
                    }
                }

                public void onNothingSelected(AdapterView<?> parent) {

                }
            });
  }

public void next(View view) {
    Intent intent = new Intent(this, Step2.class);
    intent.putExtra(EXTRA_MESSAGE, _category);
    intent.putExtra(EXTRA_MESSAGE2, _inch);
    intent.putExtra(EXTRA_MESSAGE3, _size);
    intent.putExtra(EXTRA_MESSAGE5, (Serializable) _user);
    startActivity(intent);
}

}

As far as i know i'm not doing anything which has something to do with creating files on the memory. The only thing i'm doing in the createFile method is checking if a database exists on memory (and it does exists if i may believe my file explorer). If the database does not exist, it'll create the database.

Baklap4
  • 3,914
  • 2
  • 29
  • 56
  • 1
    This appears to be an error in system code unrelated to your program. It's possible that running your program triggers it, but likely running lots of other programs would also trigger it. Does your program fail to work? – Chris Stratton Dec 04 '13 at 15:08
  • The program doesn't fail to work, i just noticed the error, and didn't know what it was and if i've made it or not. But according to your answere it's not my error if i'm right – Baklap4 Dec 04 '13 at 15:26

0 Answers0