onTap make itemizedOverlay and activity crashes due to bad constructors - java

i have my Mapactivity which addes some items from an overlay items but whenever i tap on an item, it gives me null pointer exception and of course crashes. I've made many researches and all results say that it's due to bad construtors and Context but the problem is that their solutions doesn't work for me. here are some related topics
link 1
link2
link3
i've tryied, this, this.getApplicationContext but stil, i'have a null pointer ewception
here is where i call my overlayItems in my mapActivity class:
marker1 =getResources().getDrawable(R.drawable.maps_position_marker);
marker1.setBounds( (int) (-marker1.getIntrinsicWidth()/2),
-marker1.getIntrinsicHeight(),
(int) (marker1.getIntrinsicWidth()/2),
0);
overlay4 notFunPlaces = new overlay4(marker1, this.getBaseContext());
mapView.getOverlays().add(notFunPlaces);
// GeoPoint pt1 = notFunPlaces.getCenterPt();
int latSpan1 = notFunPlaces.getLatSpanE6();
int lonSpan1 = notFunPlaces.getLonSpanE6();
Log.v("Overlays", "Lat span is " + latSpan1);
Log.v("Overlays", "Lon span is " + lonSpan1);
my itmizedOverlay class class:
#SuppressWarnings("rawtypes")
class overlay4 extends ItemizedOverlay {
private ArrayList<OverlayItem> locations =
new ArrayList<OverlayItem>();
private Context mContext;
private PopupPanel panel=new PopupPanel(R.layout.popup);
public <getBaseContext> overlay4(Drawable marker, getBaseContext context )
{
super(boundCenterBottom(marker));
mContext = (Context) context;
// my items
.........
populates();}
#Override
protected boolean onTap(int i) {
OverlayItem item=getItem(i);
GeoPoint geo=item.getPoint();
Bitmap bitmap = null;
Point pro= mapView.getProjection().toPixels(geo, null);
if (pro!=null)
{ View view=panel.getView();
String capteur= getType (locations.get(i).getSnippet());
((TextView)view.findViewById(R.id.poptext))
.setText(String.valueOf("image captured by : " + capteur + "\n" + "Latitude = " + locations.get(i).getPoint().getLatitudeE6()/1E6 +" " + "Longitude = "+ locations.get(i).getPoint().getLongitudeE6()/1E6 +" " +
"\n" + "Image can be found at the following directory :" + locations.get(i).getTitle()
));
ImageView image= (ImageView) findViewById(R.id.ImageV);
........
my logcat:
FATAL EXCEPTION: main
java.lang.NullPointerException
at tfe.rma.ciss.be.TheMap$overlay4.onTap(TheMap.java:3705)
at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356)
at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
at com.google.android.maps.MapView.onTouchEvent(MapView.java:683)
at android.view.View.dispatchTouchEvent(View.java:3885)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1750)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1135)
at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1734)
at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2216)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
: Force finishing activity tfe.rma.ciss.be/.TheMap
tate > /data/log/dumpstate_app_error
: Force finishing activity tfe.rma.ciss.be/.menu

Related

Why am I getting an java.lang.IllegalArgumentException: the bind value at index 1 is null in this case?

I know what an java.lang.IllegalArgumentException: the bind value at index 1 is null means and what causes the error. I my case I am still unable to find the reason for such an error in my case.
So, what do I intend to achieve?
I have 4 columns in my SQLite database table. I want to find the sum of each column and again find the sum of these four results. The row values for sum is filtered based on the product name chosen by the user from the autoCompleteTextView.
Where am I getting the error?
my stackTrace says I am getting the error in the line beginning with Cursor c = db.query... in the below code. The following code is part of my db file of my android project.
public int addPurchaseQuantity(String itemName) {
SQLiteDatabase db = helper.getReadableDatabase();
int result = 0;
String selection = VivzHelper.COLUMN_ADD_PURCHASE_ITEM_NAME + " =? ";
String[] selectionArgs = {itemName};
Cursor c = db.query(VivzHelper.ADD_PURCHASE_TABLE,
new String[]{"sum(" + VivzHelper.COLUMN_ADD_PURCHASE_ITEM_QUANTITY + ")"},
selection,
selectionArgs,
null,
null,
null);
if (c.moveToFirst()) {
result = c.getInt(0);
}
c.close();
return result;
}
The itemName is obtained from the autoCompleteTextView based on user selection.
String[] autoCompleteName = vivzHelper.getInventoryNameFilterBySupplierName(vivzHelper.getSupplierID(param1));
ArrayAdapter<String> NameAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, autoCompleteName);
addPurchaseItemName.setThreshold(1);// starts working from first char
addPurchaseItemName.setAdapter(NameAdapter);
addPurchaseItemName.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
itemName = String.valueOf(arg0.getItemAtPosition(arg2));
}
});
My stackTrace is also pointing to the following code of the java activity file.
int purchaseQty = vivzHelper.addPurchaseQuantity(itemName);
Here is my stackTrace
04-21 00:09:58.274 21975-21975/com.example.bharathduraiswamy.comboedittext E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bharathduraiswamy.comboedittext/com.example.bharathduraiswamy.comboedittext.AddPurchase}: java.lang.IllegalArgumentException: the bind value at index 1 is null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2313)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
at android.app.ActivityThread.access$600(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5336)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: the bind value at index 1 is null
at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:164)
at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
at com.example.bharathduraiswamy.comboedittext.VivzDatabaseAdapter.addPurchaseQuantity(VivzDatabaseAdapter.java:2011)
at com.example.bharathduraiswamy.comboedittext.AddPurchase.aggregateQty(AddPurchase.java:531)
at com.example.bharathduraiswamy.comboedittext.AddPurchase.onCreate(AddPurchase.java:133)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2277)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
at android.app.ActivityThread.access$600(ActivityThread.java:156)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:153)
        at android.app.ActivityThread.main(ActivityThread.java:5336)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
        at dalvik.system.NativeStart.main(Native Method)
Can someone tell me where actually am I going wrong?
Update 01 : onCreate() from AddPurchase activity added
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_purchase);
// Set a toolbar to replace the action bar
Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar_addPurchase);
setSupportActionBar(myToolbar);
myToolbar.setNavigationIcon(R.drawable.logo);
//Disable the Toolbar Title
getSupportActionBar().setDisplayShowTitleEnabled(false);
// Adding UP icon for Setting Activity
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
SharedPreferences myPreferences = getSharedPreferences("sharedSupplierData", Context.MODE_PRIVATE);
param1 = myPreferences.getString("sharedSupplierName", DEFAULT);
if (param1.equals(DEFAULT)) {
Message.message(this, "No data was found");
}
addPurchaseItemName = (AutoCompleteTextView) findViewById(R.id.addPurchaseProductName);
addPurchaseItemQty = (EditText) findViewById(R.id.addPurchaseProductQuantity);
addPurchaseCostPrice = (EditText) findViewById(R.id.addPurchaseCostPrice);
addPurchaseSalePrice = (EditText) findViewById(R.id.addPurchaseSalePrice);
myDate = (TextView) findViewById(R.id.addPurchaseDatum);
purchaseSum = (TextView) findViewById(R.id.addPurchaseSum);
primarySpinner = (Spinner) findViewById(R.id.toolbar_spinner);
vivzHelper = new VivzDatabaseAdapter(this);
showDialogOnButtonClick();
populateListView();
String[] autoCompleteName = vivzHelper.getInventoryNameFilterBySupplierName(vivzHelper.getSupplierID(param1));
ArrayAdapter<String> NameAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, autoCompleteName);
addPurchaseItemName.setThreshold(1);// starts working from first char
addPurchaseItemName.setAdapter(NameAdapter);
addPurchaseItemName.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
itemName = String.valueOf(arg0.getItemAtPosition(arg2));
}
});
Message.message(this, ("Item Name = " + itemName));
aggregateQty();
//Initializing an Adapter
ArrayAdapter<String> toolbar_adapter = new ArrayAdapter<>(
this, android.R.layout.simple_spinner_dropdown_item, primarySpinner_array);
//Providing the Resource xml for Drop down Layout
toolbar_adapter.setDropDownViewResource(R.layout.custom_simple_spinner_dropdown_item);
primarySpinner.setAdapter(toolbar_adapter);
//Setting a default Spinner value before onItemClick
primarySpinner.setSelection(0);
//Initializing an OnItemClick Listener for Spinner Item
primarySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
int position_toolbar = primarySpinner.getSelectedItemPosition();
//Changing Spinner TextSize and Text Color
((TextView) arg0.getChildAt(0)).setTextColor(Color.WHITE);
((TextView) arg0.getChildAt(0)).setTextSize(20);
//Changing Spinner Pointer Color - partially effective
primarySpinner.getBackground().setColorFilter(getResources().getColor(R.color.White), PorterDuff.Mode.SRC_ATOP);
//Using Switch to move to other Activities
Intent intent_spinner;
switch (arg2) {
case 1:
intent_spinner = new Intent(AddPurchase.this, SupplierDues.class);
AddPurchase.this.startActivity(intent_spinner);
break;
case 2:
intent_spinner = new Intent(AddPurchase.this, SupplierReturns.class);
AddPurchase.this.startActivity(intent_spinner);
break;
case 3:
intent_spinner = new Intent(AddPurchase.this, SupplierBalanceSheet.class);
AddPurchase.this.startActivity(intent_spinner);
break;
case 4:
intent_spinner = new Intent(AddPurchase.this, AddSupplier.class);
AddPurchase.this.startActivity(intent_spinner);
break;
default:
break;
}
//Changing Spinner Pointer Color - partially effective
primarySpinner.getBackground().setColorFilter(getResources().getColor(R.color.White), PorterDuff.Mode.SRC_ATOP);
//Setting a default Spinner value after onItemClick
primarySpinner.setSelection(0);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
Update 02 : aggregateQty() from when the addPurchaseQuantity() is called
public void aggregateQty() {
int purchaseQty = vivzHelper.addPurchaseQuantity(itemName);
int saleQty = vivzHelper.addSaleQuantity(itemName);
int supplierRtnQty = vivzHelper.returnedToSupplierQuantity(itemName, rtnPrice);
int supplierRtnScrapQty = vivzHelper.returnedToSupplierForScrapQuantity(itemName, rtnPrice);
int customerRtnQty = vivzHelper.returnedByCustomerQuantity(itemName, rtnPrice);
if (itemName.length() != 0) {
availableQuantity = String.valueOf(purchaseQty - saleQty - supplierRtnQty - supplierRtnScrapQty + customerRtnQty);
addPurchaseItemQty.setHint(availableQuantity);
Message.message(this, ("Item Name = " + itemName + "\n" +
"Purchase Quantity = " + purchaseQty + "\n" +
"Sale Quantity = " + saleQty + "\n" +
"Supplier Return Quantity = " + supplierRtnQty + "\n" +
"Customer Return Quantity = " + customerRtnQty));
} else {
Message.message(this, "Please Select an Item");
}
}
itemName is null in addPurchaseQuantity() invocation and thus why when SQLite tries to use it to replace the selection argument ('?') you receive this exception.
Try setting itemName to a known value and check the results.
EDIT
You should test every method independently so you can easily discover the errors or bugs. Learn to apply unit testing as described in Testing Fundamentals.
Then, you'll discover that the problem is reduced to get the text value from an AutoCompletTextView which you can find plenty of examples out there (i.e. How to get string text from AutoCompleteTextView?).
I would try removing the sum in : new String[]{"sum(" + VivzHelper.COLUMN_ADD_PURCHASE_ITEM_QUANTITY + ")"},
See if bind works.

