Not a supported ISO 4217 currency code: GBP - java

How to extract the currency symbol using currency which is like string "GBP" i am using
String s = obj.getCurrency().toString();
Currency currency=Currency.getInstance(s);
but it was throwing this exception :
01-31 11:40:40.464: E/AndroidRuntime(3929): FATAL EXCEPTION: main
01-31 11:40:40.464: E/AndroidRuntime(3929): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.primesoft.games.potshot/com.primesoft.games.potshot.PotshotActivity}: java.lang.IllegalArgumentException: Not a supported ISO 4217 currency code: GBP
01-31 11:40:40.464: E/AndroidRuntime(3929): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-31 11:40:40.464: E/AndroidRuntime(3929): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-31 11:40:40.464: E/AndroidRuntime(3929): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-31 11:40:40.464: E/AndroidRuntime(3929): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-31 11:40:40.464: E/AndroidRuntime(3929): at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 11:40:40.464: E/AndroidRuntime(3929): at android.os.Looper.loop(Looper.java:130)
01-31 11:40:40.464: E/AndroidRuntime(3929): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-31 11:40:40.464: E/AndroidRuntime(3929): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 11:40:40.464: E/AndroidRuntime(3929): at java.lang.reflect.Method.invoke(Method.java:507)
01-31 11:40:40.464: E/AndroidRuntime(3929): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

Related

Rounding to no decimal places (value is returned with 10 decimal places?)

So, I have this code implemented and working:
try {
float healthF = Float.parseFloat(getHealth);
healthchest.setText(Float.toString((healthF * 100) * 0.30f));
}
But the value it returns has about 10 decimal places with a 6 randomly placed at the end. Something akin to this: ###.0000000006. The weird thing is the value of healthF is 30. 3000 * .3 equals 900. Not 900.0000000006.
I tried to implement this:
try {
float healthF = Float.parseFloat(getHealth);
healthchest.setText(Float.toString((healthF * 100) * 0.30f));
df.format(healthchest);
}
but it causes the app to crash with the following logcat:
09-03 03:26:54.755: W/dalvikvm(1080): threadid=1: thread exiting with uncaught exception (group=0x41465700)
09-03 03:26:54.785: E/AndroidRuntime(1080): FATAL EXCEPTION: main
09-03 03:26:54.785: E/AndroidRuntime(1080): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mikitz.rogsimple/com.mikitz.rogsimple.ArmorStatsSP}: java.lang.IllegalArgumentException: Bad class: class android.widget.EditText
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.os.Looper.loop(Looper.java:137)
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-03 03:26:54.785: E/AndroidRuntime(1080): at java.lang.reflect.Method.invokeNative(Native Method)
09-03 03:26:54.785: E/AndroidRuntime(1080): at java.lang.reflect.Method.invoke(Method.java:525)
09-03 03:26:54.785: E/AndroidRuntime(1080): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-03 03:26:54.785: E/AndroidRuntime(1080): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-03 03:26:54.785: E/AndroidRuntime(1080): at dalvik.system.NativeStart.main(Native Method)
09-03 03:26:54.785: E/AndroidRuntime(1080): Caused by: java.lang.IllegalArgumentException: Bad class: class android.widget.EditText
09-03 03:26:54.785: E/AndroidRuntime(1080): at java.text.NumberFormat.format(NumberFormat.java:304)
09-03 03:26:54.785: E/AndroidRuntime(1080): at java.text.DecimalFormat.format(DecimalFormat.java:702)
09-03 03:26:54.785: E/AndroidRuntime(1080): at java.text.Format.format(Format.java:93)
09-03 03:26:54.785: E/AndroidRuntime(1080): at com.mikitz.rogsimple.ArmorStatsSP.onCreate(ArmorStatsSP.java:78)
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.app.Activity.performCreate(Activity.java:5133)
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-03 03:26:54.785: E/AndroidRuntime(1080): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-03 03:26:54.785: E/AndroidRuntime(1080): ... 11 more
You can't pass the edittext to the DecimalFormat, use the following method and pass the value to it, than set the string returned to the edittext.
public static String twoDecimalPlaces(double value){
try
{
DecimalFormat df = new DecimalFormat("#.##");
return df.format(value);
} catch (Exception e) {
LogHandler.error("twoDecimalPlaces","main",e);
}
return String.valueOf(value);
}
You can simply use
Float floatValue = 1.454f;
String.format("%.0f",floatValue);

Unable to start receiver, java null pointer exception

