Skip to main content
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
se eliminaron 58 caracteres en el cuerpo
Origen Enlace
Rodrigo
  • 685
  • 1
  • 7
  • 22
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import java.io.IOException;


public class Reproductor extends Activity {
public String urlMediaPlayer ="http://unlimited3="url-
cl.dps.live/cooperativafm/aac/icecast.audio";media";
public MediaPlayer mediaPlayer = new MediaPlayer();


ProgressBar progressBar;
public void onCreate(Bundle savedInstance) {
    System.out.println("Reproductor, onCreate");
    super.onCreate(savedInstance);

    setContentView(R.layout.activity_container);
    this.progressBar = (ProgressBar) findViewById(R.id.fabProgressBar);
    reproduceMedia();
}

    public Reproductor() {
}

public void reproduceMedia()
{
    cargaMedia cmedia = new cargaMedia();
    cmedia.execute();
}

public class cargaMedia extends AsyncTask<Void,Integer,Boolean> {

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }
    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
    @Override
    protected void onPreExecute() {

       progressBar.setVisibility(View.VISIBLE);
    }
    @Override
    protected void onPostExecute(Boolean aBoolean) {
        progressBar.setVisibility(View.INVISIBLE);
    }
    @Override
    protected Boolean doInBackground(Void... params) {

        try{
           mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
           mediaPlayer.setDataSource(urlMediaPlayer);
           mediaPlayer.prepare();
           mediaPlayer.setVolume(1,1);
           mediaPlayer.start();
       }catch (IOException e)

       {
           e.printStackTrace();
       }

           return true;
    }

}

public void pausaMedia() throws IOException{

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(urlMediaPlayer);
    mediaPlayer.setVolume(0,0);
    mediaPlayer.pause();

}
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import java.io.IOException;


public class Reproductor extends Activity {
public String urlMediaPlayer ="http://unlimited3-
cl.dps.live/cooperativafm/aac/icecast.audio";
public MediaPlayer mediaPlayer = new MediaPlayer();


ProgressBar progressBar;
public void onCreate(Bundle savedInstance) {
    System.out.println("Reproductor, onCreate");
    super.onCreate(savedInstance);

    setContentView(R.layout.activity_container);
    this.progressBar = (ProgressBar) findViewById(R.id.fabProgressBar);
    reproduceMedia();
}

    public Reproductor() {
}

public void reproduceMedia()
{
    cargaMedia cmedia = new cargaMedia();
    cmedia.execute();
}

public class cargaMedia extends AsyncTask<Void,Integer,Boolean> {

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }
    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
    @Override
    protected void onPreExecute() {

       progressBar.setVisibility(View.VISIBLE);
    }
    @Override
    protected void onPostExecute(Boolean aBoolean) {
        progressBar.setVisibility(View.INVISIBLE);
    }
    @Override
    protected Boolean doInBackground(Void... params) {

        try{
           mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
           mediaPlayer.setDataSource(urlMediaPlayer);
           mediaPlayer.prepare();
           mediaPlayer.setVolume(1,1);
           mediaPlayer.start();
       }catch (IOException e)

       {
           e.printStackTrace();
       }

           return true;
    }

}

public void pausaMedia() throws IOException{

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(urlMediaPlayer);
    mediaPlayer.setVolume(0,0);
    mediaPlayer.pause();

}
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import java.io.IOException;


public class Reproductor extends Activity {
public String urlMediaPlayer ="url-media";
public MediaPlayer mediaPlayer = new MediaPlayer();


ProgressBar progressBar;
public void onCreate(Bundle savedInstance) {
    System.out.println("Reproductor, onCreate");
    super.onCreate(savedInstance);

    setContentView(R.layout.activity_container);
    this.progressBar = (ProgressBar) findViewById(R.id.fabProgressBar);
    reproduceMedia();
}

    public Reproductor() {
}

public void reproduceMedia()
{
    cargaMedia cmedia = new cargaMedia();
    cmedia.execute();
}

public class cargaMedia extends AsyncTask<Void,Integer,Boolean> {

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }
    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
    @Override
    protected void onPreExecute() {

       progressBar.setVisibility(View.VISIBLE);
    }
    @Override
    protected void onPostExecute(Boolean aBoolean) {
        progressBar.setVisibility(View.INVISIBLE);
    }
    @Override
    protected Boolean doInBackground(Void... params) {

        try{
           mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
           mediaPlayer.setDataSource(urlMediaPlayer);
           mediaPlayer.prepare();
           mediaPlayer.setVolume(1,1);
           mediaPlayer.start();
       }catch (IOException e)

       {
           e.printStackTrace();
       }

           return true;
    }

}

