NullPointerException during application run - android

When running my application it is stooped with null pointer exception.
problem occurring in 4th line
1. Bundle arguments;
2.arguments = getArguments();
3.String viewType=arguments.getString("viewType");
4.if(viewType.equals("weekly"))
{
......
}
Is there any solution? please reply.
08-16 11:31:03.146: E/AndroidRuntime(2675): FATAL EXCEPTION: main
08-16 11:31:03.146: E/AndroidRuntime(2675): java.lang.NullPointerException
08-16 11:31:03.146: E/AndroidRuntime(2675): at com.nv.netmdapp1.ScheduleCreateDialog$1.onClick(ScheduleCreateDialog.java:188)
08-16 11:31:03.146: E/AndroidRuntime(2675): at com.nv.netmdapp1.customViews.CustomAlertDialog$Builder$1.onClick(CustomAlertDialog.java:110)
08-16 11:31:03.146: E/AndroidRuntime(2675): at android.view.View.performClick(View.java:3511)
08-16 11:31:03.146: E/AndroidRuntime(2675): at android.view.View$PerformClick.run(View.java:14109)
08-16 11:31:03.146: E/AndroidRuntime(2675): at android.os.Handler.handleCallback(Handler.java:605)
08-16 11:31:03.146: E/AndroidRuntime(2675): at android.os.Handler.dispatchMessage(Handler.java:92)
08-16 11:31:03.146: E/AndroidRuntime(2675): at android.os.Looper.loop(Looper.java:137)
08-16 11:31:03.146: E/AndroidRuntime(2675): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-16 11:31:03.146: E/AndroidRuntime(2675): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 11:31:03.146: E/AndroidRuntime(2675): at java.lang.reflect.Method.invoke(Method.java:511)
08-16 11:31:03.146: E/AndroidRuntime(2675): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-16 11:31:03.146: E/AndroidRuntime(2675): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-16 11:31:03.146: E/AndroidRuntime(2675): at dalvik.system.NativeStart.main(Native Method)
This is the error log.Any Idea?

4.if(viewType.equals("weekly")) ---> 4.if("weekly".equals(viewType))

I think the problem is you are not properly referencing you bundle variable. Please try the below code:
Bundle arguments = this.getIntent().getExtras();
String viewType=arguments.getString("viewType");
And the rest shall remain the same.

Related

Android - Upload Image in a Azure Container

