android - Getting a callback error -


when try run app particular activity:-

package com.justforyou.bestnarutosongs;  import android.content.context; import android.media.audiomanager; import android.media.mediaplayer; import android.os.bundle; import android.os.handler; import android.support.v7.app.appcompatactivity; import android.view.view; import android.view.windowmanager; import android.widget.adapterview; import android.widget.imagebutton; import android.widget.imageview; import android.widget.listview; import android.widget.seekbar; import android.widget.textview;  import java.util.arraylist;  public class songslistactivity extends appcompatactivity //implements view.onclicklistener {  public imagebutton p_and_p = (imagebutton) findviewbyid(r.id.p_and_p); public  imagebutton stop = (imagebutton) findviewbyid(r.id.imagebutton5); public textview named = (textview) findviewbyid(r.id.textview3); public textview rated = (textview) findviewbyid(r.id.textview4); public seekbar seek_bar = (seekbar) findviewbyid(r.id.seekbar); public boolean ispaused = false; public int old_song = -326523; private mediaplayer mediaplayer; private audiomanager maudiomanager; public handler seekhandler = new handler ();   private audiomanager.onaudiofocuschangelistener monaudiofocuschangelistener = new audiomanager.onaudiofocuschangelistener() {     @override     public void onaudiofocuschange(int focuschange){         if(focuschange == audiomanager.audiofocus_loss_transient_can_duck || focuschange == audiomanager.audiofocus_loss_transient){             mediaplayer.pause();             mediaplayer.seekto(0);         }         else if(focuschange == audiomanager.audiofocus_gain){             mediaplayer.start();         }         else if(focuschange == audiomanager.audiofocus_loss){             if(mediaplayer != null)             {                 mediaplayer.release();                 mediaplayer = null;             }         }     } };  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);     setcontentview(r.layout.activity_songs_list);     seekupdation();      maudiomanager = (audiomanager) getsystemservice(context.audio_service);      final arraylist<songs> song = new arraylist<>();     song.add(new songs("anger", "rate: 4.5", r.raw.anger, r.drawable.anger ));     song.add(new songs("daylight of konoha", "rate: 4.7", r.raw.d_o_k, r.drawable.d_o_k ));     song.add(new songs("experienced many battles", "rate: 4.0", r.raw.experienced_many_battles, r.drawable.e_m_b ));     song.add(new songs("gekiha", "rate: 4.0", r.raw.gekiha, r.drawable.gekiha ));     song.add(new songs("genshi", "rate: 3.0", r.raw.genshi, r.drawable.genshi ));     song.add(new songs("girei", "rate: 4.5", r.raw.girei, r.drawable.girei ));     song.add(new songs("hidan", "rate: 3.0", r.raw.hidan, r.drawable.hidan ));     song.add(new songs("homecoming", "rate: 3.0", r.raw.homecoming, r.drawable.homecoming ));     song.add(new songs("naruto main theme", "rate: 5.0", r.raw.naruto_main_theme, r.drawable.narutomt ));     song.add(new songs("saika", "rate: 4.5", r.raw.saika, r.drawable.saika ));     song.add(new songs("senya(itachi's theme)", "rate: 5.0", r.raw.senya, r.drawable.senya ));     song.add(new songs("shirotsumekusa", "rate: 3.0", r.raw.shirotsumekusa, r.drawable.shirot ));     song.add(new songs("turn over", "rate: 4.5", r.raw.turn_over, r.drawable.turn_over ));      p_and_p.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view)         {             if(mediaplayer != null)             {                if(!mediaplayer.isplaying() || ispaused)                {                    p_and_p.setimageresource(r.drawable.ic_play_arrow_white_48dp);                    ispaused = false;                    int result = maudiomanager.requestaudiofocus(monaudiofocuschangelistener, audiomanager.stream_music, audiomanager.audiofocus_gain_transient);                     if (result == audiomanager.audiofocus_request_granted) {                        mediaplayer.start();                        mediaplayer.setoncompletionlistener(new mediaplayer.oncompletionlistener() {                            @override                            public void oncompletion(mediaplayer mediaplayer) {                                if (mediaplayer != null) {                                    mediaplayer.release();                                    mediaplayer = null;                                    maudiomanager.abandonaudiofocus(monaudiofocuschangelistener);                                }                            }                        });                    }                }                 else                {                    p_and_p.setimageresource(r.drawable.ic_pause_white_48dp);////////////////////////////////////////////////////////////////////                    ispaused = true;                    mediaplayer.pause();                }             }          }     });      stop.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             if(mediaplayer != null)             {                 mediaplayer.pause();                 mediaplayer.seekto(0);                 ispaused = true;             }         }     });        songsadapter songadapter = new songsadapter(this, song, r.color.main_color);     listview listview = (listview) findviewbyid(r.id.list_col);     listview.setadapter(songadapter);         listview.setonitemclicklistener             (new adapterview.onitemclicklistener()              {                  @override                  public void onitemclick(adapterview<?> adapterview, view view, int i, long l)                  {                      int current_song;                      songs song = song.get(i);                       //if mediaplayer not used before, make oldsong present song.                      if (old_song == -326523)                      {                          old_song = song.getsong();                      }                       current_song = song.getsong();                       imageview ivp_p = (imageview) findviewbyid(r.id.p_pimage);                        //if mediaplayer paused.                      if (ispaused)                      {                          //if song paused same new song.                          if(current_song == old_song)                          {                              mediaplayer.start();                          }                           //if song paused not new song.                          else                          {                              if (mediaplayer != null)                              {                                  mediaplayer.release();                                  mediaplayer = null;                              }                               int result = maudiomanager.requestaudiofocus(monaudiofocuschangelistener, audiomanager.stream_music, audiomanager.audiofocus_gain_transient);                               if (result == audiomanager.audiofocus_request_granted) {                                  mediaplayer = mediaplayer.create(songslistactivity.this, song.getsong());                                  old_song = song.getsong();                                  mediaplayer.start();                                  mediaplayer.setoncompletionlistener(new mediaplayer.oncompletionlistener() {                                      @override                                      public void oncompletion(mediaplayer mediaplayer) {                                          if (mediaplayer != null) {                                              mediaplayer.release();                                              mediaplayer = null;                                              maudiomanager.abandonaudiofocus(monaudiofocuschangelistener);                                          }                                      }                                  });                              }                          }                          ispaused = false;                       }                       else if (mediaplayer != null)                      {                          //if mediaplayer playing song.                          if (mediaplayer.isplaying()) {                              mediaplayer.pause();                              ivp_p.setimageresource(r.drawable.ic_play_arrow_black_24dp);                              ispaused = true;                          }                      }                       //if mediaplayer used first time , if mediaplayer neither paused                      else                      {                           if (mediaplayer != null)                          {                              mediaplayer.release();                              mediaplayer = null;                          }                           int result = maudiomanager.requestaudiofocus(monaudiofocuschangelistener, audiomanager.stream_music, audiomanager.audiofocus_gain_transient);                           if (result == audiomanager.audiofocus_request_granted) {                              mediaplayer = mediaplayer.create(songslistactivity.this, song.getsong());                              old_song = song.getsong();                              mediaplayer.start();                               mediaplayer.setoncompletionlistener(new mediaplayer.oncompletionlistener() {                                  @override                                  public void oncompletion(mediaplayer mediaplayer) {                                      if (mediaplayer != null) {                                          mediaplayer.release();                                          mediaplayer = null;                                          maudiomanager.abandonaudiofocus(monaudiofocuschangelistener);                                      }                                  }                              });                          }                      }                   }              }             ); }  runnable run = new runnable (){     @override     public void run() {         seekupdation();     } };  public void seekupdation() {     if(mediaplayer != null) {         seek_bar.setprogress(mediaplayer.getcurrentposition());         seekhandler.postdelayed(run, 1000);     }     }  @override protected void onstop() {     super.onstop();     if(mediaplayer != null)     {         mediaplayer.release();         mediaplayer = null;     } } } 

gives error:-

08-08 14:39:41.281 1730-1730/com.justforyou.bestnarutosongs e/androidruntime: fatal exception: main                                                                           process: com.justforyou.bestnarutosongs, pid: 1730                                                                           java.lang.runtimeexception: unable instantiate activity componentinfo{com.justforyou.bestnarutosongs/com.justforyou.bestnarutosongs.songslistactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'android.view.window$callback android.view.window.getcallback()' on null object reference                                                                               @ android.app.activitythread.performlaunchactivity(activitythread.java:2444)                                                                               @ android.app.activitythread.handlelaunchactivity(activitythread.java:2613)                                                                               @ android.app.activitythread.access$800(activitythread.java:181)                                                                               @ android.app.activitythread$h.handlemessage(activitythread.java:1473)                                                                               @ android.os.handler.dispatchmessage(handler.java:111)                                                                               @ android.os.looper.loop(looper.java:194)                                                                               @ android.app.activitythread.main(activitythread.java:5649)                                                                               @ java.lang.reflect.method.invoke(native method)                                                                               @ java.lang.reflect.method.invoke(method.java:372)                                                                               @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:959)                                                                               @ com.android.internal.os.zygoteinit.main(zygoteinit.java:754)                                                                            caused by: java.lang.nullpointerexception: attempt invoke virtual method 'android.view.window$callback android.view.window.getcallback()' on null object reference                                                                               @ android.support.v7.app.appcompatdelegateimplbase.<init>(appcompatdelegateimplbase.java:72)                                                                               @ android.support.v7.app.appcompatdelegateimplv7.<init>(appcompatdelegateimplv7.java:146)                                                                               @ android.support.v7.app.appcompatdelegateimplv11.<init>(appcompatdelegateimplv11.java:28)                                                                               @ android.support.v7.app.appcompatdelegateimplv14.<init>(appcompatdelegateimplv14.java:41)                                                                               @ android.support.v7.app.appcompatdelegate.create(appcompatdelegate.java:193)                                                                               @ android.support.v7.app.appcompatdelegate.create(appcompatdelegate.java:173)                                                                               @ android.support.v7.app.appcompatactivity.getdelegate(appcompatactivity.java:511)                                                                               @ android.support.v7.app.appcompatactivity.findviewbyid(appcompatactivity.java:183)                                                                               @ com.justforyou.bestnarutosongs.songslistactivity.<init>(songslistactivity.java:23)                                                                               @ java.lang.reflect.constructor.newinstance(native method)                                                                               @ java.lang.class.newinstance(class.java:1606)                                                                               @ android.app.instrumentation.newactivity(instrumentation.java:1071)                                                                               @ android.app.activitythread.performlaunchactivity(activitythread.java:2434)                                                                               @ android.app.activitythread.handlelaunchactivity(activitythread.java:2613)                                                                                @ android.app.activitythread.access$800(activitythread.java:181)                                                                                @ android.app.activitythread$h.handlemessage(activitythread.java:1473)                                                                                @ android.os.handler.dispatchmessage(handler.java:111)                                                                                @ android.os.looper.loop(looper.java:194)                                                                                @ android.app.activitythread.main(activitythread.java:5649)                                                                                @ java.lang.reflect.method.invoke(native method)                                                                                @ java.lang.reflect.method.invoke(method.java:372)                                                                                @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:959)                                                                                @ com.android.internal.os.zygoteinit.main(zygoteinit.java:754)  

