Cursor finalize . close() issue - java

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.

Related

SQLiteException: unrecognized token in UPDATE statement

This is my update query,
ContentValues value = new ContentValues();
value.put(DBhelper.Amount, txtBudget.getText().toString());
db = helper.getWritableDatabase();
db.update(DBhelper.TABLE1, value," "+DBhelper.Description+"='"+value_in_tv,null);
db.close();
fetchData2();
Toast.makeText(this, "Update Successfully", Toast.LENGTH_LONG).show();
clearfield();
when click the button to update,it's giving fatal exception error.
value_in_tv this is the value I got from another class
Bundle data_from_list= getIntent().getExtras();
value_in_tv= data_from_list.getString("passed data key");
txr.setText(value_in_tv);
Error:
10-18 20:45:57.812 18632-18632/com.example.username.weddingplanning
E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.database.sqlite.SQLiteException: unrecognized token: "'suba" (code 1): , while compiling: UPDATE Category SET amount=?
WHERE description='suba
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:686)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1669)
at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1620)
at com.example.username.weddingplanning.addbudget.checkIfRowPresent(addbudget.java:134)
at com.example.username.weddingplanning.addbudget.onClick(addbudget.java:114)
at android.view.View.performClick(View.java:4439)
at android.view.View$PerformClick.run(View.java:18398)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5299)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
You forgot the closing ' in the where clause:
db.update(DBhelper.TABLE1, value," "+DBhelper.Description+"='"+value_in_tv + "'",null)

android app parse values through intent

I am trying to parse a value through intent while switching between activities.
I know I should read values from last intent with getExtra but I don't know why it doesn't work.
Also when I switch between activities on button click, application crashes.
In activity main I read text from editText and put it in Intent:
public void schimba(View view){
int value = Integer.parseInt(instances.getText().toString());;
Intent intent = new Intent(this, Tabel.class);
intent.putExtra("max", value);
startActivity(intent);
}
When it switch to activity 2 I have this:
Intent intentObject = getIntent();
int value;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
value = intentObject.getIntExtra("max", 0);
/*
for(i=0;i<=value;i++)
{
LayoutInflater layoutinflate = null;
layoutinflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowview = layoutinflate.inflate( R.layout.activity_tabel, null);
}
*/
setContentView(R.layout.activity_tabel);
TextView showvalue;
showvalue = (TextView) findViewById(R.id.ShowValue);
showvalue.setText(""+value);
The idea is that I want to use this value in a for loop, I already know how to display the value in a textView but I don't need it, I wanna use it in for.
Logcat:
04-23 10:40:52.550: E/AndroidRuntime(1010): FATAL EXCEPTION: main
04-23 10:40:52.550: E/AndroidRuntime(1010): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.instances_temperature/com.example.instances_temperature.Tabel}: java.lang.NullPointerException
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.os.Looper.loop(Looper.java:123)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-23 10:40:52.550: E/AndroidRuntime(1010): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 10:40:52.550: E/AndroidRuntime(1010): at java.lang.reflect.Method.invoke(Method.java:521)
04-23 10:40:52.550: E/AndroidRuntime(1010): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-23 10:40:52.550: E/AndroidRuntime(1010): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-23 10:40:52.550: E/AndroidRuntime(1010): at dalvik.system.NativeStart.main(Native Method)
04-23 10:40:52.550: E/AndroidRuntime(1010): Caused by: java.lang.NullPointerException
04-23 10:40:52.550: E/AndroidRuntime(1010): at com.example.instances_temperature.Tabel.onCreate(Tabel.java:26)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-23 10:40:52.550: E/AndroidRuntime(1010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-23 10:40:52.550: E/AndroidRuntime(1010): ... 11 more
line 26 would be this:
value = intentObject.getIntExtra("max", 0);
You have to use the code below
int maxValue = getIntent().getExtras().getInt("max");
inside onCreate().
Hope it will solve your problem..
You have not declared intentObject...
Use this:
value = getIntent().getIntExtra("max", 0);
use this
value = getIntent().getStringExtra("max");
instead of this
value = intentObject.getIntExtra("max", 0);

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.

Not a supported ISO 4217 currency code: GBP

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)

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