Android App SQLite Database Creation Crashing

I am working on a simple app for myself that posts information to a database. I'm really new at this and tried to follow some tutorials along with other tidbits to assemble this.
There is a home screen that gets to the second screen which has a button (add item). Onclicking, this is supposed to build/update the database. I get a crash when I enter that second screen before anything happens. I tried to put in breakpoints to debug but I can't even to get anywhere. It doesn't pause at my breakpoints (or doesn't seem to) so I can't see what's going on
Can anyone point in the right direction for debugging/fixing this?
This is my 2nd screen code - java
public class AddItem extends Activity {
private final String TAG = "Main Activity";
View view;
SQLiteDatabase db;
DbPrice dbprice ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_item);
Log.i(TAG, "OnCreate");
dbprice = new DbPrice(this);
db = dbprice.getWritableDatabase();
Button addButton = (Button) findViewById(R.id.addNew);
addButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
String subcat,item,store,extra;
Integer day,month,year,price,quantity,weight,volume;
Boolean sale;
DatePicker datePicker1 = (DatePicker) findViewById(R.id.datePicker1);
AutoCompleteTextView autoCompleteSubCat = (AutoCompleteTextView) findViewById(R.id.autoCompleteSubCat);
EditText editItem = (EditText) findViewById(R.id.editItem);
EditText editPrice = (EditText) findViewById(R.id.editPrice);
EditText editQuantity = (EditText) findViewById(R.id.editQuantity);
EditText editWeight = (EditText) findViewById(R.id.editWeight);
EditText editVolume = (EditText) findViewById(R.id.editVolume);
CheckBox checkSale = (CheckBox) findViewById(R.id.checkSale);
AutoCompleteTextView autoCompleteStore = (AutoCompleteTextView) findViewById(R.id.autoCompleteStore);
EditText editExtra = (EditText) findViewById(R.id.editExtra);
day = datePicker1.getDayOfMonth();
month = datePicker1.getMonth();
year = datePicker1.getYear();
subcat = autoCompleteSubCat.getText().toString();
item = editItem.getText().toString();
extra = editExtra.getText().toString();
price = Integer.parseInt(editPrice.getText().toString());
quantity = Integer.parseInt(editQuantity.getText().toString());
weight = Integer.parseInt(editWeight.getText().toString());
volume = Integer.parseInt(editVolume.getText().toString());
// sale = checkSale.isChecked();
store = autoCompleteStore.getText().toString();
ContentValues cv = new ContentValues();
cv.put(DbPrice.SUBCAT, subcat);
cv.put(DbPrice.ITEM, item);
cv.put(DbPrice.EXTRA, extra);
cv.put(DbPrice.PRICE, price);
cv.put(DbPrice.QUANTITY, quantity);
cv.put(DbPrice.WEIGHT, weight);
cv.put(DbPrice.VOLUME, volume);
cv.put(DbPrice.SALE, sale);
cv.put(DbPrice.STORE, store);
db.insert(DbPrice.TABLE_NAME, null, cv);
}
});
}
#Override
public void onStart() {
super.onStart();
Log.i(TAG, "OnStart");
}
#Override
public void onResume() {
super.onResume();
Log.i(TAG, "OnResume");
}
public void OnPause() {
super.onPause();
Log.i(TAG,"OnPause");
}
public void OnStop() {
super.onStart();
Log.i(TAG, "OnStop");
}
public void OnDestroy() {
super.onDestroy();
Log.i(TAG, "OnDestroy");
}
public void addNewItem (View v) {
Log.i(TAG, "Starting New Activity");
Intent intent = new Intent (this, AllItems.class);
startActivity(intent);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.add_item, menu);
return true;
}
}
The database class java is below. I don't know if you need the xml too but I included the catlog.
public class DbPrice extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "data";
public static final String TABLE_NAME = "price_table";
public static final String C_ID = "_id";
public static final String DAY = "day";
public static final String MONTH = "month";
public static final String YEAR = "day";
public static final String SUBCAT = "subcategory";
public static final String ITEM = "item";
public static final String PRICE = "price";
public static final String QUANTITY = "quantity";
public static final String WEIGHT = "weight";
public static final String VOLUME = "volume";
public static final String SALE = "sale";
public static final String STORE = "store";
public static final String EXTRA = "extra";
public static final int VERSION = 1;
private final String createDb = "create table if not exists " + TABLE_NAME+ " ( "
+ C_ID + " integer primary key autoincrement, "
+ DAY + " text, "
+ MONTH + " text, "
+ YEAR + " text, "
+ SUBCAT + " text, "
+ ITEM + " text, "
+ PRICE + " text, "
+ QUANTITY + " text, "
+ WEIGHT + " text, "
+ VOLUME + " text, "
+ SALE + " text, "
+ STORE + " text, "
+ EXTRA + " text) ";
public DbPrice(Context context) {
super(context, DATABASE_NAME, null, VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(createDb);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion) {
db.execSQL("drop table " + TABLE_NAME);
}
}
CATLOG BELOW
12-29 01:27:20.834: I/Main Activity(1362): OnCreate
12-29 01:27:21.044: E/SQLiteLog(1362): (1) duplicate column name: day
12-29 01:27:21.054: D/AndroidRuntime(1362): Shutting down VM
12-29 01:27:21.064: W/dalvikvm(1362): threadid=1: thread exiting with uncaught exception (group=0xb4b11b90)
12-29 01:27:21.194: E/AndroidRuntime(1362): FATAL EXCEPTION: main
12-29 01:27:21.194: E/AndroidRuntime(1362): Process: com.unsuccessfulstudent.grocerypricehistory, PID: 1362
12-29 01:27:21.194: E/AndroidRuntime(1362): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.unsuccessfulstudent.grocerypricehistory/com.unsuccessfulstudent.grocerypricehistory.AddItem}: android.database.sqlite.SQLiteException: duplicate column name: day (code 1): , while compiling: create table if not exists price_table ( _id integer primary key autoincrement, day text, month text, day text, subcategory text, item text, price text, quantity text, weight text, volume text, sale text, store text, extra text)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.os.Handler.dispatchMessage(Handler.java:102)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.os.Looper.loop(Looper.java:137)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-29 01:27:21.194: E/AndroidRuntime(1362): at java.lang.reflect.Method.invokeNative(Native Method)
12-29 01:27:21.194: E/AndroidRuntime(1362): at java.lang.reflect.Method.invoke(Method.java:515)
12-29 01:27:21.194: E/AndroidRuntime(1362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-29 01:27:21.194: E/AndroidRuntime(1362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-29 01:27:21.194: E/AndroidRuntime(1362): at dalvik.system.NativeStart.main(Native Method)
12-29 01:27:21.194: E/AndroidRuntime(1362): Caused by: android.database.sqlite.SQLiteException: duplicate column name: day (code 1): , while compiling: create table if not exists price_table ( _id integer primary key autoincrement, day text, month text, day text, subcategory text, item text, price text, quantity text, weight text, volume text, sale text, store text, extra text)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1672)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1603)
12-29 01:27:21.194: E/AndroidRuntime(1362): at com.unsuccessfulstudent.grocerypricehistory.DbPrice.onCreate(DbPrice.java:49)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
12-29 01:27:21.194: E/AndroidRuntime(1362): at com.unsuccessfulstudent.grocerypricehistory.AddItem.onCreate(AddItem.java:31)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.app.Activity.performCreate(Activity.java:5243)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-29 01:27:21.194: E/AndroidRuntime(1362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
12-29 01:27:21.194: E/AndroidRuntime(1362): ... 11 more
12-29 01:27:24.554: I/Process(1362): Sending signal. PID: 1362 SIG: 9
The reason for your app crash is caused by the fact that in your database creation query you are defining the same key twice. Thats why you are getting a duplicate column error.
Both the keys you have,i.e., DAY as well as YEAR have the same value day. You cannot have two columns in a database with the same name. So, to resolve this, all you need to do is change the YEAR definition to-
public static final String YEAR = "year";
Hope this helps!!!
You use two same columns
DAY = "day";
YEAR = "day";
Code:
create table if not exists price_table
(
_id integer primary key autoincrement,
"**day**" text,
month text,
"**day**" text,...
)
Whenever there is an Exception, if you see a line FATAL EXCEPTION: main in Logcat, look at the below lines. The line with Unable to start activity ComponentInfo, will give you a clear idea about the cause of exception. Still if you are confused, look for a line starting with Caused by:.
So here your problem is "duplicate column name: day".
Also you can navigate to the specific line which caused the exception. Just look for your package name. Here in this case,
12-29 01:27:21.194: E/AndroidRuntime(1362): at com.unsuccessfulstudent.grocerypricehistory.DbPrice.onCreate(DbPrice.java:49)
12-29 01:27:21.194: E/AndroidRuntime(1362): at com.unsuccessfulstudent.grocerypricehistory.AddItem.onCreate(AddItem.java:31)
At the end of the lines, There is corresponding class and line number. Note that these are the lines caused exception, but the cause of exception may be somewhere else. In this case, String YEAR

java.lang.NullPointerException:com.google.android.gms.maps.GoogleMap.moveCamera

I am currently working on the new Google Maps Android API v2.
My MapActivity class is working with my Samsung galaxy s3 ans s2 with the code below:
However, there are some particular devices are not working such as: GT-S5830i
class MapActivity extends FragmentActivity implements OnMapClickListener, OnMapLongClickListener, OnMarkerClickListener
{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
tvLocInfo = (TextView)findViewById(R.id.locinfo);
android.support.v4.app.FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment myMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = myMapFragment.getMap();
myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
ArrayList<Cooridnates> cooridnatesList = MainActivity.getList();
for(int i=0;i<cooridnatesList.size();i++)
{
//Toast.makeText(MapActivity.this, "SIZE : " + " " + cooridnatesList.size(), Toast.LENGTH_LONG).show();
LatLng point = new LatLng(cooridnatesList.get(i).getLat(),cooridnatesList.get(i).getLon());
tvLocInfo.setText("markers added");
myMap.addMarker(new MarkerOptions().position(point).title(point.toString()));
center=CameraUpdateFactory.newLatLng(point);
}
CameraUpdate zoom=CameraUpdateFactory.zoomTo(16);
myMap.moveCamera(center);
myMap.animateCamera(zoom);
myMap.setOnMapClickListener(this);
myMap.setOnMarkerClickListener(this);
markerClicked = false;
}
For some reason, I am getting this error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.coldice.plotfinder/com.coldice.plotfinder.MapActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.google.android.gms.maps.GoogleMap.moveCamera(Unknown Source)
at com.coldice.plotfinder.MapActivity.onCreate(MapActivity.java:70)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
You function MainActivity.getList() probably returned an empty list, so for loop doesn't execute center=CameraUpdateFactory.newLatLng(point);.
it seems center is null in this >> myMap.moveCamera(center);, make an appropriate check on this variable before passing it in moveCamera method.
It seems problem is here. center might have null value, So to get proper explanation debug your application.
center is initialzed here.
center=CameraUpdateFactory.newLatLng(point);
It might assign null in center.
myMap.moveCamera(center); <<<PROBLEM is here
if(center != null )
myMap.moveCamera(center);

Music Player - Function doesn't work when trying to use objects

I am making a music player application for my Computing project. I got it working but found that using objects would get more more marks. As a result, I changed some of my code to incorporate the use of objects, but it doesn't work when I execute my application. Btw I am quite new to Java so it's possible I made a silly mistake.
When I used this code the function I tried to implement worked:
private void SongTitleEndTime(){
try {
TextViewSongTitle = (TextView)findViewById(R.id.songTitle);
if (id != 0 ){
String where = MediaStore.Audio.Media._ID + " = " + "'" + id + "'";
final Cursor mCursor = managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] {MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media._ID.toString(), MediaStore.Audio.Media.ALBUM_ID.toString()}, where , null,
null);
mCursor.moveToFirst();
String title = mCursor.getString(0);
String artist = mCursor.getString(1);
String name = title + " - " + artist;
TextViewSongTitle.setText(name);
String fulltime;
albumfullid = Long.parseLong(mCursor.getString(3));
TextView EndTime = (TextView) findViewById(R.id.endtime);
long Minutes = TimeUnit.MILLISECONDS.toMinutes(mMediaPlayer.getDuration());
long Seconds = TimeUnit.MILLISECONDS.toSeconds(mMediaPlayer.getDuration()) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(mMediaPlayer.getDuration()));
if (Seconds < 10) {
String second = "0" + String.valueOf(Seconds);
fulltime = Minutes + ":" + second;
} else {
//else display as normal
fulltime = Minutes + ":" + Seconds;
}
EndTime.setText(fulltime);
//display the duration of song
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} //catch for errors
}
But when I tried this, I got an error:
Main Class:
private void SongTitleEndTime() {
try {
final TextView TextViewSongTitle = (TextView) findViewById(R.id.songTitle);
if (CurrentSongID != 0) {
final Song CurrentSong = new Song(CurrentSongID);
SongName = CurrentSong.SongName;
TextViewSongTitle.setText(SongName);
AlbumID = CurrentSong.AlbumID;
final TextView EndTime = (TextView) findViewById(R.id.endtime);
final String TotalSongDuration = CurrentSong.TotalDuration;
EndTime.setText(TotalSongDuration);
}
} catch (final IllegalArgumentException e) {
e.printStackTrace();
} catch (final IllegalStateException e) {
e.printStackTrace();
}
}
Object Class:
package com.example.music.test;
import java.util.concurrent.TimeUnit;
import android.app.Activity;
import android.database.Cursor;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio.AudioColumns;
import android.provider.MediaStore.MediaColumns;
public class Song extends Activity {
private final String where;
public String SongName;
public long AlbumID;
public String TotalDuration;
public Song(final long SongID) {
where = MediaStore.Audio.Media._ID + " = " + "'" + SongID + "'";
final Cursor mCursor = managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media._ID.toString(),
MediaStore.Audio.Media.ALBUM_ID.toString() }, where, null, null);
mCursor.moveToFirst();
final String SongTitle = getSongTitle(mCursor);
final String SongArtist = getSongArtist(mCursor);
SongName = SongTitle + " - " + SongArtist;
AlbumID = getAlbumID(mCursor);
TotalDuration = getTotalDuration();
}
public String getSongTitle(final Cursor mCursor) {
final String songtitle = mCursor.getString(0);
return songtitle;
}
public String getSongArtist(final Cursor mCursor) {
final String songartist = mCursor.getString(1);
return songartist;
}
public long getAlbumID(final Cursor mCursor) {
final long AlbumID = Long.parseLong(mCursor.getString(3));
return AlbumID;
}
public String getTotalDuration() {
String TotalTime;
final long Minutes = TimeUnit.MILLISECONDS
.toMinutes(Player.mMediaPlayer.getDuration());
final long Seconds = TimeUnit.MILLISECONDS
.toSeconds(Player.mMediaPlayer.getDuration())
- TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
.toMinutes(Player.mMediaPlayer.getDuration()));
if (Seconds < 10) {
final String second = "0" + String.valueOf(Seconds);
TotalTime = Minutes + ":" + second;
} else {
TotalTime = Minutes + ":" + Seconds;
}
return TotalTime;
}
}
The error I get is:
01-02 21:55:41.941: E/AndroidRuntime(717): FATAL EXCEPTION: main
01-02 21:55:41.941: E/AndroidRuntime(717): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.music.test/com.example.music.test.Player}: java.lang.NullPointerException
01-02 21:55:41.941: E/AndroidRuntime(717): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.os.Looper.loop(Looper.java:137)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-02 21:55:41.941: E/AndroidRuntime(717): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 21:55:41.941: E/AndroidRuntime(717): at java.lang.reflect.Method.invoke(Method.java:511)
01-02 21:55:41.941: E/AndroidRuntime(717): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-02 21:55:41.941: E/AndroidRuntime(717): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-02 21:55:41.941: E/AndroidRuntime(717): at dalvik.system.NativeStart.main(Native Method)
01-02 21:55:41.941: E/AndroidRuntime(717): Caused by: java.lang.NullPointerException
01-02 21:55:41.941: E/AndroidRuntime(717): at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:91)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.app.Activity.managedQuery(Activity.java:1737)
01-02 21:55:41.941: E/AndroidRuntime(717): at com.example.music.test.Song.<init>(Song.java:21)
01-02 21:55:41.941: E/AndroidRuntime(717): at com.example.music.test.Player.SongTitleEndTime(Player.java:90)
01-02 21:55:41.941: E/AndroidRuntime(717): at com.example.music.test.Player.AllActivities(Player.java:80)
01-02 21:55:41.941: E/AndroidRuntime(717): at com.example.music.test.Player.onCreate(Player.java:66)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.app.Activity.performCreate(Activity.java:5008)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-02 21:55:41.941: E/AndroidRuntime(717): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
01-02 21:55:41.941: E/AndroidRuntime(717): ... 11 more
Song is an Activity. Thus you can't call manageQuery before onCreate has been called. That's your error.

Inserting into and withdrawing from SQLite database and displaying to a TextView - Android

I am trying to implement a SQLite database for a highscores table. I am just testing it to see if my database creation, insertion and selecting is working with the below code. I am trying to insert the first row into the database and then immediately pull from it and display the values to TextViews. All of the hardcoding is for testing purposes to just get the database working correctly.
I am getting a IllegalStateException on the below lines. I have commented in the errors on the appropriate lines.
Any additional advice on code structure is much appreciate too.
Thank you in advance!
Highscores.java
public class Highscores extends Activity {
DatabaseHelper dh;
SQLiteDatabase db;
int percentages;
long scores;
TableLayout table;
TableRow rowHeader, row1, row2, row3, row4, row5, row6, row7, row8, row9, row10;
TextView rank, percentage, score;
Button btn1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.highscoresmain);
dh = new DatabaseHelper(this);
db = dh.openDB();
long x = 11;
int y = 22;
dh.insert(x, y);
percentages = dh.getPercentage(db); //Line 45
scores = dh.getScore(db);
Button btn1 = (Button)findViewById(R.id.homeBtn);
TextView rank = (TextView)findViewById(R.id.rank);
TextView percentage = (TextView)findViewById(R.id.percentage);
TextView score = (TextView)findViewById(R.id.score);
TextView r1r = (TextView)findViewById(R.id.r1r);
TextView r1p = (TextView)findViewById(R.id.r1p);
TextView r1s = (TextView)findViewById(R.id.r1s);
rank.setText("Rank Column - TEST");
percentage.setText("Percentage Column - TEST ");
score.setText("Score Column - Test");
r1r.setText("test..rank");
r1p.setText(percentages);
r1s.setText("test..score");
table = (TableLayout)findViewById(R.id.tableLayout);
dh.closeDB(db);
}
}
DatabaseHelper.java
public class DatabaseHelper extends SQLiteOpenHelper {
SQLiteDatabase db;
private static final String TABLE = "HighscoresList";
public static DatabaseHelper mSingleton = null;
// Table columns names.
private static final String RANK = "_id";
private static final String SCORE = "score";
private static final String PERCENTAGE = "percentage";
public DatabaseHelper(Context context) {
super(context, DB_NAME, null, DATABASE_VERSION);
}
public synchronized static DatabaseHelper getInstance(Context context) {
if(mSingleton == null) {
mSingleton = new DatabaseHelper(context.getApplicationContext());
}
return mSingleton;
}
public SQLiteDatabase openDB() {
db = this.getWritableDatabase();
return db;
}
//I am using hard coded numbers in the below 2 methods for testing purposes.
public long getScore(SQLiteDatabase db) {
Cursor c = db.rawQuery("SELECT " + SCORE + " FROM " + TABLE + " WHERE " + SCORE + " = " + 11 + ";", null); //Line 45
long i = 0;
if(c.getCount() != 0) {
c.moveToFirst();
int columnIndex = c.getInt(c.getColumnIndex("SCORE"));
if(columnIndex != -1) {
i = c.getLong(columnIndex);
} else {
i = 999;
}
} else {
i = 555;
}
c.close();
return i;
}
public int getPercentage(SQLiteDatabase db) {
Cursor c = db.rawQuery("SELECT " + PERCENTAGE + " FROM " + TABLE + " WHERE " + PERCENTAGE + " = " + 22 + ";", null);
int i = 0;
if(c.getCount() != 0) {
c.moveToFirst();
int columnIndex = c.getInt(c.getColumnIndex("PERCENTAGE"));
if(columnIndex != -1) {
i = c.getInt(columnIndex);
} else {
i = 999;
}
} else {
i = 555;
}
c.close();
return i;
}
//Insert new record.
public long insert(long score, int percentage) {
ContentValues values = new ContentValues();
values.put(SCORE, score);
values.put(PERCENTAGE, percentage);
return db.insert(TABLE, null, values);
}
}
LogCat output
01-03 15:39:13.952: E/AndroidRuntime(938): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.Highscores}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
01-03 15:39:13.952: E/AndroidRuntime(938): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.os.Handler.dispatchMessage(Handler.java:99)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.os.Looper.loop(Looper.java:137)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-03 15:39:13.952: E/AndroidRuntime(938): at java.lang.reflect.Method.invokeNative(Native Method)
01-03 15:39:13.952: E/AndroidRuntime(938): at java.lang.reflect.Method.invoke(Method.java:511)
01-03 15:39:13.952: E/AndroidRuntime(938): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-03 15:39:13.952: E/AndroidRuntime(938): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-03 15:39:13.952: E/AndroidRuntime(938): at dalvik.system.NativeStart.main(Native Method)
01-03 15:39:13.952: E/AndroidRuntime(938): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
01-03 15:39:13.952: E/AndroidRuntime(938): at android.database.CursorWindow.nativeGetLong(Native Method)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.database.CursorWindow.getLong(CursorWindow.java:507)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.database.CursorWindow.getInt(CursorWindow.java:574)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:69)
01-03 15:39:13.952: E/AndroidRuntime(938): at com.example.test.DatabaseHelper.getPercentage(DatabaseHelper.java:67)
01-03 15:39:13.952: E/AndroidRuntime(938): at com.example.test.Highscores.onCreate(Highscores.java:45)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.app.Activity.performCreate(Activity.java:5104)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-03 15:39:13.952: E/AndroidRuntime(938): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-03 15:39:13.952: E/AndroidRuntime(938): ... 11 more
EDIT: I updated my getScore() and getPercentage() methods. Anyways, I still used some hardcoded numbers so I know exactly what is going on but the program is still crashing. It seems that the if-else statement should set i to 555 instead of crashing but it isn't.
I updated the LogCat output also.
I don't see any database initializing code overriding onCreate but it says your column doesn't exist in the table check it's name again or check the table. Also get into the habit of closing your cursors once your done using them. Otherwise the database will throw errors when you haven't closed a previous cursor.
Just noticed the error its you're using "PERCENTAGE" while you defined it as
PERCENTAGE = "percentage";
so just be consistent in using the defined variable.
Android - SQLite Cursor getColumnIndex() is case sensitive?
public int getPercentage(SQLiteDatabase db) {
Cursor c = db.rawQuery("SELECT " + PERCENTAGE + " FROM " + TABLE + " WHERE " + PERCENTAGE + " = " + 22 + ";", null);
int i = 0;
if (c.moveToFirst())
{
int colIdx = c.getColumnIndex(PERCENTAGE);
if (colIdx != -1) // Column exists
i = c.getInt(colIdx); //Line 54
}
c.close();
return i;
}
Building off of David's comment:
public int getPercentage(SQLiteDatabase db) {
Cursor c = db.rawQuery("SELECT " + PERCENTAGE + " FROM " + TABLE + " WHERE " + PERCENTAGE + " = " + 22 + ";", null);
if(c.getCount() != 0){
c.moveToFirst();
int i = c.getInt(c.getColumnIndex(PERCENTAGE)); //Line 54
return i;
} else { return 0 }
}
Use the constant consistently, and make sure it's exactly like your sqllite DB. Apparently getColumnIndex is case sensitive ;)

Categories

Resources