public void pausaMedia() throws IOException{

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(urlMediaPlayer);
    mediaPlayer.setVolume(0,0);
    mediaPlayer.pause();

}
se añadieron 348 caracteres en el cuerpo
Origen Enlace
Rodrigo
  • 685
  • 1
  • 7
  • 22
import android.app.Activity;
import android.contentmedia.Context;AudioManager;
import android.media.AudioManager;MediaPlayer;
import android.mediaos.MediaPlayer;AsyncTask;
import android.os.AsyncTask;Bundle;
import android.view.View;
import android.widget.ProgressBar;
 
import java.io.IOException;


public class Reproductor extends Activity {
  public String urlMediaPlayer ="url="http://unlimited3-media";
  cl.dps.live/cooperativafm/aac/icecast.audio";
public MediaPlayer mediaPlayer = new MediaPlayer(); 


ProgressBar progressBar;
public Contextvoid context;onCreate(Bundle savedInstance) {
  ProgressBar progressBar =System.out.println("Reproductor, onCreate");
    super.onCreate(ProgressBarsavedInstance);

 findViewById   setContentView(R.idlayout.fabProgressBaractivity_container);
 
  public Context getContextthis.progressBar = (ProgressBar) {findViewById(R.id.fabProgressBar);
    return context;reproduceMedia();
  } 

    public Reproductor() {
  }
 

public void reproduceMedia()
{
        cargaMedia cmedia = new cargaMedia();
        cmedia.execute();
}

public class cargaMedia extends AsyncTask<Void,Integer,Boolean> {

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }
    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
    @Override
    protected void onPreExecute() {

       progressBar.setVisibility(View.VISIBLE);
    }
    @Override
    protected void onPostExecute(Boolean aBoolean) {
 
        progressBar.setVisibility(View.INVISIBLE);
    }
    @Override
    protected Boolean doInBackground(Void... params) {

        try{
           mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
           mediaPlayer.setDataSource(urlMediaPlayer);
           mediaPlayer.prepare();
           mediaPlayer.setVolume(1,1);
           mediaPlayer.start();
       }catch (IOException e)

       {
           e.printStackTrace();
       }

           return true;
 
    }

}

 public void pausaMedia() throws IOException{

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(urlMediaPlayer);
    mediaPlayer.setVolume(0,0);
    mediaPlayer.pause();


  }

}

Esta} Esta funcion es llamada desde la clase ContainerActivity, presionando un FloatingActionButton.

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.roughike.bottombar.BottomBar;
import com.roughike.bottombar.OnTabSelectListener;

import cl.cooperativa.readxmlfrominternetmaterial.R;
import cl.cooperativa.readxmlfrominternetmaterial.Reproductor;
import 
cl.cooperativa.readxmlfrominternetmaterial.view.fragment.DeportesFragment;
import 
cl.cooperativa.readxmlfrominternetmaterial.view.fragment.HomeFragment;
import 
cl.cooperativa.readxmlfrominternetmaterial.view.fragment.PoliticaFragment;

public class ContainerActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_container);

    BottomBar bottomBar = (BottomBar) findViewById(R.id.bottonbar);
    bottomBar.setDefaultTab(R.id.portada); 


    HomeFragment homeFragment = new HomeFragment();
    
   
 getSupportFragmentManager().beginTransaction() 
.replace
   (R.id.container,homeFragment)        
         
    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
   .addToBackStack(null).commit();

    FloatingActionButton floatingActionButton = (FloatingActionButton) 
     findViewById(R.id.fab);

   
    floatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

           // Reproductor reproductor = new Reproductor();

           // reproductor.reproduceMedia();

            Intent intent = new Intent(ContainerActivity.this, 
    Reproductor.class);
            startActivity(intent); 

            /*Snackbar.make(view, "Replace with your own action", 
             Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();*/
        }

    });

    bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(@IdRes int tabId) {
    switch (tabId){
        case R.id.portada:
            HomeFragment homeFragment = new HomeFragment(); 

          getSupportFragmentManager().beginTransaction()
         .replace(R.id.container,homeFragment)
                    
         .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
        .addToBackStack(null).commit();
            break;
       case R.id.deportes:
            DeportesFragment deportesFragment = new DeportesFragment();
            getSupportFragmentManager().beginTransaction()
           .replace(R.id.container,deportesFragment)
                            
           .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
           .addToBackStack(null).commit();
            break;
             case R.id.politica:
            PoliticaFragment politicaFragment = new PoliticaFragment();
            getSupportFragmentManager().beginTransaction()
            .replace(R.id.container,politicaFragment)
                    
           .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
           .addToBackStack(null).commit();
            break;
       }
    }
  });

} 


