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

  • Home
  • SEARCH
  • 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 8717149
In Process

The Archive Base Latest Questions

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

Well this code works fine in java but when i started to run it

  • 0

Well this code works fine in java but when i started to run it on Android 4.0 emulator it crashes. While Debugging i noticed that it crushed on httpConn.connect(); line

  public class GetStringFromUrl {
public static String getString(String urlPageAdress) throws Exception
{

    URL url = new URL(urlPageAdress);
     HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
      urlConn.setRequestProperty("Accept-Encoding", "UTF-8");
     HttpURLConnection httpConn = (HttpURLConnection) urlConn;
      httpConn.setAllowUserInteraction(false);
     httpConn.connect(); //crashes on this line dunno know why

     InputStream in = null;

     if (httpConn.getContentEncoding() != null && httpConn.getContentEncoding().toString().contains("gzip")) {
     in = new GZIPInputStream(httpConn.getInputStream());
      } else {
      in = httpConn.getInputStream();
    }
     BufferedInputStream bis = new BufferedInputStream(in);
     ByteArrayBuffer baf = new ByteArrayBuffer(1000);
     int read = 0;
      int bufSize = 1024;
      byte[] buffer = new byte[bufSize];
     while (true) {
      read = bis.read(buffer);
      if (read == -1) {
    break;
      }
     baf.append(buffer, 0, read);



     }
      String body = new String(baf.toByteArray());
    return body;
} }

method is used in Main Activity

public class MainActivity extends Activity{

ToggleButton  toogleButton;
 public final static String EXTRA_MESSAGE = "ru.kazartsevaa.table.MESSAGE";
int upDown;
int SpinnerCount;
  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    upDown=0;


    setContentView(R.layout.activity_main);
}

public void onClick(View v) throws Exception
{ System.out.print(SpinnerCount);
// if(upDown==0) //0 – вылет 1 прилет
//{
switch (v.getId())
{
case R.id.UpDownButton:
{
//toogleButton = (ToggleButton) findViewById(R.id.UpDownButton);
// toogleButton.setOnCheckedChangeListener(this);
}
case R.id.SheremetievoButton:
{
Spinner SherSpinner = (Spinner) findViewById(R.id.SheremetievoSpinner);

                    String SpinnerCount= SherSpinner.getItemAtPosition(SherSpinner.getSelectedItemPosition()).toString();
                    System.out.print(SpinnerCount);
                    new Thread(){ public void run() { 
                        try {
                            String body = GetStringFromUrl.getString("www.xyz.com");
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        } }.start();

                        int crowd;






                }

        }

Note: After changing to new thread it stopped crushing but still writes

  • 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-13T06:14:42+00:00Added an answer on June 13, 2026 at 6:14 am

    Are you doing this in the main thread? Should work if you execute this in a separate thread.

        public void onClick(View v) {
        try{
                new Thread(){
                        public void run() {
                            GetStringFromUrl.getString("www.xyz.com");                      
                        }
                }.start();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works well for displaying separate xml items in my main.xml. But is
I just realized that this piece of code works well in Firefox but not
This code works well: UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame]; [pickerView addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
I get a strange error and couldn't find the answer.. This code works well:
I have this code that works well: {livre:empty_name} $.ajax({ url: sent.php, type: post, dataType:
Code like this works well. Intent configIntent = new Intent (context, WidgetConfigActivity.class); configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
I got this code from someone and it works very well, I just want
I'm using this code to extract text from the database and it works well
We're using iText to generate PDF files from Java code, which works pretty well
This is a Java syntax question, but just for some background. Using android, I

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.