0

I'm new in coding. I want to add a myObjectChild to a static list that is declared in the class of MyObjectChild. I get an error when trying to add to the static list, but it works fine to add the same object to a list declared in the method. I don't know what's wrong. I want to add the object to the static list. I created the list in the method only to test if the problem was with the object or with the adding to the static list and it seems that the problem is when adding to the static list. Can someone help me?? Here is my code:

public class MyObjectChild extends MyObject {

 int id;
 String name;
 static List <MyObject> staticList = new ArrayList<>(); 
 static String jsonStaticList = null;



   @Override
   public void addToList ()  {

     List<MyObject> list = new ArrayList<>();

     try {
         list.add(this); // this works when running the app
         }  catch (Exception e){
            Log.e("error", "Didn’t add MyObject to the methodList ");  }

     try {
         staticList.add(this); // this doesn't work when running the app
         }  catch (Exception e){
              e.printStackTrace(); } //got this message: E/ViewRootImpl﹕ sendUserActionEvent() mView == null 
}
Ulla
  • 70
  • 9
  • 1
    what are the errors? – John Joe Jul 26 '17 at 02:55
  • it simply doesn't add the object to the static list and goes to catch Exception e. – Ulla Jul 26 '17 at 03:00
  • 1
    use `e.printStackTrace()` in catch block to get the error messages. – John Joe Jul 26 '17 at 03:01
  • The code you posted, once corrected, e.g. for `String` instead of `string`, does not throw any exceptions at all. – user207421 Jul 26 '17 at 03:22
  • @John Joe - using the e.printStackTrace() I got this error message: E/ViewRootImpl﹕ sendUserActionEvent() mView == null. - but only when trying to add the object to the staticList. full stackTrace: 07-26 01:28:55.810 1608-1608/com.ullaapps.calculaprazocpc E/ViewRootImpl﹕ sendUserActionEvent() mView == null – Ulla Jul 26 '17 at 04:31
  • 1
    Please edit your post by adding full stackTrace. – John Joe Jul 26 '17 at 04:32
  • the full stackTrace is: 07-26 01:54:59.855 30911-30911/com.ullaapps.calculaprazocpc E/ViewRootImpl﹕ sendUserActionEvent() mView == null – Ulla Jul 26 '17 at 04:58
  • That is not a stack trace, and it is not edited into your question, and `mView == null` has nothing to do with this code whatsoever. – user207421 Jul 26 '17 at 05:01
  • i' reading some posts that says that's a bug that occurs when running apps in Samsung devices https://stackoverflow.com/questions/18028666/senduseractionevent-is-null - I haven't another device to test it now. So I will try it later and see if that's the problem. Doesn't make much sense, but can be. My code is more extense thant that , but the problem is exactly in this part. Thanx for you trying to help . – Ulla Jul 26 '17 at 06:08
  • Err, no. You clearly do have an `mView == null` problem but it doesn't have anything to do with this code. – user207421 Jul 26 '17 at 08:03
  • Editing your title is fine, but you were asked for the complete stack trace 24 hours ago, and several times since. Where is it? At present there is *no evidence* of a problem in this code. – user207421 Jul 27 '17 at 04:56
  • I'm new in coding. Do it as a hobby, I don't understand what you mean with the complete stack trace?? Is that whats comes before and after..like this : :07-27 02:01:42.290 582-582/com.ullaapps.calculaprazocpc D/AbsListView﹕ unregisterIRListener() is called 07-27 02:01:42.295 582-582/com.ullaapps.calculaprazocpc E/ViewRootImpl﹕ sendUserActionEvent() mView == null 07-27 02:01:44.450 582-582/com.ullaapps.calculaprazocpc D/dalvikvm﹕ GC_FOR_ALLOC freed 322K, 12% free 11930K/13408K, paused 23ms, total 23ms ... ?? – Ulla Jul 27 '17 at 05:16
  • It is the result of calling `printStackTrace()`. This seems rather obvious. The stack trace would need to contain a reference to the line of your code that you claim is throwing the exception for your claim to be valid. At present there is nothing to connect them. – user207421 Jul 27 '17 at 05:27
  • well I took a way around and solved my problem changing my code - declaring the List in my activity and it worked as I needed. Was having to much headache with this issue. I will delete this post. I think that it will not help anyone. – Ulla Jul 28 '17 at 03:20

0 Answers0