I have used the following code to upload image in a storage container in azure from android. It throws the error on "// Create the blob client" line. some java.lang.verifyError. I have searched to solve this error but i can't find any solution.
String connectionString = "DefaultEndpointsProtocol=https;AccountName=StorageAccountName;AccountKey=StorageAccountKey"
CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString);
// Create the blob client
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// Get a reference to a container
// The container name must be lower case
CloudBlobContainer container = blobClient.getContainerReference("images");
// Create the container if it does not exist
container.createIfNotExists();
// Create a permissions object
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// Include public access in the permissions object
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
// Set the permissions on the container
container.uploadPermissions(containerPermissions);
// Create or overwrite the "myimage.jpg" blob with contents from a local file
CloudBlockBlob blob = container.getBlockBlobReference("myimageYdolo.jpg");
File source = new File(currImageURI.toString());
blob.upload(new FileInputStream(source), source.length());
Here is the error i have got:
08-16 14:48:15.045: W/dalvikvm(5579): VFY: unable to find exception handler at addr 0x2b
08-16 14:48:15.045: W/dalvikvm(5579): VFY: rejected Lcom/microsoft/azure/storage/ServiceClient;.uploadServicePropertiesImpl (Lcom/microsoft/azure/storage/ServiceProperties;Lcom/microsoft/azure/storage/RequestOptions;Lcom/microsoft/azure/storage/OperationContext;Z)Lcom/microsoft/azure/storage/core/StorageRequest;
08-16 14:48:15.045: W/dalvikvm(5579): VFY: rejecting opcode 0x0d at 0x002b
08-16 14:48:15.045: W/dalvikvm(5579): VFY: rejected Lcom/microsoft/azure/storage/ServiceClient;.uploadServicePropertiesImpl (Lcom/microsoft/azure/storage/ServiceProperties;Lcom/microsoft/azure/storage/RequestOptions;Lcom/microsoft/azure/storage/OperationContext;Z)Lcom/microsoft/azure/storage/core/StorageRequest;
08-16 14:48:15.045: W/dalvikvm(5579): Verifier rejected class Lcom/microsoft/azure/storage/ServiceClient;
08-16 14:48:15.045: D/AndroidRuntime(5579): Shutting down VM
08-16 14:48:15.045: W/dalvikvm(5579): threadid=1: thread exiting with uncaught exception (group=0x41dc6ba8)
08-16 14:48:15.045: E/AndroidRuntime(5579): FATAL EXCEPTION: main
08-16 14:48:15.045: E/AndroidRuntime(5579): Process: com.example.azuretry, PID: 5579
08-16 14:48:15.045: E/AndroidRuntime(5579): java.lang.VerifyError: com/microsoft/azure/storage/ServiceClient
08-16 14:48:15.045: E/AndroidRuntime(5579): at com.microsoft.azure.storage.CloudStorageAccount.createCloudBlobClient(CloudStorageAccount.java:715)
08-16 14:48:15.045: E/AndroidRuntime(5579): at com.example.azuretry.FullscreenActivity.onActivityResult(FullscreenActivity.java:144)
08-16 14:48:15.045: E/AndroidRuntime(5579): at android.app.Activity.dispatchActivityResult(Activity.java:5423)
08-16 14:48:15.045: E/AndroidRuntime(5579): at android.app.ActivityThread.deliverResults(ActivityThread.java:3347)
08-16 14:48:15.045: E/AndroidRuntime(5579): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3394)
08-16 14:48:15.045: E/AndroidRuntime(5579): at android.app.ActivityThread.access$1300(ActivityThread.java:135)
08-16 14:48:15.045: E/AndroidRuntime(5579): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
08-16 14:48:15.045: E/AndroidRuntime(5579): at android.os.Handler.dispatchMessage(Handler.java:102)
08-16 14:48:15.045: E/AndroidRuntime(5579): at android.os.Looper.loop(Looper.java:136)
08-16 14:48:15.045: E/AndroidRuntime(5579): at android.app.ActivityThread.main(ActivityThread.java:5001)
08-16 14:48:15.045: E/AndroidRuntime(5579): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 14:48:15.045: E/AndroidRuntime(5579): at java.lang.reflect.Method.invoke(Method.java:515)
08-16 14:48:15.045: E/AndroidRuntime(5579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
08-16 14:48:15.045: E/AndroidRuntime(5579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
08-16 14:48:15.045: E/AndroidRuntime(5579): at dalvik.system.NativeStart.main(Native Method)
I had an identical issue, it is most likely the dependency that you are using. Utilizing the library below resolves the issue for Android App development.
Once I used this everything worked.
https://github.com/Azure/azure-storage-android
dependencies {
compile 'com.microsoft.azure.android:azure-storage-android:0.3.0#aar'
}

Using tablet layout folders is crashing my app

I m making an app which has different layouts for phones and tablets. For the tablet layouts I use the folders layout-sw600, layout-sw600-land, layout-sw720 and layout-sw720-land. But when I open the app on a tablet or on an avd tablet it crashes instantly. When I run it on phones the layouts work normally. What could be the problem ? Do I have to specify something in the manifest ? Please help.
I paste the logcat errors:
08-16 22:30:13.124: W/dalvikvm(894): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
08-16 22:30:13.234: E/AndroidRuntime(894): FATAL EXCEPTION: main
08-16 22:30:13.234: E/AndroidRuntime(894): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mreprogramming.ultimateentitydetector/com.mreprogramming.ultimateentitydetector.MainActivity}: android.view.InflateException: Binary XML file line #153: Error inflating class <unknown>
08-16 22:30:13.234: E/AndroidRuntime(894): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.os.Looper.loop(Looper.java:137)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-16 22:30:13.234: E/AndroidRuntime(894): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 22:30:13.234: E/AndroidRuntime(894): at java.lang.reflect.Method.invoke(Method.java:511)
08-16 22:30:13.234: E/AndroidRuntime(894): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-16 22:30:13.234: E/AndroidRuntime(894): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-16 22:30:13.234: E/AndroidRuntime(894): at dalvik.system.NativeStart.main(Native Method)
08-16 22:30:13.234: E/AndroidRuntime(894): Caused by: android.view.InflateException: Binary XML file line #153: Error inflating class <unknown>
08-16 22:30:13.234: E/AndroidRuntime(894): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
08-16 22:30:13.234: E/AndroidRuntime(894): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-16 22:30:13.234: E/AndroidRuntime(894): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.app.Activity.setContentView(Activity.java:1881)
08-16 22:30:13.234: E/AndroidRuntime(894): at com.mreprogramming.ultimateentitydetector.MainActivity.onCreate(MainActivity.java:45)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.app.Activity.performCreate(Activity.java:5104)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-16 22:30:13.234: E/AndroidRuntime(894): ... 11 more
08-16 22:30:13.234: E/AndroidRuntime(894): Caused by: java.lang.reflect.InvocationTargetException
08-16 22:30:13.234: E/AndroidRuntime(894): at java.lang.reflect.Constructor.constructNative(Native Method)
08-16 22:30:13.234: E/AndroidRuntime(894): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
08-16 22:30:13.234: E/AndroidRuntime(894): ... 24 more
08-16 22:30:13.234: E/AndroidRuntime(894): Caused by: java.lang.OutOfMemoryError
08-16 22:30:13.234: E/AndroidRuntime(894): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.content.res.Resources.loadDrawable(Resources.java:1965)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.view.View.<init>(View.java:3330)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.widget.ImageView.<init>(ImageView.java:114)
08-16 22:30:13.234: E/AndroidRuntime(894): at android.widget.ImageView.<init>(ImageView.java:110)
08-16 22:30:13.234: E/AndroidRuntime(894): ... 27 more
08-16 22:30:13.694: D/dalvikvm(894): GC_CONCURRENT freed 13634K, 85% free 2497K/16280K, paused 83ms+57ms, total 370ms
08-16 22:30:17.614: I/Process(894): Sending signal. PID: 894 SIG: 9
This is the layout for tablets. Its all drawables.
What could be the problem ?
You are running out of memory:
08-16 22:30:13.234: E/AndroidRuntime(894): Caused by: java.lang.OutOfMemoryError
This specific OutOfMemoryError is caused by loading a drawable resource, perhaps as a background of something in your layout.
For whatever reason, the environment you are testing on has only allocated 16MB of heap space for your process, which is rather low by modern standards. Tablets should have larger heap sizes, specifically to deal with larger background images. If you are testing on an emulator, make sure that your emulator is realistic (e.g., Android 4.x for a tablet-sized emulator image).

App Getting Crashed in version 2.2

I create an android App which works perfectly in Android 2.3+ all devices. But when i tried to run in 2.2 but it crashed and gives error in log as,
08-16 10:22:41.323: E/dalvikvm(442): Could not find class 'android.os.StrictMode$ThreadPolicy$Builder', referenced from method com.uks.android.mssga.activity.LoginActivity.onCreate
08-16 10:22:41.333: W/dalvikvm(442): VFY: unable to resolve new-instance 39 (Landroid/os/StrictMode$ThreadPolicy$Builder;) in Lcom/uks/android/mssga/activity/LoginActivity;
08-16 10:22:41.333: D/dalvikvm(442): VFY: replacing opcode 0x22 at 0x000a
08-16 10:22:41.333: D/dalvikvm(442): VFY: dead code 0x000c-009a in Lcom/uks/android/mssga/activity/LoginActivity;.onCreate (Landroid/os/Bundle;)V
08-16 10:22:41.423: D/dalvikvm(442): GC_EXTERNAL_ALLOC freed 744 objects / 59064 bytes in 68ms
08-16 10:22:41.483: D/AndroidRuntime(442): Shutting down VM
08-16 10:22:41.483: W/dalvikvm(442): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-16 10:22:41.483: E/AndroidRuntime(442): FATAL EXCEPTION: main
08-16 10:22:41.483: E/AndroidRuntime(442): java.lang.NoClassDefFoundError: android.os.StrictMode$ThreadPolicy$Builder
08-16 10:22:41.483: E/AndroidRuntime(442): at com.uks.android.mssga.activity.LoginActivity.onCreate(LoginActivity.java:58)
08-16 10:22:41.483: E/AndroidRuntime(442): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-16 10:22:41.483: E/AndroidRuntime(442): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-16 10:22:41.483: E/AndroidRuntime(442): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-16 10:22:41.483: E/AndroidRuntime(442): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-16 10:22:41.483: E/AndroidRuntime(442): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-16 10:22:41.483: E/AndroidRuntime(442): at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 10:22:41.483: E/AndroidRuntime(442): at android.os.Looper.loop(Looper.java:123)
08-16 10:22:41.483: E/AndroidRuntime(442): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-16 10:22:41.483: E/AndroidRuntime(442): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 10:22:41.483: E/AndroidRuntime(442): at java.lang.reflect.Method.invoke(Method.java:521)
08-16 10:22:41.483: E/AndroidRuntime(442): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-16 10:22:41.483: E/AndroidRuntime(442): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-16 10:22:41.483: E/AndroidRuntime(442): at dalvik.system.NativeStart.main(Native Method)
08-16 10:22:44.503: I/Process(442): Sending signal. PID: 442 SIG: 9
Code of LoginActivity is,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
// Other stuff
}
StrictMode.ThreadPolicy.Builder was introduced in Android 2.3 (API level 9), so attempts to call it in versions earlier than that will fail.
To stop it crashing on 2.2 and earlier you can choose to either:
* Remove the ThreadPolicy code (as it is a developer debug tool to provide warnings of bad things you are doing)
or
* Use reflection to determine if the class exists before making use of it

