我收到此错误:
IllegalArgumentException
同时执行以下方法。我不知道为什么会这样。
知道这里怎么了吗??
public void sendNoteWithoutImage(){
Toast.makeText(getContext(), "Step 1", Toast.LENGTH_LONG).show();
// saving objects
Note notesRealmClass = new Note();
notesRealmClass.setTitle(titleStr);
Toast.makeText(getContext(), "Step 2", Toast.LENGTH_LONG).show();
ChannelIDs = TextUtils.join(" ",selectedItems);
Toast.makeText(getContext(), "Step 3", Toast.LENGTH_LONG).show();
notesRealmClass.setObjId(objId);
Toast.makeText(getContext(), "Step 4", Toast.LENGTH_LONG).show();
// save object asynchronously
Backendless.Persistence.save(notesRealmClass, new AsyncCallback<Note>() {
public void handleResponse(Note note) {
Toast.makeText(getContext(), "Step 5", Toast.LENGTH_LONG).show();
// new Contact instance has been saved
Toast.makeText(getActivity(), "Successfully posted ", Toast.LENGTH_SHORT).show();
}
public void handleFault(BackendlessFault fault) {
Toast.makeText(getContext(), "Step 6", Toast.LENGTH_LONG).show();
Log.d("ERROR : ", "" + fault.getMessage());
Log.d("ERROR Code: ",""+fault.getCode());
Toast.makeText(getActivity(), "" + fault.getMessage(), Toast.LENGTH_SHORT).show();
// an error has occurred, the error code can be retrieved with fault.getCode()
}
});}
如您所见,我放入编号的烤面包来检查代码的哪些部分正在执行。从第1步到第4步,一切都很好,但在第5步中却没有。在第6步中我直接遇到错误,错误的输出是:
02-18 12:54:09.025 25161-25161/pb.package D/ERROR :: rx/Observable
02-18 12:54:09.025 25161-25161/pb.package D/ERROR Code:: IllegalArgumentException
最佳答案
您的问题应该是在AsyncCallBack中创建Toast时。因为您在匿名类AsyncCallBack中使用它,所以您不能简单地调用getContext或getActivity,因为您不再处于Activity的范围内。尝试这个:
Toast.makeText(NameOfYourActivityClass.this, "Successfully posted ", Toast.LENGTH_SHORT).show();
例如,假设您的活动称为“ NotesActivity”,则可以这样做:
Toast.makeText(NotesActivity.this, "Successfully posted ", Toast.LENGTH_SHORT).show();
关于java - 扩展RealmObject的类的IllegalArgumentException(java),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35475415/