@Override
protected void onPause()
{
    super.onPause();
}
protected void onResume() {

    super.onResume();
}
protected void onDestroy() {
    super.onDestroy();

   }
   }
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ProgressBar;
 
import java.io.IOException;


public class Reproductor extends Activity {
  public String urlMediaPlayer ="url-media";
  public MediaPlayer mediaPlayer = new MediaPlayer();
  Context context;
  ProgressBar progressBar = (ProgressBar) findViewById(R.id.fabProgressBar);
 
  public Context getContext() {
    return context;
  }
    public Reproductor() {
  }
 

public void reproduceMedia()
{
        cargaMedia cmedia = new cargaMedia();
        cmedia.execute();
}

public class cargaMedia extends AsyncTask<Void,Integer,Boolean> {

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }
    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
    @Override
    protected void onPreExecute() {

       progressBar.setVisibility(View.VISIBLE);
    }
    @Override
    protected void onPostExecute(Boolean aBoolean) {
 
       progressBar.setVisibility(View.INVISIBLE);
    }
    @Override
    protected Boolean doInBackground(Void... params) {

        try{
           mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
           mediaPlayer.setDataSource(urlMediaPlayer);
           mediaPlayer.prepare();
           mediaPlayer.setVolume(1,1);
           mediaPlayer.start();
       }catch (IOException e)

       {
           e.printStackTrace();
       }

           return true;
 
    }

}

 public void pausaMedia() throws IOException{

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(urlMediaPlayer);
    mediaPlayer.setVolume(0,0);
    mediaPlayer.pause();


  }

}

Esta funcion es llamada desde la clase ContainerActivity, presionando un FloatingActionButton.

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.roughike.bottombar.BottomBar;
import com.roughike.bottombar.OnTabSelectListener;

import cl.cooperativa.readxmlfrominternetmaterial.R;
import cl.cooperativa.readxmlfrominternetmaterial.Reproductor;
import 
cl.cooperativa.readxmlfrominternetmaterial.view.fragment.DeportesFragment;
import 
cl.cooperativa.readxmlfrominternetmaterial.view.fragment.HomeFragment;
import 
cl.cooperativa.readxmlfrominternetmaterial.view.fragment.PoliticaFragment;

public class ContainerActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_container);

    BottomBar bottomBar = (BottomBar) findViewById(R.id.bottonbar);
    bottomBar.setDefaultTab(R.id.portada);

    HomeFragment homeFragment = new HomeFragment();
    
   getSupportFragmentManager().beginTransaction().replace
   (R.id.container,homeFragment)                
    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
   .addToBackStack(null).commit();

    FloatingActionButton floatingActionButton = (FloatingActionButton) 
    findViewById(R.id.fab);
    floatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Reproductor reproductor = new Reproductor();

            reproductor.reproduceMedia();
            /*Snackbar.make(view, "Replace with your own action", 
             Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();*/
        }

    });

    bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(@IdRes int tabId) {
    switch (tabId){
        case R.id.portada:
            HomeFragment homeFragment = new HomeFragment();
          getSupportFragmentManager().beginTransaction()
         .replace(R.id.container,homeFragment)
                   
        .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
        .addToBackStack(null).commit();
            break;
       case R.id.deportes:
            DeportesFragment deportesFragment = new DeportesFragment();
            getSupportFragmentManager().beginTransaction()
           .replace(R.id.container,deportesFragment)
                            
           .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
           .addToBackStack(null).commit();
            break;
             case R.id.politica:
            PoliticaFragment politicaFragment = new PoliticaFragment();
            getSupportFragmentManager().beginTransaction()
            .replace(R.id.container,politicaFragment)
                    
           .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
           .addToBackStack(null).commit();
            break;
       }
    }
});

}