ICS class not found Exception

I had updated my android sdk to ics(4.1) as i updated all my old projects which were developped in froyo(2.3) giving me error Like
08-16 19:16:32.284: E/AndroidRuntime(593): FATAL EXCEPTION: main
08-16 19:16:32.284: E/AndroidRuntime(593): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.abc.def/com.abc.def.defMain}: java.lang.ClassNotFoundException: com.abc.def.defMain in loader dalvik.system.PathClassLoader[/data/app/com.abc.def-1.apk]
08-16 19:16:32.284: E/AndroidRuntime(593): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
08-16 19:16:32.284: E/AndroidRuntime(593): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-16 19:16:32.284: E/AndroidRuntime(593): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-16 19:16:32.284: E/AndroidRuntime(593): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-16 19:16:32.284: E/AndroidRuntime(593): at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 19:16:32.284: E/AndroidRuntime(593): at android.os.Looper.loop(Looper.java:123)
08-16 19:16:32.284: E/AndroidRuntime(593): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-16 19:16:32.284: E/AndroidRuntime(593): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 19:16:32.284: E/AndroidRuntime(593): at java.lang.reflect.Method.invoke(Method.java:521)
08-16 19:16:32.284: E/AndroidRuntime(593): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-16 19:16:32.284: E/AndroidRuntime(593): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-16 19:16:32.284: E/AndroidRuntime(593): at dalvik.system.NativeStart.main(Native Method)
08-16 19:16:32.284: E/AndroidRuntime(593): Caused by: java.lang.ClassNotFoundException: com.abc.def.defMain in loader dalvik.system.PathClassLoader[/data/app/com.abc.def-1.apk]
08-16 19:16:32.284: E/AndroidRuntime(593): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
08-16 19:16:32.284: E/AndroidRuntime(593): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
08-16 19:16:32.284: E/AndroidRuntime(593): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
08-16 19:16:32.284: E/AndroidRuntime(593): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-16 19:16:32.284: E/AndroidRuntime(593): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
08-16 19:16:32.284: E/AndroidRuntime(593): ... 11 more
before updating sdk all of these were running very without any error please help
I got the solution for this Exception this problem was occuring because i was using external libraries in my project and reffering them in build path but in ics the libraries should be contained in libs directory of project so as i copied the libraries in libs problem get solved

