Cannot find a class or type named “Test”

I just found this code on the internet (how to open a webpage with java Code Example)

when i tried to run it it said Cannot find a class or type named “Test”, what do i have to replace test with to make it work?


/**
 * author Scratchy (Twitter @S_cratchy)
 * Just import stuff
 */
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
This you put in your button or whatever
 */
String url_open ="HTTPS://www.google.com";
try {
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url_open));
} catch (IOException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}

comment out the line

   // Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
1 Like

thank you, turns out it’s not what i was looking for but it works the way the maker intended

1 Like

do you also know why this one doesn’t work, its supposed to do something similar


import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.*;

public class LoadWebPage extends JFrame
{

public LoadWebPage()
{
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(620,440);
JScrollPane sp=new JScrollPane();
JTextPane tp=new JTextPane();
tp.setEditable(false);
URL myurl = null;
try {
    myurl=new URL("http://javatongue.blogspot.com");
    } catch (MalformedURLException ex) {ex.printStackTrace();}
sp.setViewportView(tp);
add(sp);
try {
    tp.setPage(myurl);
    } catch (IOException ex) {ex.printStackTrace();}

}

public static void main(String args[])
{
new LoadWebPage().setVisible(true);
}

}
1 Like

You can comment out the lines in the catch section

if i comment out the lines starting with catch it says "Error on “Finally” so i think i commented out the wrong lines. which lines do you mean?

This part

For example

Only within the {…} of catch

Are you in processing or in eclipse ide?

I am working in processing

That does not look like processing code, lol.

1 Like

can you make a screenshot please

of what do i have to make a screenshot?

I mean the IDE - looks more like eclipse IDE, not processing IDE

oh, i dont know i just copied it of the internet to see if it was what i was looking for and it looked similar to what i usually make so i assumed it was correct

Did you get it here…?

https://www.processing.org/download/

yeah i did get it there, why?

1 Like

for example this bit looks more like pure Java and not like processing afaik

processing is with draw() afaik

     void setup() {
       size(400, 400);
       stroke(255);
     }

     void draw() {
       background(192, 64, 0);
       line(150, 25, mouseX, mouseY);
     }
2 Likes

It seems to be from here:

If so, it is offered as a Java example, but not designed for Processing.

That does not necessarily mean that it cannot be adapted for Processing, with a lot of work. Adapting it might require some significant adjustments.

2 Likes