开发者

How can I understand Android crash errors and rectify them

开发者 https://www.devze.com 2023-03-23 06:06 出处:网络
This is an example of one of the stack traces, how do I fix my application from this?are there any other tools in google marketplace that help me with this?

This is an example of one of the stack traces, how do I fix my application from this? are there any other tools in google marketplace that help me with this?

java.lang.IllegalStateException: Unknown URL: content://media/external/audio/albumart/-1 at android.os.Parcel.readException(Parcel.java:1255) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114) at android.content.ContentProviderProxy.insert(ContentProviderNative.java:450) at android.content.ContentResolver.insert(ContentResolver.java:587) at com.multi.board.series9button.function2(series9button.java:155) at com.multi.board.series9button.onContextItemSelected(series9button.java:95) at android.app.Activity.onMenuItemSelected(Activity.java:2206) at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2781) at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158) at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855) at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:137) at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:876) at android.widget.AdapterView.performItemClick(AdapterView.java:284) at android.widget.ListView.performItemClick(ListView.java:3382) at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:144) at android.app.ActivityThread.main(ActivityThread.java:4937) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) at dalvik.system.NativeStart.main(Native Method)


EDIT:

I actually called it function 2! what poor programming that is. Here is the function. The problem is I couldn't get this to crash on my phone or any other I tried....

public void function2(int id){
      Toast.makeText(this, "Set as notification",

Toast.LENGTH_SHORT).show(); String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath();

            String path = sdcard + "/multi10/" + Global.currentboard +

"/series9";

                  File k = new File(path, Global.currentsound);

                  ContentValues values = new ContentValues();
                  values.put(MediaStore.MediaColumns.DATA,

k.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, "MultiboardNotif"); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg"); values.put(MediaStore.Audio.Media.ARTIST, "Unknown artist"); values.put(MediaStore.Audio.Media.IS_RINGTONE, false); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false);

                  Uri uri =

MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());

getContentResolver().delete(uri,MediaStore.MediaColumns.TITLE + "=\"" + "MultiboardNotif" +"\"", null); Uri newUri = getContentResolver().insert(uri, values);

                  RingtoneManager.setActualDefaultRingtoneUri(
                    series9button.this,
 开发者_运维技巧                   RingtoneManager.TYPE_NOTIFICATION,
                    newUri);

  }

RESOLVED

Well I now understand how the crash errors work now! and this is how I resolved my issue:

I had a problem on some phones when setting the ringtone as a sound from the directory I store my sounds in on the sdcard.

I add a file to tell the media scanner not to scan the files in my directories and add them to the database.

So to get round this when the set as ringtone/notification/alarm button is pressed I copy the file to a directory on the sdcard called \<sdard>\ringtones or \<sdard>\notifications or \<sdard>\alarms and the code I used previously works fine from that location.


The "Android crash error" you are referring to is actually a JAVA stack trace. Googling for that is sure to bring up a lot of results. Let me give you a few pointers though:

  • such a stack trace is dumped to the error stream when an exception is thrown that is not caught.
  • The first line contains the class name of the exception (in your case java.lang.IllegalStateException) followed by the message of the exception ("Unknown URL: content://media/external/audio/albumart/-1"). This tells you WHAT happened.
  • The rest of the stack trace contains info on WHERE it happened. Since functions call each other, you will see several functions in the reverse order that they were called, one per line. In your example:
    • exception occurred in class android.os.Parcel method readException() in file Parcel.java at line 1255
    • that method was called by android.database.DatabaseUtils method readExceptionFromParcel() in file DatabaseUtils.java at line 160
    • ......

You will most likely be interested in the LATEST (topmost) method call that comes FROM YOUR CODE, since in 99% of the times is what causes the error. in your case, that's com.multi.board.series9button.function2(series9button.java:155) (you interpret that as function2() from the class com.multi.board.series9button line 155).

Good luck!


If you are using eclipse or Netbeans, you can use the built-in debugger. Personally, my method (since that debugger can be not helpful sometimes) is to put "Log.d("FileName","Message about location");" throughout my code. Then follow along with the program in the code and when you get that error, you will know exactly where it is. And then comes the fun of solving it...

0

精彩评论

暂无评论...
验证码 换一张
取 消