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 7880753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:13:12+00:00 2026-06-03T04:13:12+00:00

My friend asked me to post his question here, and there it is: I

  • 0

My friend asked me to post his question here, and there it is:

I have an issue with this… My code worked out just fine, and suddenly a bug appears. I have no idea whats wrong in it, maybe you guys can show me some obvious mistake with I am making.

That’s the error communicate:

> Exception in thread "main" java.net.MalformedURLException: no
> protocol: 
>         at java.net.URL.<init>(URL.java:583) 
>         at java.net.URL.<init>(URL.java:480) 
>         at java.net.URL.<init>(URL.java:429) 
>         at pogoda.Okienko.getJPanel(Okienko.java:120) 
>         at pogoda.Okienko.getJContentPane(Okienko.java:101) 
>         at pogoda.Okienko.initialize(Okienko.java:59) 
>         at pogoda.Okienko.<init>(Okienko.java:49) 
>         at pogoda.Pogoda.main(Pogoda.java:119)

and this is my code:

package pogoda;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.GridBagLayout;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;


public final class Okienko extends JFrame
{

        public static final long serialVersionUID = 1L;
        public JPanel jContentPane = null;
        public JLabel jLabel = null;
        public JLabel jLabel1 = null;
        public JLabel LabelTemp = null;
        public JLabel LabelOdczuwalna = null;
        public JPanel jPanel = null;

        public Okienko(double temperatura, double odczuwalna, String adres) throws MalformedURLException
        {
                super();
                initialize(temperatura, odczuwalna, adres);
        }

public void initialize(double temperatura, double odczuwalna, String adres) throws MalformedURLException
        {
                this.setLocation(350, 250);
                this.setSize(350, 350);
                this.setContentPane(getJContentPane(temperatura, odczuwalna,adres));
                this.setTitle("Pogoda");
                this.setResizable(false); // jesli damy na true bedziemy mogli zmienic rozmiar naszego okienka
                this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        }

public JPanel getJContentPane(double temperatura, double odczuwalna, String adres) throws MalformedURLException
        {
                if (jContentPane == null)
                {
                        LabelOdczuwalna = new JLabel();
                        LabelOdczuwalna.setBounds(new Rectangle(200, 50, 100, 20));
                        odczuwalna *=100;
                        int pomoc=(int) odczuwalna;
                        odczuwalna = ((double)pomoc)/100;
                        LabelOdczuwalna.setText("" + odczuwalna + " °C");
                        LabelTemp = new JLabel();
                        LabelTemp.setBounds(new Rectangle(200, 10, 100, 20));
                        temperatura *=100;
                        pomoc = (int)temperatura;
                        temperatura = ((double)pomoc)/100;
                        LabelTemp.setText("" + temperatura + " °C");
                        jLabel1 = new JLabel();
                        jLabel1.setBounds(new Rectangle(5, 50, 300, 20));
                        jLabel1.setText("Temperatura odczuwalna");
                        jLabel = new JLabel();
                        jLabel.setBounds(new Rectangle(5, 10, 300, 20));

                        jLabel.setText(" Aktualna temperatura ");
                        jContentPane = new JPanel();
                        jContentPane.setLayout(null);
                        jContentPane.add(jLabel, null);
                        jContentPane.add(jLabel1, null);
                        jContentPane.add(LabelTemp, null);
                        jContentPane.add(LabelOdczuwalna, null);
                        jContentPane.add(getJPanel(adres), null);
                }
                return jContentPane;
        }

 public JPanel getJPanel(String adres) throws MalformedURLException
 {
     if (jPanel == null)
     {
         jPanel = new JPanel();
         jPanel.setLayout(new GridBagLayout());
         jPanel.setBounds(new Rectangle(75, 100, 150, 150));
     }

     java.net.URL where = new URL(adres);
     ImageIcon icon = new ImageIcon(where);
     JLabel pomocnik = new JLabel();
     pomocnik.setIcon(icon);
     jPanel.add(pomocnik);
     return jPanel;
 }

}

package pogoda;



/**
 *
 * @author mateusz
 */

import com.sun.corba.se.impl.logging.OMGSystemException;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.swing.JFrame;






import java.net.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;


public class Pogoda
{


        public int counter = 1;
        public static String linia1 =
                "<span class=\"twc-forecast-when twc-none\">Right Now</span>";
        public static String linia11 =
                "<img src=\""+
                ".+"+
                "\" alt=";

        public static String linia2 =
                "<td class=\"twc-col-1 twc-forecast-temperature\"><strong>"+
                "\\d+"+
                "&deg;F</strong></td>";
        public static String linia3 =
                "<td class=\"twc-col-1 twc-forecast-temperature-info\">Feels Like: <strong>"+
                "\\d+"+
                "&deg;</strong>";




        public static void main(String args[]) throws IOException
        {

                int temperatura =0;
                int odczuwalna =0;
                String adresObrazka="";
                String help = "";
                String linia = "";
                URL strona = new URL("http://www.weather.com/weather/today/Wroclaw+Poland+PLXX0029");
                URLConnection con = (URLConnection) strona.openConnection();

                con.connect();
                BufferedReader in = new BufferedReader(new InputStreamReader(strona.openStream()));
                while((linia = in.readLine()) != null)
                {
                                Pattern p = Pattern.compile(linia2);
                                Matcher m = p.matcher(linia);
                                if(m.find())
                                {

                                        help = m.group().substring(55,m.group().length()-20);
                                        temperatura = Integer.parseInt(help);
                                        System.out.println(temperatura);

                                }
                                p = Pattern.compile(linia3);
                                m = p.matcher(linia);
                                if(m.find())
                                {
                                        System.out.println("znaleziono odczuwalna");
                                        help = m.group().substring(72,m.group().length()-14);
                                        System.out.println(help);
                                        odczuwalna=Integer.parseInt(help);
                                }
                                p = Pattern.compile(linia1);
                                m = p.matcher(linia);
                                if(m.find())
                                {
                                        linia = in.readLine();
                                        p = Pattern.compile(linia11);
                                        m = p.matcher(linia);
                                        if(m.find())
                                        {
                                                System.out.println("Pobrałem adres obrazka");
                                                System.out.println(m.group().substring(10,m.group().length()-6));
                                                adresObrazka = m.group().substring(10,m.group().length()-6);
                                        }
                                }


                }

                double temperatura1 = temperatura;
                double odczuwalna1 = odczuwalna;
                odczuwalna1 = ((odczuwalna1-32)*5)/9;
                temperatura1 = ((temperatura1-32)*5)/9;
                System.out.println("Dane pobrane");
                System.out.println("Temperatura " + temperatura1 + "\n Odczuwalna " + odczuwalna1 + "\n Adres obrazka " + adresObrazka);
                Okienko o = new Okienko(temperatura1,odczuwalna1,adresObrazka);
                o.setVisible(true);
                o.jContentPane.setVisible(true);
        }

}
  • 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-03T04:13:14+00:00Added an answer on June 3, 2026 at 4:13 am

    From the looks of it the application does the following:

    • Retrieve the contents of a specific web page
    • Use regular expressions to retrieve specific data from the above web page
    • One of the items extracted is a URL to an image
    • The URL is never verified to be valid
    • Occasionally the URL isn’t valid and an MalformedURLException is thrown

    As the scraped web page is external to the application there is no guarantee that the extracted URL exist, is valid, or is in the same place as it was the last week (regardless of how well the regular expressions are written). There is only one solution and that is to fail gracefully (perhaps show another image in these cases) and optionally notify the application maintainer to update the regular expressions and/or web page used to extract the information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is just a random question my friend asked me which I also do
This question was asked in another post at Facebook iframe app being redirected out
A friend just asked me this interesting question and I had no answer to
My friend asked this question I am not sure why it is on my
My friend asked me this question today. How to test a vending machine and
this is an interview question my friend was asked yesterday. The question was something
A friend asked me to add some dropdown menus to his site. It's here:
Yesterday my friend asked me a question about this query: select * from user
MY friend asked here a question And the one who answered him - wrote
A friend asked me to check out Wefeelfine and I was just flabbergasted on

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.