[Java for Android App Development] Wetzel402:
Issues passing context?

I tried passing my activities context as suggested above. The problem is that I still have a force close with one of my two context dependent cards.

This card works just fine:

public class MyStoryCard extends Card {

public MyStoryCard(final Context c, final String title, final String story,
final String href, final int cardColor) {
super(c, title, story, href, cardColor);
}

[MENTION=439709]override[/MENTION]
public View getCardContent(final Context context) {
final View v = LayoutInflater.from(c)
.inflate(R.layout.story_card, null);

((TextView) v.findViewById(R.id.title_story_card)).setText(title);
((TextView) v.findViewById(R.id.title_story_card)).setTextColor(c
.getResources().getColor(cardColor));
final TextView t = (TextView) v.findViewById(R.id.story_story_card);
t.setText(Html.fromHtml(story + "<br><br>" + "<a href=\"" + href
+ "\">View the original story.</a>"));
final Pattern p = Pattern.compile(href);
Linkify.addLinks(t, p, "http://");
t.setMovementMethod(LinkMovementMethod.getInstance());

return v;
}
}

This card, even though identical in nature, causes a force close on clicking the link:

public class MyStoryVideoCard extends Card {

public MyStoryVideoCard(final Context c, final Bitmap thumb,
final String vidDesc, final String href) {
super(c, thumb, vidDesc, href);
}

[MENTION=439709]override[/MENTION]
public View getCardContent(final Context context) {
final View v = LayoutInflater.from(c).inflate(
R.layout.story_video_card, null);

((ImageView) v.findViewById(R.id.story_video_card_image_view))
.setImageBitmap(thumb);
final TextView t = (TextView) v
.findViewById(R.id.vidDesc_story_video_card);
t.setText(Html.fromHtml(vidDesc + "<br><br>" + "<a href=\"" + href
+ "\">View video.</a>"));
final Pattern p = Pattern.compile(href);
Linkify.addLinks(t, p, "http://");
t.setMovementMethod(LinkMovementMethod.getInstance());

return v;
}
}

Basic implementation of the cards:

if (Headlines.card1 == true) {

Headlines.card1 = false;

final String headlineText1 = EspnJsonParser.map.get("title1");
final String hrefText1 = EspnJsonParser.map.get("href1");
final String descText1 = EspnJsonParser.map.get("description1");
final String hrefVideo1 = EspnJsonParser.map.get("hrefVideo1");
final String storyText1 = EspnJsonParser.map.get("story1");
final String imageCaption1 = EspnJsonParser.map
.get("imageCaption1");
final String vidDesc1 = EspnJsonParser.map.get("vidDesc1");

if (Headlines.video1 == null && Headlines.image1 == null) {
Logger.logDebug(TAG,
"hrefVideo1 & urlText1 = null, displaying no video or picture cards");
Logger.bugSenseAddExtraData(TAG,
"hrefVideo1 & urlText1 = null, displaying no video or picture cards");
mCardView.addCard(new MyStoryCard(Story.this, headlineText1,
descText1, hrefText1, R.color.jays_blue));
mCardView.refresh();
} else if (Headlines.video1 == null && Headlines.image1 != null) {
Logger.logDebug(TAG,
"hrefVideo1 = null, displaying no video card");
Logger.bugSenseAddExtraData(TAG,
"hrefVideo1 = null, displaying no video card");
mCardView.addCard(new MyStoryPictureCard(Headlines.image1,
imageCaption1));
mCardView.addCard(new MyStoryCard(Story.this, headlineText1,
descText1, hrefText1, R.color.jays_blue));
mCardView.refresh();
} else if (Headlines.video1 != null && Headlines.image1 == null) {
Logger.logDebug(TAG,
"urlText1 = null, displaying no picture card");
Logger.bugSenseAddExtraData(TAG,
"urlText1 = null, displaying no picture card");
mCardView.addCard(new MyStoryVideoCard(Story.this,
Headlines.video1, vidDesc1, hrefVideo1));
mCardView.addCard(new MyStoryCard(Story.this, headlineText1,
descText1, hrefText1, R.color.jays_blue));
mCardView.refresh();
} else if (Headlines.video1 != null && Headlines.image1 != null
&& descText1.equalsIgnoreCase(vidDesc1)) {
Logger.logDebug(TAG,
"vidThum & pic are the same, displaying no picture card");
Logger.bugSenseAddExtraData(TAG,
"vidThum & pic are the same, displaying no picture card");
mCardView.addCard(new MyStoryVideoCard(Story.this,
Headlines.video1, vidDesc1, hrefVideo1));
mCardView.addCard(new MyStoryCard(Story.this, headlineText1,
descText1, hrefText1, R.color.jays_blue));
mCardView.refresh();
} else if (Headlines.video1 != null && Headlines.image1 != null) {
Logger.logDebug(TAG, "Displaying all three card types");
Logger.bugSenseAddExtraData(TAG,
"Displaying all three card types");
mCardView.addCard(new MyStoryVideoCard(Story.this,
Headlines.video1, vidDesc1, hrefVideo1));
mCardView.addCard(new MyStoryPictureCard(Headlines.image1,
imageCaption1));
mCardView.addCard(new MyStoryCard(Story.this, headlineText1,
descText1, hrefText1, R.color.jays_blue));
mCardView.refresh();
} else {
Logger.logDebug(TAG,
"final else block hit - displaying story card only");
Logger.bugSenseAddExtraData(TAG,
"final else block hit - displaying story card only");
mCardView.addCard(new MyStoryCard(Story.this, headlineText1,
descText1, hrefText1, R.color.jays_blue));
mCardView.refresh();
}
}

