Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8763077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:41:47+00:00 2026-06-13T15:41:47+00:00

Hello everyone I have this problem, I had to make a AsyncTask because the

  • 0

Hello everyone I have this problem, I had to make a AsyncTask because the connection to the service from IceCast error NetworkOnMainThreadException then as I read around I say you put a AsyncTask to solve the problem, or give privileges with

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

but does not work under any circumstances and it crashes my application without even telling me something error despite the try-catch ..
Can you give me an explanation of what?

Thanks in advance here is the code:

import java.io.IOException; 
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import net.moraleboost.streamscraper.ScrapeException;
import net.moraleboost.streamscraper.Scraper;
import net.moraleboost.streamscraper.Stream;    
import net.moraleboost.streamscraper.scraper.IceCastScraper;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;


public class SwipeyTabsSampleActivity extends FragmentActivity {
    private Button streamButton;

    private ImageButton playButton;

    private TextView textStreamed;
    private TextView textSong;

    private boolean isPlaying;

    private StreamingMediaPlayer audioStreamer;

    private static final String [] TITLES = {
            "Live Stream",
            "Palinsesto",
            "Programmi",
            "Eventi",
    };

    private SwipeyTabs mTabs;
    private ViewPager mViewPager;


    @Override
    public void onCreate(Bundle savedInstanceState) {


            super.onCreate(savedInstanceState);

            setContentView(R.layout.activity_swipeytab);

            mViewPager = (ViewPager) findViewById(R.id.viewpager);
            mTabs = (SwipeyTabs) findViewById(R.id.swipeytabs);

            SwipeyTabsPagerAdapter adapter = new SwipeyTabsPagerAdapter(this,
                            getSupportFragmentManager());
            mViewPager.setAdapter(adapter);
            mTabs.setAdapter(adapter);
            mViewPager.setOnPageChangeListener(mTabs);
            mViewPager.setCurrentItem(0);

            Inizializza();

            new AsyncTaskProc().execute();

    }

    private void startStreamingAudio() {
            try { 
                    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
                    if ( audioStreamer != null) {
                            audioStreamer.interrupt();
                    }


                    audioStreamer = new StreamingMediaPlayer(this, textStreamed, playButton, streamButton,progressBar);
                    audioStreamer.startStreaming("http://r35798.ovh.net:8000/listen",1677, 214);
                    streamButton.setEnabled(false);
            } catch (IOException e) {                       
            }

    }
    private void Inizializza()
    {
            textStreamed = (TextView) findViewById(R.id.text_kb_streamed);
            streamButton = (Button) findViewById(R.id.button_stream);
            streamButton.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View view) {
                            startStreamingAudio();
                    }});


            playButton = (ImageButton) findViewById(R.id.button_play);
            playButton.setEnabled(false);
            playButton.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View view) {
                            if (audioStreamer.getMediaPlayer().isPlaying()) {
                                    audioStreamer.getMediaPlayer().pause();
                                    playButton.setImageResource(R.drawable.button_play);
                            } else {
                                    audioStreamer.getMediaPlayer().start();

                                    audioStreamer.startPlayProgressUpdater();
                                    playButton.setImageResource(R.drawable.button_pause);
                            }
                            isPlaying = !isPlaying;
                    }});
    }
    private class SwipeyTabsPagerAdapter extends FragmentPagerAdapter implements
    SwipeyTabsAdapter {

            private final Context mContext;

            public SwipeyTabsPagerAdapter(Context context, FragmentManager fm) {
                    super(fm);

                    this.mContext = context;
            }

            @Override
            public Fragment getItem(int position) {
                    return SwipeyTabFragment.newInstance(TITLES[position]);
            }

            @Override
            public int getCount() {
                    return TITLES.length;
            }

            public TextView getTab(final int position, SwipeyTabs root) {
                    TextView view = (TextView) LayoutInflater.from(mContext).inflate(
                                    R.layout.swipey_tab_indicator, root, false);
                    view.setText(TITLES[position]);
                    view.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {
                                    mViewPager.setCurrentItem(position);
                            }
                    });

                    return view;
            }

    }


    public void onPageScrollStateChanged(int arg0) {
            // TODO Auto-generated method stub

    }

    public void onPageScrolled(int arg0, float arg1, int arg2) {
            // TODO Auto-generated method stub

    }

    public void onPageSelected(int arg0) {
            // TODO Auto-generated method stub

    }
    //////////////////////////////////////

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
            menu.add("Uscita").setOnMenuItemClickListener(
                            new OnMenuItemClickListener() {
                                    public boolean onMenuItemClick(MenuItem item) {
                                            Toast.makeText(getApplicationContext(),
                                                            "Uscita Programma", Toast.LENGTH_SHORT).show();
                                            finish();
                                            System.exit(0);

                                            return true;
                                    }
                            });
            ;


            return true;
    }


    class AsyncTaskProc extends AsyncTask<Void, String, Void> {
            @Override
            protected Void doInBackground(Void... unused) {


                    List<Stream> streams=null;
                    Scraper scraper = new IceCastScraper();

                    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                    StrictMode.setThreadPolicy(policy);

                    try {
                            streams = scraper.scrape(new URI("@@@@@@"));
                    } catch (ScrapeException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            //Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_LONG).show();
                    } catch (URISyntaxException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            //Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_LONG).show();
                    }


                    textSong =(TextView) findViewById(R.id.textViewCurrentSong);

                    try {
                            for (Stream stream: streams) {

                                    textSong.setText((stream.getCurrentSong()));
                            }
                    } catch (Exception e) {
                            //Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show();

                    }


                    return (null);
            }


    }
}