@Override
protected void onPause()
{
    super.onPause();
}
protected void onResume() {

    super.onResume();
}
protected void onDestroy() {
    super.onDestroy();

   }
   }
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import java.io.IOException;


public class Reproductor extends Activity {
public String urlMediaPlayer ="http://unlimited3-
cl.dps.live/cooperativafm/aac/icecast.audio";
public MediaPlayer mediaPlayer = new MediaPlayer(); 


ProgressBar progressBar;
public void onCreate(Bundle savedInstance) {
    System.out.println("Reproductor, onCreate");
    super.onCreate(savedInstance);

    setContentView(R.layout.activity_container);
    this.progressBar = (ProgressBar) findViewById(R.id.fabProgressBar);
    reproduceMedia();
} 

    public Reproductor() {
}

public void reproduceMedia()
{
    cargaMedia cmedia = new cargaMedia();
    cmedia.execute();
}

public class cargaMedia extends AsyncTask<Void,Integer,Boolean> {

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }
    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
    @Override
    protected void onPreExecute() {

       progressBar.setVisibility(View.VISIBLE);
    }
    @Override
    protected void onPostExecute(Boolean aBoolean) {
        progressBar.setVisibility(View.INVISIBLE);
    }
    @Override
    protected Boolean doInBackground(Void... params) {

        try{
           mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
           mediaPlayer.setDataSource(urlMediaPlayer);
           mediaPlayer.prepare();
           mediaPlayer.setVolume(1,1);
           mediaPlayer.start();
       }catch (IOException e)

       {
           e.printStackTrace();
       }

           return true;
    }

}

public void pausaMedia() throws IOException{

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(urlMediaPlayer);
    mediaPlayer.setVolume(0,0);
    mediaPlayer.pause();

}

} Esta funcion es llamada desde la clase ContainerActivity, presionando un FloatingActionButton.

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.roughike.bottombar.BottomBar;
import com.roughike.bottombar.OnTabSelectListener;

import cl.cooperativa.readxmlfrominternetmaterial.R;
import cl.cooperativa.readxmlfrominternetmaterial.Reproductor;
import 
cl.cooperativa.readxmlfrominternetmaterial.view.fragment.DeportesFragment;
import 
cl.cooperativa.readxmlfrominternetmaterial.view.fragment.HomeFragment;
import 
cl.cooperativa.readxmlfrominternetmaterial.view.fragment.PoliticaFragment;

public class ContainerActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_container);

    BottomBar bottomBar = (BottomBar) findViewById(R.id.bottonbar);
    bottomBar.setDefaultTab(R.id.portada); 


    HomeFragment homeFragment = new HomeFragment();
  
 
 getSupportFragmentManager().beginTransaction() 
.replace(R.id.container,homeFragment) 
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.addToBackStack(null).commit();

    FloatingActionButton floatingActionButton = (FloatingActionButton) 
     findViewById(R.id.fab);

   
    floatingActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

           // Reproductor reproductor = new Reproductor();

           // reproductor.reproduceMedia();

            Intent intent = new Intent(ContainerActivity.this, 
    Reproductor.class);
            startActivity(intent); 

            /*Snackbar.make(view, "Replace with your own action", 
     Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();*/
        }

    });

    bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(@IdRes int tabId) {
    switch (tabId){
        case R.id.portada:
            HomeFragment homeFragment = new HomeFragment(); 

          getSupportFragmentManager().beginTransaction()
         .replace(R.id.container,homeFragment)
                    
         .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
        .addToBackStack(null).commit();
            break;
       case R.id.deportes:
            DeportesFragment deportesFragment = new DeportesFragment();
            getSupportFragmentManager().beginTransaction()
           .replace(R.id.container,deportesFragment)
                    
         .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
         .addToBackStack(null).commit();
            break;
        case R.id.politica:
            PoliticaFragment politicaFragment = new PoliticaFragment();
            getSupportFragmentManager().beginTransaction()
           .replace(R.id.container,politicaFragment)
                    
          .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
           .addToBackStack(null).commit();
            break;
       }
    }
  });

} 


@Override
protected void onPause()
{
    super.onPause();
}
protected void onResume() {

    super.onResume();
}
protected void onDestroy() {
    super.onDestroy();

  }
}
Marcado de codigo
Origen Enlace
Dev. Joel
  • 23.9k
  • 3
  • 30
  • 47