I am getting a Java null pointer exception Unable to start receiver error,
My LogCat
04-23 21:55:16.889: I/TextView(8039): *****onCrecateContextMenu::isInputMethodTarget:true, isIMEChangable;true
04-23 21:55:25.479: D/AndroidRuntime(8039): Shutting down VM
04-23 21:55:25.479: W/dalvikvm(8039): threadid=1: thread exiting with uncaught exception (group=0x40018578)
04-23 21:55:25.479: E/AndroidRuntime(8039): FATAL EXCEPTION: main
04-23 21:55:25.479: E/AndroidRuntime(8039): java.lang.RuntimeException: Unable to start receiver com.yp.iss_project.CbReceiver: java.lang.NullPointerException
04-23 21:55:25.479: E/AndroidRuntime(8039): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1809)
04-23 21:55:25.479: E/AndroidRuntime(8039): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
04-23 21:55:25.479: E/AndroidRuntime(8039): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
04-23 21:55:25.479: E/AndroidRuntime(8039): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 21:55:25.479: E/AndroidRuntime(8039): at android.os.Looper.loop(Looper.java:130)
04-23 21:55:25.479: E/AndroidRuntime(8039): at android.app.ActivityThread.main(ActivityThread.java:3687)
04-23 21:55:25.479: E/AndroidRuntime(8039): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 21:55:25.479: E/AndroidRuntime(8039): at java.lang.reflect.Method.invoke(Method.java:507)
04-23 21:55:25.479: E/AndroidRuntime(8039): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-23 21:55:25.479: E/AndroidRuntime(8039): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-23 21:55:25.479: E/AndroidRuntime(8039): at dalvik.system.NativeStart.main(Native Method)
04-23 21:55:25.479: E/AndroidRuntime(8039): Caused by: java.lang.NullPointerException
04-23 21:55:25.479: E/AndroidRuntime(8039): at com.yp.iss_project.CbReceiver.onReceive(CbReceiver.java:272)
04-23 21:55:25.479: E/AndroidRuntime(8039): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1798)
04-23 21:55:25.479: E/AndroidRuntime(8039): ... 10 more
04-23 21:56:57.819: W/KeyCharacterMap(8162): No keyboard for id 0
04-23 21:56:57.819: W/KeyCharacterMap(8162): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
04-23 21:57:00.359: I/TextView(8162): *****onCrecateContextMenu::isInputMethodTarget:true, isIMEChangable;true
04-23 21:57:08.069: D/AndroidRuntime(8162): Shutting down VM
04-23 21:57:08.069: W/dalvikvm(8162): threadid=1: thread exiting with uncaught exception (group=0x40018578)
04-23 21:57:08.069: E/AndroidRuntime(8162): FATAL EXCEPTION: main
04-23 21:57:08.069: E/AndroidRuntime(8162): java.lang.RuntimeException: Unable to start receiver com.yp.iss_project.CbReceiver: java.lang.NullPointerException
04-23 21:57:08.069: E/AndroidRuntime(8162): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1809)
04-23 21:57:08.069: E/AndroidRuntime(8162): at andr oid.app.ActivityThread.access$2400(ActivityThread.java:117)
04-23 21:57:08.069: E/AndroidRuntime(8162): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
04-23 21:57:08.069: E/AndroidRuntime(8162): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 21:57:08.069: E/AndroidRuntime(8162): at android.os.Looper.loop(Looper.java:130)
04-23 21:57:08.069: E/AndroidRuntime(8162): at android.app.ActivityThread.main(ActivityThread.java:3687)
04-23 21:57:08.069: E/AndroidRuntime(8162): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 21:57:08.069: E/AndroidRuntime(8162): at java.lang.reflect.Method.invoke(Method.java:507)
04-23 21:57:08.069: E/AndroidRuntime(8162): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-23 21:57:08.069: E/AndroidRuntime(8162): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-23 21:57:08.069: E/AndroidRuntime(8162): at dalvik.system.NativeStart.main(Native Method)
04-23 21:57:08.069: E/AndroidRuntime(8162): Caused by: java.lang.NullPointerException
04-23 21:57:08.069: E/AndroidRuntime(8162): at com.yp.iss_project.CbReceiver.onReceive(CbReceiver.java:273)
04-23 21:57:08.069: E/AndroidRuntime(8162): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1798)
04-23 21:57:08.069: E/AndroidRuntime(8162): ... 10 more
04-23 21:59:10.639: I/TextView(8265): *****onCrecateContextMenu::isInputMethodTarget:true, isIMEChangable;true
04-23 21:59:19.979: D/AndroidRuntime(8265): Shutting down VM
04-23 21:59:19.979: W/dalvikvm(8265): threadid=1: thread exiting with uncaught exception (group=0x40018578)
My broadcast receiver is
public static String str;
public static int my;
public static String MSG = encrypt.message;
public final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
public void onReceive(Context context, Intent intent) {
//---get the CB message passed in---
Bundle bundle = intent.getExtras();
SmsCbMessage[] msgs = null;
if (bundle != null) {
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsCbMessage[pdus.length];
for (int i=0; i<msgs.length; i++) {
msgs[i] = SmsCbMessage.createFromPdu((byte[])pdus[i]);
str = "";
str +="" +msgs[i].getGeographicalScope() + msgs[i].getMessageCode() + msgs[i].getMessageIdentifier() + msgs[i].getUpdateNumber();
my = msgs[i].getGeographicalScope() + msgs[i].getMessageCode() + msgs[i].getMessageIdentifier() + msgs[i].getUpdateNumber();
if(str != "")
{
Toast.makeText(context, "CB: " +str, Toast.LENGTH_LONG).show();
Toast.makeText(context, "MY: " +my, Toast.LENGTH_LONG).show();
{
String cipherText="";
for(int y=0;y<MSG.length();y++)
{
int charPosition = ALPHABET.indexOf(MSG.charAt(y));
int keyVal = (my + charPosition)%26;
char replaceVal = this.ALPHABET.charAt(keyVal);
cipherText += replaceVal;
}
Toast.makeText(context, "CipherText: " +cipherText, Toast.LENGTH_LONG).show();
}
}
}
abortBroadcast();
}
Removed
public static String MSG = encrypt.message;
and replaced all occurrences of MSG with
encrypt.message
My mistake was with passing the value pf message from the encrypt class, as the MSG value declared in the receiver class is a null I've received a null pointer exception.

How to get Options Menu to work on Nexus 7?

I am programming an app with an Options Menu in my Main Activity. This Options Menu works fine on my HTC Android Incredible device. However, when I test it with a Nexus 7 emulator the program crashes. How can I get the options menu to work on the Nexus 7? Any ideas on this? Thank you in advance. Here is the code I am using.
package com.carouseldemo.main;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.carouseldemo.controls.Carousel;
import com.carouseldemo.controls.CarouselAdapter;
import com.carouseldemo.controls.CarouselAdapter.AdapterContextMenuInfo;
import com.carouseldemo.controls.CarouselAdapter.OnItemClickListener;
import com.carouseldemo.controls.CarouselAdapter.OnItemSelectedListener;
import com.carouseldemo.controls.CarouselItem;
public class MainActivity extends Activity {
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.testmenu1, menu);
// your code...
return true;} // true if you want the menu to be displayed; false otherwise
#Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// Just prepare ourself for unexpected arguments...
if (menuInfo == null) {
return;
}
if (!(menuInfo instanceof AdapterContextMenuInfo)) {
return;
}
AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
switch (mi.position) {
case 0:
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
break;
case 1:
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
break;
case 2:
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
break;
case 3:
menu.add("mouse menu");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
break;
case 4:
menu.add("panda menu");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
break;
case 5:
menu.add("rabbit menu");
menu.add("Product 1");
menu.add("Product 1");
menu.add("Product 1");
break;
default:
break;
}
super.onCreateContextMenu(menu, v, menuInfo);
}
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Carousel carousel = (Carousel) findViewById(R.id.carousel);
carousel.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(CarouselAdapter<?> parent, View view,
int position, long id) {
CarouselItem item = (CarouselItem) parent.getChildAt(position);
// HERE: Force context menu
carousel.showContextMenuForChild(item);
Toast.makeText(
MainActivity.this,
String.format("%s has been clicked",
((CarouselItem) parent.getChildAt(position))
.getName()), Toast.LENGTH_SHORT).show();
}
#Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
return false;
}});
carousel.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(CarouselAdapter<?> parent, View view,
int position, long id) {
final TextView txt = (TextView) (findViewById(R.id.selected_item));
switch (position) {
case 0:
txt.setText("The cat (Felis catus), also known as the domestic cat or housecat to distinguish it from other felids and felines, is a small, usually furry, domesticated, carnivorous mammal that is valued by humans for its companionship and for its ability to hunt vermin and household pests. Cats have been associated with humans for at least 9,500 years, and are currently the most popular pet in the world. Owing to their close association with humans, cats are now found almost everywhere in the world.");
break;
case 1:
txt.setText("The hippopotamus (Hippopotamus amphibius), or hippo, from the ancient Greek for \"river horse\" (), is a large, mostly herbivorous mammal in sub-Saharan Africa, and one of only two extant species in the family Hippopotamidae (the other is the Pygmy Hippopotamus.) After the elephant, the hippopotamus is the third largest land mammal and the heaviest extant artiodactyl.");
break;
case 2:
txt.setText("A monkey is a primate, either an Old World monkey or a New World monkey. There are about 260 known living species of monkey. Many are arboreal, although there are species that live primarily on the ground, such as baboons. Monkeys are generally considered to be intelligent. Unlike apes, monkeys usually have tails. Tailless monkeys may be called \"apes\", incorrectly according to modern usage; thus the tailless Barbary macaque is called the \"Barbary ape\".");
break;
case 3:
txt.setText("A mouse (plural: mice) is a small mammal belonging to the order of rodents. The best known mouse species is the common house mouse (Mus musculus). It is also a popular pet. In some places, certain kinds of field mice are also common. This rodent is eaten by large birds such as hawks and eagles. They are known to invade homes for food and occasionally shelter.");
break;
case 4:
txt.setText("The giant panda, or panda (Ailuropoda melanoleuca, literally meaning \"black and white cat-foot\") is a bear native to central-western and south western China.[4] It is easily recognized by its large, distinctive black patches around the eyes, over the ears, and across its round body. Though it belongs to the order Carnivora, the panda's diet is 99% bamboo.");
break;
case 5:
txt.setText("Rabbits (or, colloquially, bunnies) are small mammals in the family Leporidae of the order Lagomorpha, found in several parts of the world. There are eight different genera in the family classified as rabbits, including the European rabbit (Oryctolagus cuniculus), cottontail rabbits (genus Sylvilagus; 13 species), and the Amami rabbit (Pentalagus furnessi, an endangered species on Amami, Japan)");
break;
}
}
public void onNothingSelected(CarouselAdapter<?> parent) {
}
});
registerForContextMenu(carousel);
}
}
LogCat Error:
01-31 19:55:42.221: E/AndroidRuntime(1758): FATAL EXCEPTION: main
01-31 19:55:42.221: E/AndroidRuntime(1758): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.carouseldemo.main/com.carouseldemo.main.MainActivity}: android.view.InflateException: Binary XML file line #34: Error inflating class com.carouseldemo.controls.Carousel
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.os.Looper.loop(Looper.java:137)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-31 19:55:42.221: E/AndroidRuntime(1758): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 19:55:42.221: E/AndroidRuntime(1758): at java.lang.reflect.Method.invoke(Method.java:511)
01-31 19:55:42.221: E/AndroidRuntime(1758): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-31 19:55:42.221: E/AndroidRuntime(1758): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-31 19:55:42.221: E/AndroidRuntime(1758): at dalvik.system.NativeStart.main(Native Method)
01-31 19:55:42.221: E/AndroidRuntime(1758): Caused by: android.view.InflateException: Binary XML file line #34: Error inflating class com.carouseldemo.controls.Carousel
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-31 19:55:42.221: E/AndroidRuntime(1758): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.app.Activity.setContentView(Activity.java:1881)
01-31 19:55:42.221: E/AndroidRuntime(1758): at com.carouseldemo.main.MainActivity.onCreate(MainActivity.java:108)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.app.Activity.performCreate(Activity.java:5104)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-31 19:55:42.221: E/AndroidRuntime(1758): ... 11 more
01-31 19:55:42.221: E/AndroidRuntime(1758): Caused by: java.lang.reflect.InvocationTargetException
01-31 19:55:42.221: E/AndroidRuntime(1758): at java.lang.reflect.Constructor.constructNative(Native Method)
01-31 19:55:42.221: E/AndroidRuntime(1758): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
01-31 19:55:42.221: E/AndroidRuntime(1758): ... 22 more
01-31 19:55:42.221: E/AndroidRuntime(1758): Caused by: java.lang.OutOfMemoryError
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.content.res.Resources.loadDrawable(Resources.java:1965)
01-31 19:55:42.221: E/AndroidRuntime(1758): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-31 19:55:42.221: E/AndroidRuntime(1758): at com.carouseldemo.controls.Carousel$ImageAdapter.SetImages(Carousel.java:778)
01-31 19:55:42.221: E/AndroidRuntime(1758): at com.carouseldemo.controls.Carousel.<init> (Carousel.java:253)
01-31 19:55:42.221: E/AndroidRuntime(1758): at com.carouseldemo.controls.Carousel.<init> (Carousel.java:204)
01-31 19:55:42.221: E/AndroidRuntime(1758): ... 25 more