can tell me, causing error? here xml file :-

<?xml version="1.0" encoding="utf-8"?>  <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent">  <relativelayout     android:layout_width="match_parent"     android:layout_height="0dp"     android:layout_weight="0.58"     android:background="@color/player_color">      <linearlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical">          <linearlayout             android:orientation="horizontal"             android:layout_width="match_parent"             android:layout_height="0dp"             android:layout_weight="2.27">              <linearlayout                 android:orientation="horizontal"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:weightsum="1">                  <imageview                     android:layout_width="100dp"                     android:layout_height="100dp"                     android:id="@+id/imageview" />                  <linearlayout                     android:orientation="vertical"                     android:layout_width="match_parent"                     android:layout_height="match_parent">                      <textview                         android:layout_width="match_parent"                         android:layout_height="0dp"                         android:text="please select song"                         android:textappearance="?android:textappearancemedium"                         android:textstyle="bold"                         android:id="@+id/textview3"                         android:layout_weight="1"                         android:gravity="bottom" />                      <textview                         android:layout_width="match_parent"                         android:layout_height="0dp"                         android:text=""                         android:id="@+id/textview4"                         android:layout_weight="1" />                 </linearlayout>             </linearlayout>         </linearlayout>          <linearlayout             android:orientation="horizontal"             android:layout_width="match_parent"             android:layout_height="0dp"             android:layout_weight="1">              <imagebutton                 android:layout_width="wrap_content"                 android:layout_height="match_parent"                 android:id="@+id/repeat"                 android:layout_weight="1"                 android:background="@color/player_color"                 android:src="@drawable/ic_repeat_white_48dp" />              <imagebutton                 android:layout_width="wrap_content"                 android:layout_height="match_parent"                 android:id="@+id/previous"                 android:layout_weight="1"                 android:background="@color/player_color"                 android:src="@drawable/ic_skip_previous_white_48dp" />              <imagebutton                 android:layout_width="wrap_content"                 android:layout_height="match_parent"                 android:id="@+id/p_and_p"                 android:layout_weight="1"                 android:src="@drawable/ic_play_arrow_white_48dp"                 android:background="@color/player_color" />              <imagebutton                 android:layout_width="wrap_content"                 android:layout_height="match_parent"                 android:id="@+id/next"                 android:layout_weight="1"                 android:background="@color/player_color"                 android:src="@drawable/ic_skip_next_white_48dp" />              <relativelayout                 android:layout_width="wrap_content"                 android:layout_height="match_parent">                  <imagebutton                     android:padding="11dp"                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:id="@+id/imagebutton5"                     android:background="@color/player_color"                     android:src="@drawable/control_stop"                     android:scaletype="centerinside"                     android:layout_centervertical="true"                     android:layout_alignparentstart="true" />              </relativelayout>          </linearlayout>          <linearlayout             android:orientation="horizontal"             android:layout_width="match_parent"             android:layout_height="0dp"             android:layout_weight="1">              <linearlayout                 android:orientation="horizontal"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:weightsum="1"                 android:gravity="center_vertical">                  <textview                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:text="00:00"                     android:id="@+id/textview"                     android:gravity="center_vertical" />                   <seekbar                     android:layout_width="0dp"                     android:layout_height="wrap_content"                     android:id="@+id/seekbar"                     android:layout_weight="1" />                  <textview                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:text="00:00"                     android:id="@+id/textview2"                     android:gravity="center_vertical" />             </linearlayout>         </linearlayout>     </linearlayout>  </relativelayout>   <listview     android:id="@+id/list_col"     android:layout_width="match_parent"     android:layout_height="0dp"     android:layout_weight="1"     android:layout_gravity="bottom"     android:drawselectorontop="true"     android:orientation="vertical"     tools:context="com.justforyou.bestnarutosongs.songslistactivity"     style="centrecrop" /> 

while rendering xml file, gives me error:-

error image

are these 2 errors related or not. best solution problem? appreciated.

you should put snippet

public imagebutton p_and_p = (imagebutton) findviewbyid(r.id.p_and_p); public  imagebutton stop = (imagebutton) findviewbyid(r.id.imagebutton5); public textview named = (textview) findviewbyid(r.id.textview3); public textview rated = (textview) findviewbyid(r.id.textview4); public seekbar seek_bar = (seekbar) findviewbyid(r.id.seekbar); 

in oncreate() under :setcontentview(r.layout.activity_songs_list);


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -