I started off with the notepad example on the android website. What I did was add another table to the database and make it accessible in the NotePad
class (added another inner class called Table
that extended BaseColumns
). It appears the database is being read correctly, and I can launch my view directly. However, when I try to launch it the same way google launches NoteEditor
(via the ACTION_INSERT
intent), the application crashes.
I have an updated URI for the new table, and the intent filter for the activity I want to launch is in the manifest (with the proper mimetype). However, it seems to not be able to find and launch the activity I want.
Here's the output that is relevant:
02-04 01:13:54.964: DEBUG/AndroidRuntime(342): Shutting down VM
02-04 01:13:54.964: WARN/dalvikvm(342): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): FATAL EXCEPTION: main
**02-04 01:13:54.984: ERROR/AndroidRuntime(342): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT dat=content://com.google.provider.NotePad/courses }**
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.app.Activity.startActivityForResult(Activity.java:2827)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.app.Activity.startActivity(Activity.java:2933)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at com.example.android.notepad.CoursesList.onOptionsItemSelected(CoursesList.java:154)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.app.Activity.onMenuItemSelected(Activity.java:2205)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:748)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.view.View$PerformClick.run(View.java:9080)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.os.Handler.handleCallback(Handler.java:587)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.os.Handler.dispatchMessage(Handler.java:92)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.os.Looper.loop(Looper.java:123)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at android.app.ActivityThread.main(ActivityThread.java:3647)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at java.lang.reflect.Method.invoke(Method.java:507)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-04 01:13:54.984: ERROR/AndroidRuntime(342): at dalvik.system.NativeStart.main(Native Method)
02-04 01:13:55.014: WARN/ActivityManager(61): Force finishing activity com.example.android.notepad/.CoursesList
I have the intent-filter in my manifest:
<activity android:name="AddCourseView"
android:theme="@android:style/Theme.Light"
android:label="@string/title_note"
android:screenOrientation="sensor"
android:configChanges="keyboardHidden|orientation"
>
<!-- This filter says that we can view or edit the data of
a single note -->
<intent-filter android:label="@string/resolve_course_edit">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="com.android.notepad.action.EDIT_COURSE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.google.course" />
</intent-filter>
<!-- This filter says that we can create a new note inside
of a directory of notes. -->
<intent-filter>
<action android:name="android.intent.action.INSERT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/vnd.google.course" />
</intent-filter>
</activity>
here is the code where the intent gets launched:
Uri intentUri = getIntent().getData();
Intent intent = new Intent(Intent.ACTION_INSERT, intentUri );
startActivity( intent );
getType() method in NotePadProvider:
@Override
public String getType(Uri uri) {
switch (sUriMatcher.match(uri)) {
case NOTES:
case LIVE_FOLDER_NOTES:
return Notes.CONTENT_TYPE;
case NOTE_ID:
return Notes.CONTENT_ITEM_TYPE;
case COURSES:
return Courses.CONTENT_TYPE;
case COURSE_ID:
return Courses.CONTENT_ITEM_TYPE;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
}
here is where i define the types:
public final class NotePad { public static final String AUTHORITY = "com.google.provider.NotePad";
// This class cannot be instantiated
private NotePad() {}
/**
* Notes table
*/
public static final class Notes implements BaseColumns {
// This class cannot be instantiated
private Notes() {}
/**
* The content:// style URL for this table
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/notes");
/**
* The MIME type of {@link #CONTENT_URI} providing a directory of notes.
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.note";
/**
* The MIME type of a {@link #CONTENT_URI} sub-directory of a single note.
*/
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.google.note";
/**
* The default sort order for this table
*/
public static final String DEFAULT_SORT_ORDER = "modified DESC";
/**
* The title of the note
* <P>Type: TEXT</P>
*/
public static final String TITLE = "title";
/**
* The note itself
* <P>Type: TEXT</P>
*/
public static final String NOTE = "note";
/**
* The task content
开发者_开发百科 * <P>Type: TEXT</P>
*/
public static final String TASK_DESCRIPTION = "description";
/**
* The task location
* <P>Type: TEXT</P>
*/
public static final String TASK_LOCATION = "location";
/**
* The task start time
* as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC
*/
public static final String TASK_START_TIME = "starttime";
/**
* The task end time
* as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC
*/
public static final String TASK_END_TIME = "endtime";
/**
* The timestamp for when the note was created
* <P>Type: INTEGER (long from System.curentTimeMillis())</P>
*/
public static final String CREATED_DATE = "created";
/**
* The timestamp for when the note was last modified
* <P>Type: INTEGER (long from System.curentTimeMillis())</P>
*/
public static final String MODIFIED_DATE = "modified";
/**
* if it is an assignment/test, the weight of it is here
*/
public static final String WEIGHT = "weight";
/**
* the course the note is assigned to
*/
public static final String RELATED_COURSE = "relatedcourse";
}
/**
* Courses table
*/
public static final class Courses implements BaseColumns {
// This class cannot be instantiated
private Courses() {}
/**
* The content:// style URL for this table
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/courses");
/**
* The MIME type of {@link #CONTENT_URI} providing a directory of notes.
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.course";
/**
* The MIME type of a {@link #CONTENT_URI} sub-directory of a single note.
*/
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.google.course";
/**
* The default sort order for this table
*/
public static final String DEFAULT_SORT_ORDER = "modified DESC";
/**
* The title of the note
* <P>Type: TEXT</P>
*/
public static final String TITLE = "title";
public static final String PROFESSOR = "professor";
public static final String DESCRIPTION = "description";
/**
* The timestamp for when the note was created
* <P>Type: INTEGER (long from System.curentTimeMillis())</P>
*/
public static final String CREATED_DATE = "created";
/**
* The timestamp for when the note was last modified
* <P>Type: INTEGER (long from System.curentTimeMillis())</P>
*/
public static final String MODIFIED_DATE = "modified";
}
}
here is the provider part of the manifest:
<provider android:name="NotePadProvider"
android:authorities="com.google.provider.NotePad"/>
ok, i changed the intent launch to this:
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(Courses.CONTENT_TYPE);
startActivity(intent);
so there should be no confusion on the type. and now i get this error:
02-06 22:48:26.076: ERROR/AndroidRuntime(640): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.notepad/com.example.android.notepad.AddCourseView}: java.lang.NullPointerException
I would has at a guess you have a problem with your intent.
Edit:
Please post the provider part of your manifest :)
Edit 2:
com.example.android.notepad.AddCourseView doesn't exist.
Is the package path correct? Is the class name correct? Does AddCourseView extend Activity?
Feel free to mark me down... 2 more and I can delete the post and get a badge...
Your activity responds to intents with content type "vnd.android.cursor.item/vnd.google.course" only. Probably your content provider does not provide this content type (in getType() method) for this URI: content://com.google.provider.NotePad/courses.
OK, your question is very good but it misses some pieces of information.
First of all, here is the intent:
act=android.intent.action.INSERT dat=content://com.google.provider.NotePad/courses
so the action is correct but data seems to be incorrect. You have set the data to the Uri of the items but you have to set it to the content type which is vnd.android.cursor.dir/vnd.google.course
. Doing that, it will open the activity.
I fixed this problem by adding the activity in the manifest, however put the exact case sensitive class name with package information as well.
e.g: com.faceworld.galleryActivity
精彩评论