Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jordan Peterson
5,134 PointsError with adding text messaging to Ribbit app
I'm trying to add text messaging to the Ribbit App. I've made a button in the action bar that takes the user to a new activity. In that activity the user can put text into a editText then when they click on the button they are able to choose a recipient. When the user clicks the recipient then sends the message my app crashes. Is anybody able to help me with this? I am getting this in my logcat:
05-09 12:17:27.149: E/AndroidRuntime(31198): FATAL EXCEPTION: main 05-09 12:17:27.149: E/AndroidRuntime(31198): java.lang.IllegalArgumentException: value may not be null. 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.parse.ParseObject.performPut(ParseObject.java:2733) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.parse.ParseObject.put(ParseObject.java:2724) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.jordanpeterson.textly.ui.RecipientsActivity.createMessage(RecipientsActivity.java:178) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.jordanpeterson.textly.ui.RecipientsActivity.onOptionsItemSelected(RecipientsActivity.java:153) 05-09 12:17:27.149: E/AndroidRuntime(31198): at android.app.Activity.onMenuItemSelected(Activity.java:2508) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:956) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:163) 05-09 12:17:27.149: E/AndroidRuntime(31198): at android.widget.AdapterView.performItemClick(AdapterView.java:292) 05-09 12:17:27.149: E/AndroidRuntime(31198): at android.widget.AbsListView.performItemClick(AbsListView.java:1058) 05-09 12:17:27.149: E/AndroidRuntime(31198): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514) 05-09 12:17:27.149: E/AndroidRuntime(31198): at android.widget.AbsListView$1.run(AbsListView.java:3168) 05-09 12:17:27.149: E/AndroidRuntime(31198): at android.os.Handler.handleCallback(Handler.java:605) 05-09 12:17:27.149: E/AndroidRuntime(31198): at android.os.Handler.dispatchMessage(Handler.java:92) 05-09 12:17:27.149: E/AndroidRuntime(31198): at android.os.Looper.loop(Looper.java:137) 05-09 12:17:27.149: E/AndroidRuntime(31198): at android.app.ActivityThread.main(ActivityThread.java:4429) 05-09 12:17:27.149: E/AndroidRuntime(31198): at java.lang.reflect.Method.invokeNative(Native Method) 05-09 12:17:27.149: E/AndroidRuntime(31198): at java.lang.reflect.Method.invoke(Method.java:511) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:3151) 05-09 12:17:27.149: E/AndroidRuntime(31198): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:2918) 05-09 12:17:27.149: E/AndroidRuntime(31198): at dalvik.system.NativeStart.main(Native Method)
This is my createMessage() method from RecipientsActivity:
protected ParseObject createMessage(){ ParseObject message = new ParseObject(ParseConstants.CLASS_MESSAGES); message.put(ParseConstants.KEY_SENDER_ID, ParseUser.getCurrentUser().getObjectId()); message.put(ParseConstants.KEY_SENDER_NAME, ParseUser.getCurrentUser().getUsername()); message.put(ParseConstants.KEY_RECIPIENT_IDS, getRecipientIds());
message.put(ParseConstants.KEY_FILE_TYPE, mFileType);
if (mFileType.equals(ParseConstants.TYPE_TEXT)) {
message.put(ParseConstants.KEY_MESSAGE, mEditMessage);
message.put(ParseConstants.KEY_FILE_TYPE, ParseConstants.TYPE_TEXT);
return message;
}else{
byte[] fileBytes = FileHelper.getByteArrayFromFile(this, mMediaUri);
if (fileBytes == null) {
return null;
}else {
if(mFileType.equals(ParseConstants.TYPE_IMAGE)) {
fileBytes = FileHelper.reduceImageForUpload(fileBytes);
}
String fileName = FileHelper.getFileName(this, mMediaUri, mFileType);
ParseFile file = new ParseFile(fileName, fileBytes);
message.put(ParseConstants.KEY_FILE, file);
return message;
}
}
}