-
Compiles but doesnt run
This is my first attempt at a java app. Basically, its just 2 textfields and an exit button. The user enters a phone extension number in the first textfield and the corisponding cube number is displayed in the second text box. Or atleast that is what its supposed to do 
The program compiles but when I go to run it, it tells me it could not find the main class and the program will exit.
I've searched all over the web and been over the code a 100 times and I dont know what I'm missing, any help would be appreciated 
/*code
package project;
import javax.swing.*;
import java.awt.Dimension;
import java.awt.event.*;
import java.util.*;
import java.lang.reflect.*;
public class project implements ActionListener {
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField jTextField2 = new JTextField();
JButton jButton1 = new JButton();
int [] Extension = { 1143, 1165,1203,1214,1228,1233, 1272, 1303, 1308, 1311, 1313, 1314, 1322, 1323, 1326, 1327, 1331, 1333, 1337, 1338, 3019, 3021, 3025, 3028, 3029, 3062, 3064, 3065, 3066, 3067, 3068, 3071, 3073, 3074, 3075, 3076, 3077, 3078, 3079, 3080, 3081, 3082, 3083, 3084, 3085, 3086, 3088, 3090, 3091, 3092, 3093, 3094, 3095, 3096, 3097, 3098, 3236, 3237, 3238, 3239, 3240, 3242, 3243, 3244, 3245, 3246, 3247, 3248, 3249, 3250, 3251, 3252, 3253, 3254, 3255, 3258, 3261, 3263, 3264, 3265, 3266, 3269, 3270, 3271, 3272, 3274, 3275, 3276, 3277, 3280, 3282, 3283, 3284, 3285, 3286, 3287, 3288, 3289, 3290, 3291, 3294, 3295, 3296, 3297, 3298, 3299, 3300, 3301, 3302, 3303, 3305, 3309, 3310, 3311, 3314, 3315, 3316, 3318, 3321, 3323, 3324, 3325, 3326, 3327, 3328, 3329, 3330, 3336, 3337, 3338, 3340, 3342, 3344, 3346, 3348, 3350, 3351, 3385, 3388, 3432, 3436, 3464, 3523, 3524, 3533, 3534, 3535, 3536,
3537, 3538, 3539, 3540, 3549, 3550, 3560, 3561 };
int [] Cube = { 73, 8, 156, 16, 47, 63, 116, 41, 141, 1, 33, 17, 9, 125,153, 154, 32, 42, 15, 13, 105, 81, 31, 108, 81, 31, 108, 91, 74, 82, 124, 99, 83, 26, 140, 139, 67, 138, 71, 137, 155, 136, 152, 135, 151, 56, 107, 133, 134, 72, 100, 117, 101, 109, 102, 119, 103, 120, 104, 121, 122, 106, 123, 49, 90, 36, 88, 28, 87, 70, 86, 69, 85, 68, 27, 84, 65, 66, 48, 12, 50, 35, 51, 24, 38, 53, 39, 11, 55, 54, 23, 6, 59, 58, 57, 77, 89, 78, 95, 79, 111, 80, 97, 131, 114, 130, 113, 129, 112, 128, 93, 127, 126, 40, 75, 96, 76, 94, 25, 29, 30, 98, 45, 115, 62, 46, 61, 14, 60, 44, 110, 43, 143, 144, 145, 146, 147, 148, 132,
149, 150, 142, 10, 64, 92, 52, 37, 21, 5, 20, 4, 19, 3, 18, 2, 22, 7, 118, 34};
public project() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args){
project project = new project();
}
private void jbInit() throws Exception {
jLabel1.setText("Extension#");
jTextField1.setMaximumSize(new Dimension(63, 21));
jTextField1.setMinimumSize(new Dimension(63, 21));
jTextField1.setPreferredSize(new Dimension(63, 21));
jTextField1.addActionListener(this);
jLabel2.setText("Cube#");
jTextField2.setMaximumSize(new Dimension(63, 21));
jTextField2.setMinimumSize(new Dimension(63, 21));
jTextField2.setPreferredSize(new Dimension(63, 21));
jTextField2.setEditable(false);
jButton1.setText("Exit");
jButton1.addActionListener(this);
jPanel1.add(jLabel1, null);
jPanel1.add(jTextField1, null);
jPanel1.add(jLabel2, null);
jPanel1.add(jTextField2, null);
jPanel1.add(jButton1, null);
}
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
if (source == jTextField1) {
String text = jTextField1.getText();
int e = Integer.valueOf(text).intValue();
int c = Arrays.binarySearch(Extension, e);
if (c >= 0) {
int cube1 = Array.getInt(Cube, c);
String text2 = Integer.toString(cube1);
jTextField2.setText(text2);
}
else {
System.out.println("Extension not found, please re-enter");
}
}
else {
System.exit(0);
}
}
}
Thanks,
Tazman
-
Probably to do with the package name and the fact its not in your classpath.
Go to the directory where your project/ folder is and use the command:
java -cp . project.project
This will let it know it needs to find the class project, in the package project, and the current directory is a good place to look.
Btw, your main method in the class only instantiated a new project object but does not actually do anything with it, so when you run this class you will see no output before it returns to the prompt.
Hope this all helps
Laziness is a virtue.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks