jeudi 23 avril 2015

I can not understand what is wrong in my code, any help is appreciated

This is my complete code for Admin class. When I call this class from another class via Intent, app crashes showing no signs of error at all.

I checked the manifest and the build, and cleaned the project more than the words in this post. I have been banging my head for past hour for a solution and still couldn't find one. Please let me know what could be the issue. Any help is appreciated.

Regards.

package com.pricecalculator;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class Admin extends Activity{

    Button Edit,Update;
    ListView listView1;
    DbComplete myDb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.admin_view);
        listView1 = (ListView)findViewById(R.id.listView1);
        Edit = (Button)findViewById(R.id.button2);
        Update = (Button)findViewById(R.id.button3);

        openDB();
        populate();

    }

    public void onClick_editDb(View v){

        Intent i = new Intent(this,EditDb.class);
        startActivity(i);
    }

    public void onClick_Calculate(View v){

        myDb.insertRow("Jenny", 5559);
        Toast.makeText(getApplicationContext(), "Entry Added!",
                   Toast.LENGTH_LONG).show();

        /*Intent i = new Intent(this,Calculate.class);
        startActivity(i);*/
    }

    private void openDB(){
        myDb = new DbComplete(this);
        myDb.open();
    }

    private void populate(){
        Cursor cursor = myDb.getAllRows();
        String[] fromNames = new String[]{DbComplete.COLUMN_ID,DbComplete.COLUMN_PRODUCTNAME,DbComplete.COLUMN_PRODUCTPRICE};
        int[] toViewIds = new int[]{R.id.textView1,R.id.editText1};
        SimpleCursorAdapter mySimpleAdapter;
        mySimpleAdapter = new SimpleCursorAdapter(getBaseContext(), R.layout.product_list, cursor, fromNames, toViewIds,0);
        ListView myList = (ListView)findViewById(R.id.listView1);
        myList.setAdapter(mySimpleAdapter);
    }




}

Aucun commentaire:

Enregistrer un commentaire