Advertisement

05.30.2008 at 08:25AM PDT, ID: 23444901
[x]
Attachment Details

How Do I Fix "variable might not have been initialized" error in Java?

Asked by infinitusagnitio in Java Programming Language, Bayesian Filters, New to Java Programming

Tags: spamsort.java:103: variable hamzProb might not have been initialized, Java, Bayesian, Spam, Filter

I keep getting these error messages when I try to compile this program (simple Bayesian spam filter):  spamsort.java:103: variable hamzProb might not have been initialized
                              hamzProb[y] = (Double) dictList.get(tempWords[i]);
                                        ^
spamsort.java:104: variable spamzProb might not have been initialized
                              spamzProb[y] = (Double) dictList.get(tempWords[i]);
                                        ^
spamsort.java:112: variable spamzProb might not have been initialized
                  for (int z = 0; z < spamzProb.length; i++){
                                            ^
spamsort.java:114: variable hamzProb might not have been initialized
                        totalHamProb = totalHamProb * hamzProb[z];//Float.valueOf(hamzProb[z].trim()).floatValue();




Below is my code.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
for (int i = 0; i < kids.length; i++){
			FileInputStream dis = new FileInputStream(args[0] + "/" + kids[i].getName());
			FileChannel dc = dis.getChannel();
			ByteBuffer byteb = ByteBuffer.allocate((int)dc.size());
			fc.read(byteb);
			fc.close();
			String fileBox = new String(byteb.array());
			String[] tempWords = fileBox.split("\\s+");
			double[] hamzProb;
			double[] spamzProb;
			int y = 0;
			for (int x = 0; x < tempWords.length; x++){
				if (dictList.containsKey(tempWords[x])){
					hamzProb[y] = (Double) dictList.get(tempWords[i]);
					spamzProb[y] = (Double) dictList.get(tempWords[i]);
					//hamzProb[y] = Float.valueOf(hamValue.trim()).floatValue();
					//spamzProb[y] = Float.valueOf(spamValue.trim()).floatValue();
					y++;
				}
			}
			double totalSpamProb = 1.0;
			double totalHamProb = 1.0;
			for (int z = 0; z < spamzProb.length; i++){
				totalSpamProb = totalSpamProb * spamzProb[z];//Float.valueOf(spamzProb[z].trim()).floatValue();
				totalHamProb = totalHamProb * hamzProb[z];//Float.valueOf(hamzProb[z].trim()).floatValue();
			}
			float spam_probability = Float.valueOf(args[3].trim()).floatValue();
 
 
[+][-]05.30.2008 at 08:28AM PDT, ID: 21678667

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, Bayesian Filters, New to Java Programming
Tags: spamsort.java:103: variable hamzProb might not have been initialized, Java, Bayesian, Spam, Filter
Sign Up Now!
Solution Provided By: CEHJ
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.30.2008 at 08:37AM PDT, ID: 21678769

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 08:49AM PDT, ID: 21678893

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628