Cursor finalize . close() issue

I'm trying to retrieve the data from my database through a cursor object once the database has been queried. I seem to be getting an error on my cursor.close() and when closing my database. This has been fine up until the point but I started receiving 'cursor finalizer' errors when accessing classes from different intents.
At the moment I seem to have my cursor objects closing in an incorrect manner.
As an example heres how Im trying to retrieve all the data to populate a listview within the onCreate method of my class.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.appointmentview);
searchedAppView = (ListView)findViewById(android.R.id.list);
DBHandlerApp DBAppointments = new DBHandlerApp(this, null, null);
DBHandlerApp searchApps = new DBHandlerApp(this, null, null);
searchApps.open();
Cursor cursor = searchApps.getAppointmentsData();
startManagingCursor(cursor);
#SuppressWarnings("static-access")
String [] from = new String [] {DBAppointments.KEY_NAMEAPP, DBAppointments.KEY_TYPEAPP, DBAppointments.KEY_TIMEAPP, DBAppointments.KEY_DATEAPP, DBAppointments.KEY_COMMENTAPP};
int [] to = new int [] {R.id.txtAppointName, R.id.txtAppointType, R.id.txtAppointTime, R.id.txtAppointDate, R.id.txtAppointCom};
#SuppressWarnings("deprecation")
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.setappointviews, cursor, from, to);
searchedAppView.setAdapter(cursorAdapter);
searchAppoints = (ImageButton) findViewById(R.id.btnSearchAppointName);
searchAppName = (EditText) findViewById(R.id.inputAppointName);
searchAppoints.setOnClickListener(this);
}
Heres the method 'getAppointmentData' of the DBHandlerApp class:
public Cursor getAppointmentsData() {
String [] columns = new String[]{KEY_ROWAPPID, KEY_NAMEAPP, KEY_TYPEAPP, KEY_TIMEAPP, KEY_DATEAPP, KEY_COMMENTAPP};
Cursor c = ourDatabase.query(DATABASE_TABLEAPP, columns, null, null, null, null, KEY_NAMEAPP + " ASC", null);
//*****Closing the cursor object.*****
c.close();
return c;
Logcat error:
01-31 17:44:34.220: E/AndroidRuntime(269): FATAL EXCEPTION: main
01-31 17:44:34.220: E/AndroidRuntime(269): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.ViewAppointments}: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentsTable ORDER BY app_name ASC)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.os.Looper.loop(Looper.java:123)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 17:44:34.220: E/AndroidRuntime(269): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 17:44:34.220: E/AndroidRuntime(269): at java.lang.reflect.Method.invoke(Method.java:521)
01-31 17:44:34.220: E/AndroidRuntime(269): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-31 17:44:34.220: E/AndroidRuntime(269): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-31 17:44:34.220: E/AndroidRuntime(269): at dalvik.system.NativeStart.main(Native Method)
01-31 17:44:34.220: E/AndroidRuntime(269): Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentsTable ORDER BY app_name ASC)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:34)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:64)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:283)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:264)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.support.v4.widget.CursorAdapter.getCount(CursorAdapter.java:202)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.widget.ListView.setAdapter(ListView.java:436)
01-31 17:44:34.220: E/AndroidRuntime(269): at com.example.flybase2.ViewAppointments.onCreate(ViewAppointments.java:54)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-31 17:44:34.220: E/AndroidRuntime(269): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-31 17:44:34.220: E/AndroidRuntime(269): ... 11 more
Currently at the moment I do not close the database using .searchApps.close();. If do this then I get the following logcat error:
01-31 17:52:17.324: E/AndroidRuntime(277): FATAL EXCEPTION: main
01-31 17:52:17.324: E/AndroidRuntime(277): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.ViewAppointments}: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentsTable ORDER BY app_name ASC)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.os.Looper.loop(Looper.java:123)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 17:52:17.324: E/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 17:52:17.324: E/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
01-31 17:52:17.324: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-31 17:52:17.324: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-31 17:52:17.324: E/AndroidRuntime(277): at dalvik.system.NativeStart.main(Native Method)
01-31 17:52:17.324: E/AndroidRuntime(277): Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentsTable ORDER BY app_name ASC)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:34)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:64)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:283)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:264)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.support.v4.widget.CursorAdapter.getCount(CursorAdapter.java:202)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.widget.ListView.setAdapter(ListView.java:436)
01-31 17:52:17.324: E/AndroidRuntime(277): at com.example.flybase2.ViewAppointments.onCreate(ViewAppointments.java:56)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-31 17:52:17.324: E/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-31 17:52:17.324: E/AndroidRuntime(277): ... 11 more
You're closing your cursor in the wrong place. You should close a cursor when you're completely done using it, you're closing it right after populating it, before returning it from your getAppointmentData method.
Simply removing the close call from that method should fix your problem because when you use startManagingCursor, the activity handles closing it.
As an aside, startManagingCursor is depreciated in favor of using Loaders.
I do not exactly know what the problem is. However, the method startManagingCursor(...) is deprecated and should not be used, see: http://developer.android.com/reference/android/app/Activity.html#startManagingCursor(android.database.Cursor)
A better way is to use a CursorLoader.