error when retrieving a record from the data base?

I'm trying to retrieve a name stred in SQLite table, despite the database has 11 or more records, when I try to retrieve any name from the stored records, The App. Crashs.
Java code:
OnClickListener btn_NavaigateListsner = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (!btn_Save.isEnabled()) {
int c = mpoh.getCurrentRowNumber();
Toast.makeText(getBaseContext(), ""+mpoh.getMP_Name(0), Toast.LENGTH_SHORT).show();
Bundle bundle = new Bundle();
//bundle.putString("name", mpoh.getMP_Name(c));
//bundle.putDouble("lat", mpoh.getMP_Lat(c));
//bundle.putDouble("lng", mpoh.getMP_Lng(c));
//bundle.putString("date", mpoh.getMP_Date(c));
//bundle.putString("time", mpoh.getMP_Time(c));
intent01 = new Intent(MPData.this, MPInfo.class);
intent01.putExtras(bundle);
startActivity(intent01);
}// End of If
}
};
Method that retrieves the stored name:
public String getMP_Name(long id) {
SQLiteDatabase db = this.getReadableDatabase();
SQLiteCursor c = (SQLiteCursor) db.rawQuery("SELECT name FROM MPData WHERE "+
BaseColumns._ID+" = "+
Long.toString(id) +" AND name IS NOT NULL ", null);
c.moveToFirst();
String r = c.getString(0);
c.close();
db.close();
return r;
}
some of LogCat's output:
03-05 12:16:48.288: E/AndroidRuntime(973): FATAL EXCEPTION: main
03-05 12:16:48.288: E/AndroidRuntime(973): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
03-05 12:16:48.288: E/AndroidRuntime(973): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.androidbook.MP.MP_DB.getMP_Name(MP_DB.java:45)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.androidbook.MP.MPData$1.onClick(MPData.java:57)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.view.View.performClick(View.java:2485)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.view.View$PerformClick.run(View.java:9080)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.os.Handler.handleCallback(Handler.java:587)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.os.Handler.dispatchMessage(Handler.java:92)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.os.Looper.loop(Looper.java:130)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 12:16:48.288: E/AndroidRuntime(973): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:16:48.288: E/AndroidRuntime(973): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 12:16:48.288: E/AndroidRuntime(973): at dalvik.system.NativeStart.main(Native Method)
03-05 12:32:19.897: E/AndroidRuntime(1022): FATAL EXCEPTION: main
03-05 12:32:19.897: E/AndroidRuntime(1022): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.androidbook.MP.MP_DB.getMP_Name(MP_DB.java:45)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.androidbook.MP.MPData$1.onClick(MPData.java:57)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.view.View.performClick(View.java:2485)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.view.View$PerformClick.run(View.java:9080)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.os.Handler.handleCallback(Handler.java:587)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.os.Handler.dispatchMessage(Handler.java:92)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.os.Looper.loop(Looper.java:130)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 12:32:19.897: E/AndroidRuntime(1022): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:32:19.897: E/AndroidRuntime(1022): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 12:32:19.897: E/AndroidRuntime(1022): at dalvik.system.NativeStart.main(Native Method)
03-05 12:39:24.627: E/AndroidRuntime(1093): FATAL EXCEPTION: main
03-05 12:39:24.627: E/AndroidRuntime(1093): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.androidbook.MP.MP_DB.getMP_Name(MP_DB.java:45)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.androidbook.MP.MPData$1.onClick(MPData.java:57)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.View.performClick(View.java:2485)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.View.onKeyUp(View.java:4257)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.widget.TextView.onKeyUp(TextView.java:4587)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.KeyEvent.dispatch(KeyEvent.java:1280)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.View.dispatchKeyEvent(View.java:3855)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.os.Looper.loop(Looper.java:130)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 12:39:24.627: E/AndroidRuntime(1093): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:39:24.627: E/AndroidRuntime(1093): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 12:39:24.627: E/AndroidRuntime(1093): at dalvik.system.NativeStart.main(Native Method)
The code looks fine to me. Are you 100% sure you have an entry in your DB with an _id corresponding to 0?
If you call getMP_Name with an invalid _id then the exception will get raised as you posted it.
You should check for this case as follows:
if (c.getCount()==0) return "";
// rest of code
But I wouldn't do it like this anyway because your current implementation of getMP_XXX is very inefficient because you hit the database for each field and each row. You should minimise your number of queries and then iterate over the resulting cursor.
Look at the following line :
String r = c.getString(0);
You are not safe checking your cursor and just assuming a result was recieved.
Check you SQL query and add a safe check for making sure your cursor has retrieved results.

Categories

Resources