title: How can I wait until my retrofit download is successful before invoking other code?
body: <p>In my oncreate</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      eventList = new ArrayList&lt;Event&gt;();
      loadEvents();
      init();
  
  }
  
  public void init() {
  
      recyclerView = (RecyclerView) findViewById(R.id.eventListRV);
      recyclerView.setHasFixedSize(true);
      adapter = new EventAdapter(this, eventList);
      recyclerView.setAdapter(adapter);
      recyclerView.setLayoutManager(new LinearLayoutManager(this));
  }
  
  public void loadEvents() {
      MarvelApi.create(privateKey, publicKey, getApplicationContext(), 5*1024*1024);
  
      EventRequest request = new EventRequest(RequestSignature.create());
      request.setLimit(20);
      request.setOffset(0);
  
      EventManager client = new EventManager();
      client.listCreators(request, new Callback&lt;ServiceResponse&lt;Event&gt;&gt;() {
          @Override
          public void success(ServiceResponse&lt;Event&gt; eventServiceResponse, Response response) {
              eventList.addAll(eventServiceResponse.data.results);
          }
  
          @Override
          public void failure(RetrofitError error) {
              mTV.setText(error.toString());
          }
      });
  
  }
  </code></pre>
  
  <p>Is there a way to wait until my loadEvents() code returns successful and loads the data before calling init()?</p>
  
  <p>Right now I believe my init() code is called before my loadEvents() finishes loading. I want to wait until my loadEvents() is successful and loads all the data before continuing my program.</p>
  
  <p>error log:</p>
  
  <pre><code> 02-18 21:41:19.789  31420-31420/kim.albert.marveleventtracker E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: kim.albert.marveleventtracker, PID: 31420
  java.lang.NullPointerException
          at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:1694)
          at android.view.View.measure(View.java:17387)
          at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
          at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
          at android.view.View.measure(View.java:17387)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
          at android.view.View.measure(View.java:17387)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
          at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:453)
          at android.view.View.measure(View.java:17387)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
          at android.view.View.measure(View.java:17387)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
          at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
          at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
          at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
          at android.view.View.measure(View.java:17387)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
          at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2533)
          at android.view.View.measure(View.java:17387)
          at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2214)
          at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1351)
          at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1550)
          at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1235)
          at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6472)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
          at android.view.Choreographer.doCallbacks(Choreographer.java:603)
          at android.view.Choreographer.doFrame(Choreographer.java:573)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
          at android.os.Handler.handleCallback(Handler.java:733)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:157)
          at android.app.ActivityThread.main(ActivityThread.java:5356)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Also a debug log for when the app runs, but doesn't show anything</p>
  
  <pre><code>02-18 21:53:13.835      686-686/kim.albert.marveleventtracker I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
  02-18 21:53:13.835      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to resolve virtual method 12746: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
  02-18 21:53:13.835      686-686/kim.albert.marveleventtracker D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
  02-18 21:53:13.835      686-686/kim.albert.marveleventtracker I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
  02-18 21:53:13.835      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to resolve virtual method 12752: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
  02-18 21:53:13.835      686-686/kim.albert.marveleventtracker D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
  02-18 21:53:13.835      686-686/kim.albert.marveleventtracker I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
  02-18 21:53:13.835      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to resolve virtual method 9103: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
  02-18 21:53:13.835      686-686/kim.albert.marveleventtracker D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
  02-18 21:53:13.845      686-686/kim.albert.marveleventtracker I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
  02-18 21:53:13.845      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to resolve virtual method 377: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
  02-18 21:53:13.845      686-686/kim.albert.marveleventtracker D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
  02-18 21:53:13.845      686-686/kim.albert.marveleventtracker I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
  02-18 21:53:13.845      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to resolve virtual method 399: Landroid/content/res/TypedArray;.getType (I)I
  02-18 21:53:13.845      686-686/kim.albert.marveleventtracker D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker I/dalvikvm﹕ Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to resolve static method 16973: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x000a
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker I/dalvikvm﹕ Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker W/dalvikvm﹕ VFY: unable to resolve static method 16972: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
  02-18 21:53:13.945      686-686/kim.albert.marveleventtracker D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x000a
  </code></pre>