Card.java:

public Card(Context c, String title,String story, String href, int cardColor){
this.c = c;
this.title = title;
this.story = story;
this.cardColor = cardColor;
this.href = href;
}

public Card(Context c, Bitmap thumb, String vidDesc, String href){
this.c = c;
this.thumb = thumb;
this.vidDesc = vidDesc;
this.href = href;
}

AbstractCard.java:

protected Context c;

public Context getActivityContext(){
return c;
}
public Context setActivityContext(Context c){
return this.c = c;
}

My question would be do any seasoned developers see something wrong causing this? You would think with the cards being nearly identical that they would both function the same but obviously the video card is getting the wrong context even though I am trying to pass it directly.

Thank you so much everyone!

Edit:

Logcat:

08-26 12:23:24.790: E/InputEventReceiver(13708): Exception dispatching input event.
08-26 12:23:24.790: E/MessageQueue-JNI(13708): Exception in MessageQueue callback: handleReceiveCallback
08-26 12:23:24.870: E/MessageQueue-JNI(13708): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat= (has extras) }
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.app.Activity.startActivityForResult(Activity.java:3351)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.app.Activity.startActivityForResult(Activity.java:3312)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.app.Activity.startActivity(Activity.java:3522)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.app.Activity.startActivity(Activity.java:3490)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.text.style.URLSpan.onClick(URLSpan.java:62)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.widget.TextView.onTouchEvent(TextView.java:7383)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.View.dispatchTouchEvent(View.java:7127)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2212)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1398)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2160)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.View.dispatchPointerEvent(View.java:7307)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4155)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4134)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4226)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.os.MessageQueue.nativePollOnce(Native Method)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.os.MessageQueue.next(MessageQueue.java:125)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.os.Looper.loop(Looper.java:124)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at android.app.ActivityThread.main(ActivityThread.java:4931)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at java.lang.reflect.Method.invokeNative(Native Method)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at java.lang.reflect.Method.invoke(Method.java:511)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:110)
08-26 12:23:24.870: E/MessageQueue-JNI(13708):	at dalvik.system.NativeStart.main(Native Method)
08-26 12:23:24.870: D/AndroidRuntime(13708): Shutting down VM
08-26 12:23:24.870: W/dalvikvm(13708): threadid=1: thread exiting with uncaught exception (group=0x4175a300)
08-26 12:23:24.880: E/AndroidRuntime(13708): FATAL EXCEPTION: main
08-26 12:23:24.880: E/AndroidRuntime(13708): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat= (has extras) }
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.app.Activity.startActivityForResult(Activity.java:3351)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.app.Activity.startActivityForResult(Activity.java:3312)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.app.Activity.startActivity(Activity.java:3522)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.app.Activity.startActivity(Activity.java:3490)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.text.style.URLSpan.onClick(URLSpan.java:62)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.widget.TextView.onTouchEvent(TextView.java:7383)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.View.dispatchTouchEvent(View.java:7127)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2212)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1398)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2160)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.View.dispatchPointerEvent(View.java:7307)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4155)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4134)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4226)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.os.MessageQueue.nativePollOnce(Native Method)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.os.MessageQueue.next(MessageQueue.java:125)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.os.Looper.loop(Looper.java:124)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at android.app.ActivityThread.main(ActivityThread.java:4931)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at java.lang.reflect.Method.invokeNative(Native Method)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at java.lang.reflect.Method.invoke(Method.java:511)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:110)
08-26 12:23:24.880: E/AndroidRuntime(13708):	at dalvik.system.NativeStart.main(Native Method)