Estimados, tengo una función llamada Reproductor(), el fin de esta es utilizar la clase MediaPlayerMediaPlayer, tanto como para reproducir como para darle pause.

Deseo que por mientras se carga el audio me muestre el progressbarprogressbar, y una vez esté listo, desaparezca y me muestre un botonbotón pause. Pero con el código que tengo al presionar en el floating actionbuttonfloating actionbutton me envía un error de NullPointerException.

PID: 9364
                                                                                      
 java.lang.NullPointerException: Attempt to invoke virtual method 
'android.view.View android.view.Window.findViewById(int)' on a null object 
 reference
                                                                                          
 at android.app.Activity.findViewById(Activity.java:2090)
                                                                                          
  at cl.cooperativa.readxmlfrominternetmaterial.Reproductor.<init>
  (Reproductor.java:21)
                                                                                          
  at cl.cooperativa.readxmlfrominternetmaterial.view

 .ContainerActivity$1.onClick(ContainerActivity.java:42)
                                                                                          
 at android.view.View.performClick(View.java:5198)
                                                                                          
 at android.view.View$PerformClick.run(View.java:21147)
                                                                                          
 at android.os.Handler.handleCallback(Handler.java:739)
                                                                                          
 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                          
 at android.os.Looper.loop(Looper.java:148)
                                                                                          
 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                          
 at java.lang.reflect.Method.invoke(Native Method)
                                                                                          
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller
 .run(ZygoteInit.java:726)
                                                                                          
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

PID:936
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference at android.app.Activity.findViewById(Activity.java:2090) at cl.cooperativa.readxmlfrominternetmaterial.Reproductor. (Reproductor.java:21) at cl.cooperativa.readxmlfrominternetmaterial.view

.ContainerActivity$1.onClick(ContainerActivity.java:42) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller .run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Estimados, necesito su ayuda, que¿Qué estoy haciendo mal?

Estimados, tengo una función llamada Reproductor(), el fin de esta es utilizar la clase MediaPlayer, tanto como para reproducir como para darle pause.

Deseo que por mientras se carga el audio me muestre el progressbar, y una vez esté listo, desaparezca y me muestre un boton pause. Pero con el código que tengo al presionar en el floating actionbutton me envía un error de NullPointerException.

PID: 9364
                                                                                      
 java.lang.NullPointerException: Attempt to invoke virtual method 
'android.view.View android.view.Window.findViewById(int)' on a null object 
 reference
                                                                                          
 at android.app.Activity.findViewById(Activity.java:2090)
                                                                                          
  at cl.cooperativa.readxmlfrominternetmaterial.Reproductor.<init>
  (Reproductor.java:21)
                                                                                          
  at cl.cooperativa.readxmlfrominternetmaterial.view

 .ContainerActivity$1.onClick(ContainerActivity.java:42)
                                                                                          
 at android.view.View.performClick(View.java:5198)
                                                                                          
 at android.view.View$PerformClick.run(View.java:21147)
                                                                                          
 at android.os.Handler.handleCallback(Handler.java:739)
                                                                                          
 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                          
 at android.os.Looper.loop(Looper.java:148)
                                                                                          
 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                          
 at java.lang.reflect.Method.invoke(Native Method)
                                                                                          
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller
 .run(ZygoteInit.java:726)
                                                                                          
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Estimados, necesito su ayuda, que estoy haciendo mal?

Estimados, tengo una función llamada Reproductor(), el fin de esta es utilizar la clase MediaPlayer, tanto como para reproducir como para darle pause.

Deseo que por mientras se carga el audio me muestre el progressbar, y una vez esté listo, desaparezca y me muestre un botón pause. Pero con el código que tengo al presionar en el floating actionbutton me envía un error de NullPointerException.

PID:936
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference at android.app.Activity.findViewById(Activity.java:2090) at cl.cooperativa.readxmlfrominternetmaterial.Reproductor. (Reproductor.java:21) at cl.cooperativa.readxmlfrominternetmaterial.view

.ContainerActivity$1.onClick(ContainerActivity.java:42) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller .run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

¿Qué estoy haciendo mal?

Origen Enlace
Rodrigo
  • 685
  • 1
  • 7
  • 22
Loading