EDIT: I move Ui in OnPostExecute() now this is new logcat

010-30 21:22:03.535: E/Trace(4973): error opening trace file: No such file or directory (2)
10-30 21:22:05.145: E/AndroidRuntime(4973): FATAL EXCEPTION: AsyncTask #1
10-30 21:22:05.145: E/AndroidRuntime(4973): java.lang.RuntimeException: An error occured while executing doInBackground()
10-30 21:22:05.145: E/AndroidRuntime(4973):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at java.lang.Thread.run(Thread.java:856)
10-30 21:22:05.145: E/AndroidRuntime(4973): Caused by: java.lang.Error: Unresolved compilation problem: 
10-30 21:22:05.145: E/AndroidRuntime(4973):     org.apache.commons.logging.LogFactory cannot be resolved to a type
10-30 21:22:05.145: E/AndroidRuntime(4973):     at net.htmlparser.jericho.LoggerFactory.determineDefaultLoggerProvider(LoggerFactory.java:51)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at net.htmlparser.jericho.LoggerFactory.getDefaultLoggerProvider(LoggerFactory.java:39)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at net.htmlparser.jericho.LoggerFactory.getLoggerProvider(LoggerFactory.java:35)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at net.htmlparser.jericho.LoggerFactory.getLogger(LoggerFactory.java:27)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at net.htmlparser.jericho.Source.newLogger(Source.java:1645)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at net.htmlparser.jericho.Source.<init>(Source.java:109)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at net.moraleboost.streamscraper.parser.IceCastParser.parse(IceCastParser.java:67)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at net.moraleboost.streamscraper.scraper.IceCastScraper.scrape(IceCastScraper.java:65)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at com.uniradio.cesena.app.SwipeyTabsSampleActivity$AsyncTaskProc.doInBackground(SwipeyTabsSampleActivity.java:264)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at com.uniradio.cesena.app.SwipeyTabsSampleActivity$AsyncTaskProc.doInBackground(SwipeyTabsSampleActivity.java:1)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-30 21:22:05.145: E/AndroidRuntime(4973):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-30 21:22:05.145: E/AndroidRuntime(4973):     ... 5 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:41:49+00:00Added an answer on June 13, 2026 at 3:41 pm

    You have not provided your logcat error so I’m guessing, but I think the issue is as follows.

    You are attempting to manipulate the UI from within doInBackground which will cause your app to crash. Move any changes to the UI that your AsyncTask must perform into onPostExecute

    for example:

    textSong.setText((stream.getCurrentSong()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello again everyone, This time I have a problem with Intent & Extras. here's
hello everyone I have some problem with understanding this piece of the code: import
Hello everyone I have a problem. I want to do a GridView with a
hello everyone i have a problem with my 3-tiers application i don't know how
Hello everyone i have created a multi threaded chat server that looks like this:
THIS PROBLEM IS NOW SOLVED. THANK YOU TO EVERYONE WHO REPLIED. Hello, I am
Hello everyone~ I have a problem to solve~ I have created a server that
hello everyone im trying to create this tweak that copies a file from one
Hello everyone I have a difficult problem with using BULK INSERT command when I
Hello everyone i have a problem I have a text $text = some and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.