App is force closing when i run it? Unable to start activity

When i run my app, and i press on a button it force closes. I fixed my Android manifest and i cannot find the problem. Here is the Logcat:
03-07 23:48:53.035: D/dalvikvm(5457): GC_EXTERNAL_ALLOC freed 43K, 49% free 2797K/5379K, external 1596K/2108K, paused 99ms
03-07 23:48:53.132: D/dalvikvm(5457): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 35ms
03-07 23:48:53.691: D/dalvikvm(5457): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 53ms
03-07 23:48:54.281: D/dalvikvm(5457): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 48ms
03-07 23:48:55.996: D/AndroidRuntime(5457): Shutting down VM
03-07 23:48:55.996: W/dalvikvm(5457): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-07 23:48:56.039: E/AndroidRuntime(5457): FATAL EXCEPTION: main
03-07 23:48:56.039: E/AndroidRuntime(5457): android.content.ActivityNotFoundException: Unable to find explicit activity class {izzy.n/izzy.n.main1}; have you declared this activity in your AndroidManifest.xml?
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.Activity.startActivity(Activity.java:2933)
03-07 23:48:56.039: E/AndroidRuntime(5457): at izzy.n.IzzynActivity$2.onClick(IzzynActivity.java:31)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.view.View.performClick(View.java:2538)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.view.View$PerformClick.run(View.java:9152)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.os.Handler.handleCallback(Handler.java:587)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.os.Looper.loop(Looper.java:130)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:48:56.039: E/AndroidRuntime(5457): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 23:48:56.039: E/AndroidRuntime(5457): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:48:56.039: E/AndroidRuntime(5457): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:48:56.039: E/AndroidRuntime(5457): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:48:56.039: E/AndroidRuntime(5457): at dalvik.system.NativeStart.main(Native Method)
03-07 23:50:31.398: D/dalvikvm(5553): GC_EXTERNAL_ALLOC freed 47K, 49% free 2797K/5379K, external 1596K/2108K, paused 21ms
03-07 23:50:31.457: D/dalvikvm(5553): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 22ms
03-07 23:50:31.660: D/dalvikvm(5553): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 25ms
03-07 23:50:31.753: D/dalvikvm(5553): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 20ms
03-07 23:50:41.910: D/AndroidRuntime(5553): Shutting down VM
03-07 23:50:41.910: W/dalvikvm(5553): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-07 23:50:41.933: E/AndroidRuntime(5553): FATAL EXCEPTION: main
03-07 23:50:41.933: E/AndroidRuntime(5553): android.content.ActivityNotFoundException: Unable to find explicit activity class {izzy.n/izzy.n.main1}; have you declared this activity in your AndroidManifest.xml?
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.Activity.startActivity(Activity.java:2933)
03-07 23:50:41.933: E/AndroidRuntime(5553): at izzy.n.IzzynActivity$2.onClick(IzzynActivity.java:31)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.view.View.performClick(View.java:2538)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.view.View$PerformClick.run(View.java:9152)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.os.Handler.handleCallback(Handler.java:587)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.os.Looper.loop(Looper.java:130)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:50:41.933: E/AndroidRuntime(5553): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 23:50:41.933: E/AndroidRuntime(5553): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:50:41.933: E/AndroidRuntime(5553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:50:41.933: E/AndroidRuntime(5553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:50:41.933: E/AndroidRuntime(5553): at dalvik.system.NativeStart.main(Native Method)
03-07 23:51:20.371: D/dalvikvm(5609): GC_EXTERNAL_ALLOC freed 48K, 49% free 2797K/5379K, external 1596K/2108K, paused 97ms
03-07 23:51:20.503: D/dalvikvm(5609): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 57ms
03-07 23:51:20.792: D/dalvikvm(5609): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 24ms
03-07 23:51:21.039: D/dalvikvm(5609): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 65ms
03-07 23:51:26.679: D/AndroidRuntime(5609): Shutting down VM
03-07 23:51:26.679: W/dalvikvm(5609): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-07 23:51:26.714: E/AndroidRuntime(5609): FATAL EXCEPTION: main
03-07 23:51:26.714: E/AndroidRuntime(5609): android.content.ActivityNotFoundException: Unable to find explicit activity class {izzy.n/izzy.n.main1}; have you declared this activity in your AndroidManifest.xml?
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.Activity.startActivity(Activity.java:2933)
03-07 23:51:26.714: E/AndroidRuntime(5609): at izzy.n.IzzynActivity$2.onClick(IzzynActivity.java:31)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.view.View.performClick(View.java:2538)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.view.View$PerformClick.run(View.java:9152)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.os.Handler.handleCallback(Handler.java:587)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.os.Looper.loop(Looper.java:130)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:51:26.714: E/AndroidRuntime(5609): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 23:51:26.714: E/AndroidRuntime(5609): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:51:26.714: E/AndroidRuntime(5609): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:51:26.714: E/AndroidRuntime(5609): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:51:26.714: E/AndroidRuntime(5609): at dalvik.system.NativeStart.main(Native Method)
03-07 23:59:24.920: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed 51K, 49% free 2797K/5379K, external 1596K/2108K, paused 54ms
03-07 23:59:25.104: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 46ms
03-07 23:59:25.537: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 24ms
03-07 23:59:25.846: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 38ms
03-07 23:59:41.502: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed 10K, 48% free 2828K/5379K, external 11785K/11958K, paused 25ms
03-07 23:59:41.740: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed <1K, 48% free 2829K/5379K, external 13363K/14068K, paused 25ms
03-07 23:59:41.865: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed <1K, 48% free 2830K/5379K, external 16457K/17091K, paused 20ms
03-07 23:59:42.607: D/AndroidRuntime(5784): Shutting down VM
03-07 23:59:42.607: W/dalvikvm(5784): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-07 23:59:42.783: E/AndroidRuntime(5784): FATAL EXCEPTION: main
03-07 23:59:42.783: E/AndroidRuntime(5784): java.lang.RuntimeException: Unable to start activity ComponentInfo{izzy.n/izzy.n.main1}: java.lang.NullPointerException
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.os.Looper.loop(Looper.java:130)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:59:42.783: E/AndroidRuntime(5784): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 23:59:42.783: E/AndroidRuntime(5784): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:59:42.783: E/AndroidRuntime(5784): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:59:42.783: E/AndroidRuntime(5784): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:59:42.783: E/AndroidRuntime(5784): at dalvik.system.NativeStart.main(Native Method)
03-07 23:59:42.783: E/AndroidRuntime(5784): Caused by: java.lang.NullPointerException
03-07 23:59:42.783: E/AndroidRuntime(5784): at izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-07 23:59:42.783: E/AndroidRuntime(5784): at izzy.n.main1.onCreate(main1.java:52)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-07 23:59:42.783: E/AndroidRuntime(5784): ... 11 more
03-07 23:59:52.850: I/Process(5784): Sending signal. PID: 5784 SIG: 9
03-08 00:11:06.982: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed 46K, 49% free 2797K/5379K, external 1596K/2108K, paused 29ms
03-08 00:11:07.033: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 20ms
03-08 00:11:07.248: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 21ms
03-08 00:11:07.350: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 19ms
03-08 00:11:10.588: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed 9K, 48% free 2828K/5379K, external 11785K/11958K, paused 100ms
03-08 00:11:11.068: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed 1K, 48% free 2829K/5379K, external 13363K/14068K, paused 49ms
03-08 00:11:11.365: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed <1K, 48% free 2830K/5379K, external 16457K/17091K, paused 47ms
03-08 00:11:11.736: D/AndroidRuntime(6029): Shutting down VM
03-08 00:11:11.736: W/dalvikvm(6029): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-08 00:11:11.752: E/AndroidRuntime(6029): FATAL EXCEPTION: main
03-08 00:11:11.752: E/AndroidRuntime(6029): java.lang.RuntimeException: Unable to start activity ComponentInfo{izzy.n/izzy.n.main1}: java.lang.NullPointerException
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.os.Looper.loop(Looper.java:130)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-08 00:11:11.752: E/AndroidRuntime(6029): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 00:11:11.752: E/AndroidRuntime(6029): at java.lang.reflect.Method.invoke(Method.java:507)
03-08 00:11:11.752: E/AndroidRuntime(6029): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-08 00:11:11.752: E/AndroidRuntime(6029): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-08 00:11:11.752: E/AndroidRuntime(6029): at dalvik.system.NativeStart.main(Native Method)
03-08 00:11:11.752: E/AndroidRuntime(6029): Caused by: java.lang.NullPointerException
03-08 00:11:11.752: E/AndroidRuntime(6029): at izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-08 00:11:11.752: E/AndroidRuntime(6029): at izzy.n.main1.onCreate(main1.java:52)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-08 00:11:11.752: E/AndroidRuntime(6029): ... 11 more
03-08 00:16:11.924: I/Process(6029): Sending signal. PID: 6029 SIG: 9
03-08 00:16:14.525: D/dalvikvm(6173): GC_EXTERNAL_ALLOC freed 10K, 48% free 2828K/5379K, external 11785K/11958K, paused 20ms
03-08 00:16:14.678: D/dalvikvm(6173): GC_EXTERNAL_ALLOC freed 1K, 48% free 2829K/5379K, external 13363K/14068K, paused 22ms
03-08 00:16:14.779: D/dalvikvm(6173): GC_EXTERNAL_ALLOC freed <1K, 48% free 2829K/5379K, external 16457K/17091K, paused 21ms
03-08 00:16:15.037: D/AndroidRuntime(6173): Shutting down VM
03-08 00:16:15.037: W/dalvikvm(6173): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-08 00:16:15.037: E/AndroidRuntime(6173): FATAL EXCEPTION: main
03-08 00:16:15.037: E/AndroidRuntime(6173): java.lang.RuntimeException: Unable to start activity ComponentInfo{izzy.n/izzy.n.main1}: java.lang.NullPointerException
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.os.Looper.loop(Looper.java:130)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-08 00:16:15.037: E/AndroidRuntime(6173): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 00:16:15.037: E/AndroidRuntime(6173): at java.lang.reflect.Method.invoke(Method.java:507)
03-08 00:16:15.037: E/AndroidRuntime(6173): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-08 00:16:15.037: E/AndroidRuntime(6173): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-08 00:16:15.037: E/AndroidRuntime(6173): at dalvik.system.NativeStart.main(Native Method)
03-08 00:16:15.037: E/AndroidRuntime(6173): Caused by: java.lang.NullPointerException
03-08 00:16:15.037: E/AndroidRuntime(6173): at izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-08 00:16:15.037: E/AndroidRuntime(6173): at izzy.n.main1.onCreate(main1.java:52)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-08 00:16:15.037: E/AndroidRuntime(6173): ... 11 more
Here is the code for Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="izzy.n"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.READ_CALENDAR"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CALENDAR"></uses-permission>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="izzy.n.IzzynActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="izzy.n.notes"
android:label="#string/notes"></activity>
<activity
android:name="izzy.n.calculator"
android:label="#string/calculator"></activity>
<activity android:name="izzy.n.main1"
android:label="#string/app_name"></activity>
</application>
</manifest>
and finally here is the main1.java:
class MyCalendar {
public String name;
public String id;
public MyCalendar(String _name, String _id) {
name = _name;
id = _id;
}
#Override
public String toString() {
return name;
}
}
public class main1 extends Activity {
/*********************************************************************
* UI part*/
private Spinner m_spinner_calender;
private Button m_button_add;
private Button m_button_add2;
private Button m_button_getEvents;
private TextView m_text_event;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*get calendar list and populate the view*/
getCalendars();
populateCalendarSpinner();
populateAddBtn();
populateAddBtn2();
populateTextEvent();
populateGetEventsBtn();
}
private void populateCalendarSpinner() {
m_spinner_calender = (Spinner)this.findViewById(R.id.spinner_calendar);
ArrayAdapter l_arrayAdapter = new ArrayAdapter(this.getApplicationContext(), android.R.layout.simple_spinner_item, m_calendars);
l_arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
m_spinner_calender.setAdapter(l_arrayAdapter);
m_spinner_calender.setSelection(0);
m_spinner_calender.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> p_parent, View p_view,
int p_pos, long p_id) {
m_selectedCalendarId = m_calendars[(int)p_id].id;
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {}
});
}
private void populateAddBtn() {
m_button_add = (Button) this.findViewById(R.id.button_add);
m_button_add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addEvent();
}
});
}
private void populateAddBtn2() {
m_button_add2 = (Button) this.findViewById(R.id.button_add2);
m_button_add2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addEvent2();
}
});
}
private void populateGetEventsBtn() {
m_button_getEvents = (Button) findViewById(R.id.button_get_events);
m_button_getEvents.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getLastThreeEvents();
}
});
}
private void populateTextEvent() {
m_text_event = (TextView) findViewById(R.id.text_event);
String l_str = "title: roman10 calendar tutorial test\n" +
"description: This is a simple test for calendar api\n" +
"eventLocation: #home\n" +
"start time:" + getDateTimeStr(0) + "\n" +
"end time: " + getDateTimeStr(30) + "\n" +
"event status: confirmed\n" +
"all day: no\n" +
"has alarm: yes\n";
m_text_event.setText(l_str);
}
/****************************************************************
* Data part
*/
/*retrieve a list of available calendars*/
private MyCalendar m_calendars[];
private String m_selectedCalendarId = "0";
private void getCalendars() {
String[] l_projection = new String[]{"_id", "displayName"};
Uri l_calendars;
if (Build.VERSION.SDK_INT >= 8) {
l_calendars = Uri.parse("content://com.android.calendar/calendars");
} else {
l_calendars = Uri.parse("content://calendar/calendars");
}
Cursor l_managedCursor = this.managedQuery(l_calendars, l_projection, null, null, null); //all calendars
//Cursor l_managedCursor = this.managedQuery(l_calendars, l_projection, "selected=1", null, null); //active calendars
if (l_managedCursor.moveToFirst()) {
m_calendars = new MyCalendar[l_managedCursor.getCount()];
String l_calName;
String l_calId;
int l_cnt = 0;
int l_nameCol = l_managedCursor.getColumnIndex(l_projection[1]);
int l_idCol = l_managedCursor.getColumnIndex(l_projection[0]);
do {
l_calName = l_managedCursor.getString(l_nameCol);
l_calId = l_managedCursor.getString(l_idCol);
m_calendars[l_cnt] = new MyCalendar(l_calName, l_calId);
++l_cnt;
} while (l_managedCursor.moveToNext());
}
}
/*add an event to calendar*/
private void addEvent() {
ContentValues l_event = new ContentValues();
l_event.put("calendar_id", m_selectedCalendarId);
l_event.put("title", "roman10 calendar tutorial test");
l_event.put("description", "This is a simple test for calendar api");
l_event.put("eventLocation", "#home");
l_event.put("dtstart", System.currentTimeMillis());
l_event.put("dtend", System.currentTimeMillis() + 1800*1000);
l_event.put("allDay", 0);
//status: 0~ tentative; 1~ confirmed; 2~ canceled
l_event.put("eventStatus", 1);
//0~ default; 1~ confidential; 2~ private; 3~ public
l_event.put("visibility", 0);
//0~ opaque, no timing conflict is allowed; 1~ transparency, allow overlap of scheduling
l_event.put("transparency", 0);
//0~ false; 1~ true
l_event.put("hasAlarm", 1);
Uri l_eventUri;
if (Build.VERSION.SDK_INT >= 8) {
l_eventUri = Uri.parse("content://com.android.calendar/events");
} else {
l_eventUri = Uri.parse("content://calendar/events");
}
Uri l_uri = this.getContentResolver().insert(l_eventUri, l_event);
Log.v("++++++test", l_uri.toString());
}
/*add an event through intent, this doesn't require any permission
* just send intent to android calendar
* http://www.openintents.org/en/uris*/
private void addEvent2() {
Intent l_intent = new Intent(Intent.ACTION_EDIT);
l_intent.setType("vnd.android.cursor.item/event");
//l_intent.putExtra("calendar_id", m_selectedCalendarId); //this doesn't work
l_intent.putExtra("title", "roman10 calendar tutorial test");
l_intent.putExtra("description", "This is a simple test for calendar api");
l_intent.putExtra("eventLocation", "#home");
l_intent.putExtra("beginTime", System.currentTimeMillis());
l_intent.putExtra("endTime", System.currentTimeMillis() + 1800*1000);
l_intent.putExtra("allDay", 0);
//status: 0~ tentative; 1~ confirmed; 2~ canceled
l_intent.putExtra("eventStatus", 1);
//0~ default; 1~ confidential; 2~ private; 3~ public
l_intent.putExtra("visibility", 0);
//0~ opaque, no timing conflict is allowed; 1~ transparency, allow overlap of scheduling
l_intent.putExtra("transparency", 0);
//0~ false; 1~ true
l_intent.putExtra("hasAlarm", 1);
try {
startActivity(l_intent);
} catch (Exception e) {
Toast.makeText(this.getApplicationContext(), "Sorry, no compatible calendar is found!", Toast.LENGTH_LONG).show();
}
}
/*get a list of events
* http://jimblackler.net/blog/?p=151*/
private void getLastThreeEvents() {
Uri l_eventUri;
if (Build.VERSION.SDK_INT >= 8) {
l_eventUri = Uri.parse("content://com.android.calendar/events");
} else {
l_eventUri = Uri.parse("content://calendar/events");
}
String[] l_projection = new String[]{"title", "dtstart", "dtend"};
Cursor l_managedCursor = this.managedQuery(l_eventUri, l_projection, "calendar_id=" + m_selectedCalendarId, null, "dtstart DESC, dtend DESC");
//Cursor l_managedCursor = this.managedQuery(l_eventUri, l_projection, null, null, null);
if (l_managedCursor.moveToFirst()) {
int l_cnt = 0;
String l_title;
String l_begin;
String l_end;
StringBuilder l_displayText = new StringBuilder();
int l_colTitle = l_managedCursor.getColumnIndex(l_projection[0]);
int l_colBegin = l_managedCursor.getColumnIndex(l_projection[1]);
int l_colEnd = l_managedCursor.getColumnIndex(l_projection[1]);
do {
l_title = l_managedCursor.getString(l_colTitle);
l_begin = getDateTimeStr(l_managedCursor.getString(l_colBegin));
l_end = getDateTimeStr(l_managedCursor.getString(l_colEnd));
l_displayText.append(l_title + "\n" + l_begin + "\n" + l_end + "\n----------------\n");
++l_cnt;
} while (l_managedCursor.moveToNext() && l_cnt < 3);
m_text_event.setText(l_displayText.toString());
}
}
/************************************************
* utility part
*/
private static final String DATE_TIME_FORMAT = "yyyy MMM dd, HH:mm:ss";
public static String getDateTimeStr(int p_delay_min) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_TIME_FORMAT);
if (p_delay_min == 0) {
return sdf.format(cal.getTime());
} else {
Date l_time = cal.getTime();
l_time.setMinutes(l_time.getMinutes() + p_delay_min);
return sdf.format(l_time);
}
}
public static String getDateTimeStr(String p_time_in_millis) {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_TIME_FORMAT);
Date l_time = new Date(Long.parseLong(p_time_in_millis));
return sdf.format(l_time);
}
}
Fix this:
03-07 23:50:41.933: E/AndroidRuntime(5553): android.content.ActivityNotFoundException: Unable to find explicit activity class {izzy.n/izzy.n.main1}; have you declared this activity in your AndroidManifest.xml?
ALSO
Point out which line its complaining about.
A Object in the populateCalendarSpinner() method is null . Please put try catch and debug.
Your log show
03-08 00:16:15.037: E/AndroidRuntime(6173): Caused by: java.lang.NullPointerException
03-08 00:16:15.037: E/AndroidRuntime(6173): at izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-08 00:16:15.037: E/AndroidRuntime(6173): at izzy.n.main1.onCreate(main1.java:52)
Activity not found is the old log. You already fixed it.
if you're sure you declared it, make sure to clean your project. Sometimes Eclipse doesn't realize your XML has changed and is acting on older versions.
<activity android:name="main1"
android:label="#string/app_name"></activity>
should be
<activity android:name="izzy.n.main1"
android:label="#string/app_name"></activity>
<activity android:name="main1"
android:label="#string/app_name"></activity>
Try with changing this to
<activity android:name="izzy.n.main1"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Your log also says NullPointerException in populateCalendarSpinner(); debug and fix that too.
Just do this to debug:
try {
populateCalendarSpinner();
}
catch(NullPointerException e) {
e.printStackTrace();
}

Categories