Compatible & Incompatible types
Why is that I can assign a integer value to a double variable, but cannot assign a double value to an integer variable? Aren't double and integer compatible types? Isn't there a concept of truncation in java? I searched the net but in vain. I couldn't find the exact answer I was looking for. So I am posting in this forum.
PS: I understand it is not possible to assign an integer to a string since they are incompatible types.
Edited by: 964980 on Mar 26, 2013 9:29 PM
Why is that I can assign a integer value to a double variableBecause it's a widening conversion that doesn't lose any information. See JLS #5.1.2.
but cannot assign a double value to an integer variable?Because it's a narrowing conversion that might lose information. You can do it as long as you write an explicit typecast. See JLS #5.1.3.
Aren't double and integer compatible types?No, see above.
Isn't there a concept of truncation in java?Yes, see above.
@rp0428 I don't see what good asking for the code and the error message does, in a fundamental case like this. It doesn't change the answer, and your own answer (is/isn't) wasn't too inspiring.
Similar Messages
-
ORABPEL-10041 Trying to assign incompatible types
Hi,
I'm developing a BPEL process which takes an input xml file and inserts data into AP interface tables. I used a file adapter to read the input file and used applications adapter to import ap interface tables.
I use the assign activity to assign the number value from my xml file to the invoice_id column in the ap_invoices_interface column. I get the following warning. Can anyone please tell me how do I fix this. I have BPEL 10.1.2.2 installed.
Warning(29):
[Error ORABPEL-10041]: Trying to assign incompatible types
[Description]: in line 29 of "C:\OraBPELPM_1\integration\jdev\jdev\mywork\Workspace1\BPELProcess_TestInsert\BPELProcess_TestInsert.bpel", <from> value type "{http://www.w3.org/2001/XMLSchema}string" is not compatible with <to> value type "{http://www.w3.org/2001/XMLSchema}long".
[Potential fix]: Please make sure that the return value of from-spec query is compatible with the to-spec query.
ThanksThis is just a warning so it does not mean that your process will fail, e.g. string to decimal may work for the string holds a number, but will fail if it has a string.
So if you know the data you can safely ignore, otherwise you will have to do some transofrmation within an assign.
cheers
James -
Incompatible types error on a for loop
Hi. I am in the middle of making a program and a decided to make a print statment to check to make sure everything was organized as it should be and I got an incompatible types error for the line where I start my for loop - for (index = 0 ...) etc. Since everything is an int, I'm not sure how they're not compatible with each other.. thoughts? here's my code so far, thanks
import java.io.*; // needed for stream readers
import java.lang.*;
public class testScores extends Object
public static void main(String args[] ) throws Exception
// declare variables for input
String records;
String room_nbr_input;
String test_score_input;
String student_id;
int room_nbr_nbr;
int test_score_nbr;
int index;
String[] record = new String[3];
int[] room_nbr = new int[30];
int[] test_score = new int[30];
int[] kount = new int[30];
// created file reader and buffered reader
FileReader frM;
BufferedReader brM;
// open file
frM = new FileReader("einstein_testscores_2009.txt");
brM = new BufferedReader(frM);
// print headings
startUp();
// get one record from file
records = brM.readLine();
while(records !=null)
//split the record into three fields = the array record[], then assign those values to variables
record = records.split(", ");
student_id = record[0];
room_nbr_input = record[1];
test_score_input = record[2];
//change the data into integers
room_nbr_nbr = Integer.parseInt(room_nbr_input);
test_score_nbr = Integer.parseInt(test_score_input);
//put the variables into arrays
room_nbr[room_nbr_nbr -1] = room_nbr_nbr;
test_score[room_nbr_nbr -1] = test_score[room_nbr_nbr -1] + test_score_nbr;
//get new record
records = brM.readLine();
for (index = 0; index = room_nbr.length; index++)
System.out.print(room_nbr[index] + "\t\t" + test_score[index]);
public static void startUp()
System.out.print("Einstein Elementary Test Scores\n\n");
System.out.print("Room Number\t\tTest Score Average\n\n");
} // end of class declarationthank you. here's the code.
import java.io.*; // needed for stream readers
import java.lang.*;
public class testScores extends Object
public static void main(String args[] ) throws Exception
// declare variables for input
String records;
String room_nbr_input;
String test_score_input;
String student_id;
int room_nbr_nbr;
int test_score_nbr;
int index;
String[] record = new String[3];
int[] room_nbr = new int[30];
int[] test_score = new int[30];
int[] kount = new int[30];
// created file reader and buffered reader
FileReader frM;
BufferedReader brM;
// open file
frM = new FileReader("einstein_testscores_2009.txt");
brM = new BufferedReader(frM);
// print headings
startUp();
// get one record from file
records = brM.readLine();
while(records !=null)
//split the record into three fields = the array record[], then assign those values to variables
record = records.split(", ");
student_id = record[0];
room_nbr_input = record[1];
test_score_input = record[2];
//change the data into integers
room_nbr_nbr = Integer.parseInt(room_nbr_input);
test_score_nbr = Integer.parseInt(test_score_input);
//put the variables into arrays
room_nbr[room_nbr_nbr -1] = room_nbr_nbr;
test_score[room_nbr_nbr -1] = test_score[room_nbr_nbr -1] + test_score_nbr;
//get new record
records = brM.readLine();
for (index = 0; index = room_nbr.length; index++)
System.out.print(room_nbr[index] + "\t\t" + test_score[index]);
public static void startUp()
System.out.print("Einstein Elementary Test Scores\n\n");
System.out.print("Room Number\t\tTest Score Average\n\n");
} // end of class declaration -
Sample 1:
public interface I<T extends I<?>>
I<? extends I<T>> m1 ();
public class Z<T extends I<?>> implements I<T>
public I<? extends I<T>> m1 ()
return m2();
protected I<? extends I<T>> m2 ()
return null;
javac Z.javacompiled with no problems
Sample 2:
public interface I<Tx, T extends I<Tx, ?>>
I<Tx, ? extends I<Tx, T>> m1 ();
public class Z<Tx, T extends I<Tx, ?>> implements I<Tx, T>
public I<Tx, ? extends I<Tx, T>> m1 ()
return m2();
protected I<Tx, ? extends I<Tx, T>> m2 ()
return null;
javac Z.javaZ.java:5: incompatible types
found : I<Tx,capture of ? extends I<Tx,T>>
required: I<Tx,? extends I<Tx,T>>
return m2();
^
1 error
Well... can anyone help with this? Or at least some explanations why adding second generic generates this problem?The problem is in the recursion, not in the second type argument. If you changed your first interface from
public interface I<T extends I<?>> {} to
public interface I<T extends I<T>> {} you would run into the same error message. For sake of clarity let's discuss the issue using your first example in a slightly simplified form:
public interface I<T extends I<T>> {}
public class Z<E>
public I<? extends I<E>> m1 ()
return m2();
/* error: incompatible types
found : I<capture of ? extends I<E>>
required: I<? extends I<E>>
return m2();
^
protected I<? extends I<E>> m2 ()
{ return null; }
}The error message is not awfully helpful, because the "E" is different in both types.
Method m2 returns a reference of type I<capture of ? extends I<E>>, where E extends I<capture of ? extends I<E>>, that is, it returns a concrete instantiation of the interface, namely I<SomeType> with a type that extends I<SomeType> with a type that extends ... continued recursively.
On the other hand, method m1 is supposed to return a reference of type I<? extends I<E>>, where E extends I<? extends I<E>>, that is, it returns a wildcard instantiation of the interface, namely I<? extends I<SomeType>> with a type that extends I<? extends I<SomeType>> with a type that extends ... continued recursively.
And here is the point: The first construct leads to a concrete instantiation like a List<List<List<String>>>. The second construct lead to a recursive wildcard instantiation like List<? extends List<? extends List<?>>>. As soon as the wildcard appears on a nested level, the types are no longer compatible.
It's like assigning a List<List<String>> to a List<List<?>>. It's not permitted because the first is a list of string-lists and the second is a list of mixed-lists. You cannot assign one to the other.
In your example, changing
public interface I2<Tx, T extends I2<Tx, ?>> to
public interface I2<Tx, T extends I2<?, ?>>might do the trick.
(As usual, ignore the annoying additional angle brackets.) -
Incompatible types - found java.lang.String but expected int
This is an extremely small simple program but i keep getting an "incompatible types - found java.lang.String but expected int" error and dont understand why. Im still pretty new to Java so it might just be something stupid im over looking...
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Lab
public static void main(String []args)
int input = JOptionPane.showInputDialog("Input Decimal ");
String bin = Integer.toBinaryString(input);
String hex = Integer.toHexString(input);
System.out.println("Decimal= " + input + '\n' + "Binary= " + bin + '\n' + "Hexadecimal " + hex);
}You should always post the full, exact error message.
Your error message probably says that the error occurred on something like line #10, the JOptionPane line. The error is telling you that the compiler found a String value, but an int value was expected.
If you go to the API docs for JOptionPane, it will tell you what value type is returned for showInputDialog(). The value type is String. But you are trying to assign that value to an int. You can't do that.
You will need to assign the showInputDialog() value to a String variable. Then use Integer.parseInt(the_string) to convert to an int value. -
Incompatible types with generics problem
Hi,
I get a mysterious compiler error:
C:\Documents and Settings\Eigenaar\Mijn documenten\NetBeansProjects\Tests\src\tests\genericstest.java:26: incompatible types
found : tests.Store<T>
required: tests.Store<T>
return store;
1 error
BUILD FAILED (total time: 0 seconds)
in the following code:
class Supply<T extends Supply<T>>{}
class Store<T extends Supply<T>>{ }
class A<T extends Supply<T>>{
private Store<T> store;
class B<T extends Supply<T>> {
public Store<T> getStore(){
return store; <-- compiler error!
}Any help would be greatly appreciated.
Edited by: farcat on Jan 13, 2009 1:23 PMNote that the type parameter T used to define class B is not the T used to define class A. What you wrote can be more clearly written:
class Supply<T extends Supply<T>>{}
class Store<T extends Supply<T>>{ }
class A<T extends Supply<T>>{
private Store<T> store;
class B<U extends Supply<U>> {
public Store<U> getStore(){
return store;
}Which produces the more readable error message:
A.java:10: incompatible types
found : Store<T>
required: Store<U>
return store;B, being a nested, non-static class is already parameterized by T:
class Supply<T extends Supply<T>>{}
class Store<T extends Supply<T>>{ }
class A<T extends Supply<T>>{
private Store<T> store;
class B {
public Store<T> getStore(){
return store;
} -
Incompatible types in case statement
I'm getting incompatible types inside this case statement :
inString = s_in.readUTF();
switch (inString.substring(1,3))
case nam:
ChatClient.nameArea.append(inString);
break;
case txt:
ChatClient.chatArea.append( "\n >>>" + inString );
break;
}If you want, or need to see more or all of the code in this class, just ask.This is because you can't use Strings within a switch statement. Use if statements instead.
-
Incompatible types - found, required...
Experts,
I am getting the following failure. What am I missing?
Javac output,
#javac .\org\ocap\dvr\*.java
.\org\ocap\dvr\TestRecord.java:123: incompatible types
found : org.ocap.shared.dvr.RecordingManager
required: org.ocap.dvr.OcapRecordingManager
recManager = OcapRecordingManager.getInstance();
^
The source code is as follows,
In .\src\org\ocap\shared\dvr\RecordingManager.java
----------------- START --------------------
package org.ocap.shared.dvr;
public abstract class RecordingManager
public static RecordingManager getInstance()
return null;
// stuff deleted
------------------ END -------------------
In .\src\org\ocap\dvr\OcapRecordingManager.java
----------------- START --------------------
package org.ocap.dvr;
import org.ocap.dvr.*;
import org.ocap.shared.dvr.*;
public abstract class OcapRecordingManager extends RecordingManager
// stuff deleted
------------------ END -------------------
In .\src\org\ocap\dvr\OcapRecordingManagerImpl.java
----------------- START --------------------
package org.ocap.dvr;
import org.ocap.dvr.*;
import org.ocap.shared.dvr.*;
public class OcapRecordingManagerImpl extends OcapRecordingManager
private static OcapRecordingManager mOcapRecordingManager = null;
public static OcapRecordingManager getInstance()
if (mOcapRecordingManager == null)
mOcapRecordingManager = new OcapRecordingManagerImpl();
return mOcapRecordingManager;
------------------ END -------------------
In .\src\org\ocap\dvr\TestRecord.java
----------------- START --------------------
package org.ocap.dvr;
import org.ocap.dvr.OcapRecordingManager;
import org.ocap.shared.dvr.RecordingManager;
class TestRecord
//Object of OcapRecordingManager class
private static OcapRecordingManager recManager = null;
public static void main(String args[])
recManager = OcapRecordingManager.getInstance();
if(recManager == null)
System.out.println ("Value obtained in OcapRecordingManagerImpl reference is null");
------------------ END -------------------
Thanks!Please don't crosspost!
http://forum.java.sun.com/thread.jspa?threadID=5210277&messageID=9846716#9846716 -
[SOLVED] XSD simpleType trying to assign incompatible types
Hi all!
I have a big XSD schema with complex and simple types defined. One of the simple types looks like this (string with min and max length defined):
<xsd:simpleType name="MySimpleType">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1" />
<xsd:maxLength value="36" />
</xsd:restriction>
</xsd:simpleType>I assign (copy operation) a string variable to an element of this type. When I compile i get the trying to assign incompatible types warning. I know it's just a warning but I'd like to solve it. I thought I can create a variable of the same type, but I can't (if I try to define message type only the complex type from XSD are displayed).
Is there a way to get rid of this warning?
Thanksinstead of using a variable assignment use the expression builder to construct the 'bpws:getVariableData() equivalent of the variable assignment. The warning will no longer exist.
-
I get the following error message:
headoffice.java:181: incompatible types
found : java.lang.String
required: int
switch (sa[3]) //sa[3] contains customer type
^
headoffice.java:183: incompatible types
found : java.lang.String
required: int
case �B�:
^
headoffice.java:186: incompatible types
found : java.lang.String
required: int
case �G�:
^
3 errors
...and it is associated with the piece of code below. I do not understand in what way the �G� and �B� are incompatible types with sa[3] which is supposed to hold strings.
StringTokenizer st=new StringTokenizer(s, �*�);
String[] sa=new String[st.countTokens()]; int i=0;
while(st.hasMoreTokens())
sa=st.nextToken();
i++;
switch (sa[3]) //sa[3] contains customer type
case �B�:
BronzeCustomer anotherBronzeCustomer = new BronzeCustomer(sa[0], sa[1]); break;
case �G�:
GoldCustomer anotherGoldCustomer = new GoldCustomer(sa[0], sa[1]); break;
default: return;
// break;
What is the problem here?
Regards
TJIf you are using only 1-character strings, then you can do:
switch (sa[3].charAt(0)) //sa[3] contains customer type
case 'B': // ...
case 'G': // ...
// etc.
} -
Trouble at the end of this code involving incompatible types within word = listEasy.get(wordArrayLocation); along with the other two in that method. Says it needs a java.lang.String.
import java.util.Random;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.lang.String;
public class WordArray
public WordArray() throws FileNotFoundException
Creation of 3 word arrays based off of the desired level of game difficulty
ArrayList<String> listEasy = new ArrayList<String>();
ArrayList<String> listIntermediate = new ArrayList<String>();
ArrayList<String> listHard = new ArrayList<String>();
//open the physical files (words*.txt) for use in the corresponding ArrayList
FileReader readerEasy = new FileReader("wordsEasy.txt");
FileReader readerIntermediate = new FileReader("wordsIntermediate.txt");
FileReader readerHard = new FileReader("wordsHard.txt");
use a Scanner object called "in*" to access the respective file handle.
Scanner inEasy = new Scanner(readerEasy);
Scanner inIntermediate = new Scanner(readerIntermediate);
Scanner inHard = new Scanner(readerHard);
Use a loop to walk through the input file WordsEasy.txt reading one line at a time.
while (inEasy.hasNext())
String record = inEasy.next();
listEasy.add(record);
Use a loop to walk through the input file WordsIntermediate.txt reading one line at a time.
while (inIntermediate.hasNext())
String record = inIntermediate.next();
listIntermediate.add(record);
Use a loop to walk through the input file WordsHard.txt reading one line at a time.
while (inHard.hasNext())
String record = inHard.next();
listHard.add(record);
inEasy.close();
inIntermediate.close();
inHard.close();
set ListEasy's size
public int setListEasySize()
listEasySize = listEasy.size();
set ListIntermediate's size
public int setListIntermediateSize()
listIntermediateSize = listIntermediate.size();
set ListHard's size
public int setListHardSize()
listHardSize = listHard.size();
public int setGeneratorLength(int difficultyLevel)
if (difficultyLevel == 3)
generatorLength = listHardSize - 1;
else if(difficultyLevel == 2)
generatorLength = listIntermediateSize - 1;
else
generatorLength = listEasySize - 1;
Picks a random word
@return
public int randWord()
Random generator = new Random();
wordArrayLocation = generator.nextInt(generatorLength);
public String getWord(int difficultyLevel)
if (difficultyLevel == 3)
word = listHard.get(wordArrayLocation);
else if(difficultyLevel == 2)
word = listIntermediate.get(wordArrayLocation);
else
word = listEasy.get(wordArrayLocation);
return word;
private String word;
private int wordArrayLocation;
private int generatorLength;
private int listEasySize;
private int listIntermediateSize;
private int listHardSize;
private ArrayList<WordArray> listEasy;
private ArrayList<WordArray> listIntermediate;
private ArrayList<WordArray> listHard;
}Here is what I have changed things to...
import java.util.Random;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.lang.String;
public class WordArray
public WordArray() throws FileNotFoundException
Creation of 3 word arrays based off of the desired level of game difficulty
//open the physical files (words*.txt) for use in the corresponding ArrayList
FileReader readerEasy = new FileReader("wordsEasy.txt");
FileReader readerIntermediate = new FileReader("wordsIntermediate.txt");
FileReader readerHard = new FileReader("wordsHard.txt");
use a Scanner object called "in*" to access the respective file handle.
Scanner inEasy = new Scanner(readerEasy);
Scanner inIntermediate = new Scanner(readerIntermediate);
Scanner inHard = new Scanner(readerHard);
Use loops to walk through the input file reading one line at a time.
while (inEasy.hasNext())
String record = inEasy.next();
listEasy.add(record);
while (inIntermediate.hasNext())
String record = inIntermediate.next();
listIntermediate.add(record);
while (inHard.hasNext())
String record = inHard.next();
listHard.add(record);
inEasy.close();
inIntermediate.close();
inHard.close();
set the size of of the arraylists to a variable.
public void setListEasySize()
listEasySize = listEasy.size();
public void setListIntermediateSize()
listIntermediateSize = listIntermediate.size();
public void setListHardSize()
listHardSize = listHard.size();
//Set the difficulty level from user input
public void setDifficultyLevel(int difficulty)
difficultyLevel = difficulty;
//Calculate the wanted randomm generator length depending on the difficulty level
public void setGeneratorLength()
if (difficultyLevel == 3)
generatorLength = listHardSize - 1;
else if(difficultyLevel == 2)
generatorLength = listIntermediateSize - 1;
else
generatorLength = listEasySize - 1;
// Calculates what random arraylist location to pull an object from
public void randWord()
Random generator = new Random();
wordArrayLocation = generator.nextInt(generatorLength);
Sets the selected arraylist object to another object
public void setWordObject()
if (difficultyLevel == 3)
wordObject = (listHard.get(wordArrayLocation));
else if(difficultyLevel == 2)
wordObject = listIntermediate.get(wordArrayLocation);
else
wordObject = listEasy.get(wordArrayLocation);
returns the word
@return
public String getWord()
word = wordObject.toString();
return word;
private ArrayList<String> listEasy = new ArrayList<String>();
private ArrayList<String> listIntermediate = new ArrayList<String>();
private ArrayList<String> listHard = new ArrayList<String>();
private String word;
private Object wordObject;
private int difficultyLevel;
private int wordArrayLocation;
private int generatorLength;
private int listEasySize;
private int listIntermediateSize;
private int listHardSize;
}Edited by: jojavawuz on Nov 19, 2008 8:34 AM -
I am receiving the following errors:
incompatible types
found: int
required: boolean
if (accessCode = 8345)
if (accessCode = 55875)
if (accessCode = 999909)
I do not understand why I am getting the errors. accessCode is of type int.
Thanks in advance for any input.
int accessCode = Integer.parseInt( String.valueOf(
securityCodeJPasswordField.getPassword() ) );
int code;
if (accessCode >= 1645 && accessCode <= 1689)
code = 1;
else
if (accessCode = 8345)
code = 2;
else
if (accessCode = 55875)
code = 3;
else
if (accessCode = 999898)
code = 4;
else
if (accessCode >= 1000006 && accessCode <= 1000008)
code = 5;
else
if (accessCode < 1000)
code = 6;
else
code = accessCode;Thanks !! I am stuck in the coding syntax that I use in my job: SAS
-
Incompatible Types... NOT!
Why am I getting incompatible types in this method?
C:\jdk1.3\src\CalcBusinessDays.java:53: incompatible types
found : java.util.Date
required: Date
Date covDate = sdf.parse(dt, pos);^ <-- carat is at end of line
public Date dateConvert(String dt) {
SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
ParsePosition pos = new ParsePosition(0);
Date covDate = sdf.parse(dt, pos);
return covDate;
} //dateConvert
Thanks in advance.Actually I'm in Hartford, CT, where NJ sends its rain! I used to live in Staten Island which is close to NJ as you know. Also worked in Parsippany for a while.
I think "Date" needs to be changed to "java.util.Date" in three places. See comments below where changes are marked. I could not compile or test because I don't have Domino / Notes.
By the way, in case you get similar problems with another class (Calendar?), I believe that the lotus.domino classes are AgentBase, AgentContext, Session and DateTime. The others should be standard Java classes. Good Luck.
import java.util.*;
import java.text.*;
import java.math.*;
import lotus.domino.*;
public class CalcBusinessDays extends AgentBase {
public void NotesMain() {
DateTime startTime = null, endTime = null;
String startTimeStr, endTimeStr, result;
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
startTimeStr = "04/12/2000";
endTimeStr = "05/04/2000";
startTime = session.createDateTime(startTimeStr);
endTime = session.createDateTime(endTimeStr);
result = diffInWeekdays(startTime, endTime, startTimeStr,
endTimeStr);
System.out.println("Result = " + result);
} catch(Exception e) {
e.printStackTrace();
} //NotesMain
public String diffInWeekdays(DateTime startTime, DateTime endTime, String startTimeStr, String endTimeStr) {
String res = "";
try {
Date firstDate = null, secondDate = null;
int diffInt = endTime.timeDifference(startTime);
int diffIntDays = (diffInt / 86400 + 1);
BigInteger sev = BigInteger.valueOf(7);
BigInteger minusTwo = BigInteger.valueOf(-2);
BigInteger bis = BigInteger.valueOf(getWeekday(firstDate = dateConvert(startTimeStr)));
BigInteger bie = BigInteger.valueOf(getWeekday(secondDate = dateConvert(endTimeStr)));
int strtDay = bis.mod(sev).intValue();
int endDay = bie.mod(sev).intValue();
int max = minusTwo.max(BigInteger.valueOf(strtDay * -1)).intValue();
int min = BigInteger.valueOf(1).min(bie.mod(sev)).intValue();
int result = (diffIntDays - endDay + strtDay - 8) * 5 / 7 - max - min + 5 - strtDay + endDay;
//o.println("result =\t" + result);
res = Integer.toString(result);
} catch (Exception e) {
e.printStackTrace();
return res;
} //diffInWeekdays
public java.util.Date dateConvert(String dt) { // *** changed
SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
ParsePosition pos = new ParsePosition(0);
java.util.Date covDate = sdf.parse(dt, pos); // *** changed
return covDate;
} //dateConvert
public int getWeekday(java.util.Date cdt) { // *** changed
Calendar cal = Calendar.getInstance();
cal.setTime(cdt);
return cal.get(Calendar.DAY_OF_WEEK);
} //getWeekday
} //CalcBusinessDays -
Error in Parser.fx file "incompatible types found : java.util.Properties"
Hi,
In parser file "Parser.fx",
public-read def PROPERTIES_PARSER = StreamParser {
override public function parse(input : java.io.InputStream) : RecordSet {
var props = javafx.util.Properties {};
props.load(input);
input.close();
MemoryRecordSet {
records: [
MapRecord {
fields: props
due to under line portion an error is appearing:
"incompatible types
found : javafx.util.Properties
required: java.util.Map
fields: props".
Please suggest some solution.
Thanks in advance.
regards,
Choudhary Nafees Ahmed
Edited by: ChoudharyNafees on Jul 5, 2010 3:48 AMParser.fx
package org.netbeans.javafx.datasrc;
import javafx.data.pull.PullParser;
import javafx.data.pull.Event;
import org.netbeans.javafx.datasrc.MemoryRecordSet;
public-read def PROPERTIES_PARSER = StreamParser {
override public function parse(input : java.io.InputStream) : RecordSet {
var props =java.util.Properties{};
props.load(input);
input.close();
MemoryRecordSet {
records: [
MapRecord {
fields: props
public-read def LINE_PARSER_FIELD_LINE = ".line";
public-read def LINE_PARSER = StreamParser {
override public function parse(input : java.io.Reader) : RecordSet {
var line : String;
var result : Record [] = [];
line = readLine(input);
// BEWARE ("" == null) is true
while (line != null or "".equals(line)) {
var map = new java.util.HashMap();
map.put(LINE_PARSER_FIELD_LINE, line);
var record = MapRecord {
fields: map
insert record into result;
line = readLine(input);
MemoryRecordSet {
records: result
function readLine(in : java.io.Reader) : String {
var str = new java.lang.StringBuilder;
while (true) {
var c = in.read();
if (c == -1) {
return if (str.length() == 0) then null else str.toString();
} else if (c == 0x0D) {
c = in.read();
if (c == 0x0A or c == -1) {
return str.toString();
str.append(0x0D);
} else if (c == 0x0A) {
return str.toString();
str.append(c as Character);
str.toString()
public-read def JSON_PARSER = StreamParser {
function toSequence(list : java.util.List) : Record [] {
var result : Record [] = [];
var ii = list.iterator();
while (ii.hasNext()) {
var r = ii.next() as Record;
insert r into result;
result
override public function parse(input : java.io.InputStream) : RecordSet {
var topLevel : Object;
def parser = PullParser {
documentType: PullParser.JSON
input: input
var mapStack = new java.util.Stack();
var currentMap : java.util.Map;
var recordsStack = new java.util.Stack();
var currentRecords : java.util.List;
var lastEvent: Event;
onEvent: function(event: Event) {
if (event.type == PullParser.TEXT) {
currentMap.put(event.name, event.text)
} else if (event.type == PullParser.INTEGER) {
currentMap.put(event.name, event.integerValue)
} else if (event.type == PullParser.NULL) {
currentMap.put(event.name, null)
} else if (event.type == PullParser.START_ELEMENT) {
if (lastEvent.type == PullParser.START_ARRAY_ELEMENT) return;
var oldMap = currentMap;
var temp = new java.util.HashMap();
temp.put(new Object(), null);
currentMap = temp;
currentMap.clear();
mapStack.push(currentMap);
if (topLevel == null) topLevel = currentMap;
if (oldMap != null) {
var mr = MapRecord {
fields: currentMap
if (event.name == "" and lastEvent.type == PullParser.START_VALUE) {
oldMap.put(lastEvent.name, mr)
} else {
oldMap.put(event.name, mr)
} else if (event.type == PullParser.START_ARRAY_ELEMENT) {
var temp = new java.util.HashMap();
temp.put(new Object(), null);
currentMap = temp;
currentMap.clear();
mapStack.push(currentMap);
var mr = MapRecord {
fields: currentMap
currentRecords.add(mr);
} else if (event.type == PullParser.END_ELEMENT) {
mapStack.pop();
if (not mapStack.empty()) {
currentMap = mapStack.peek() as java.util.HashMap;
} else {
currentMap = null;
} else if (event.type == PullParser.END_ARRAY_ELEMENT) {
if (lastEvent.type == PullParser.END_ELEMENT) return;
mapStack.pop();
if (not mapStack.empty()) {
currentMap = mapStack.peek() as java.util.HashMap;
} else {
currentMap = null;
} else if (event.type == PullParser.START_ARRAY) {
currentRecords = new java.util.ArrayList();
recordsStack.push(currentRecords);
if (topLevel == null) topLevel = currentRecords;
} else if (event.type == PullParser.END_ARRAY) {
var set = MemoryRecordSet {
records: toSequence(currentRecords)
currentMap.put(event.name, set);
recordsStack.pop();
if (not recordsStack.empty()) {
currentRecords = recordsStack.peek() as java.util.List;
} else {
currentRecords = null;
lastEvent = event;
parser.parse();
if (topLevel instanceof java.util.Map) {
var mr = MapRecord {
fields: topLevel as java.util.Map
MemoryRecordSet {
records: [mr]
} else {
// List
var rs = MemoryRecordSet {
records: toSequence(topLevel as java.util.List)
rs
parser.parse();
var mr = MapRecord {
fields: topLevel as java.util.Map
MemoryRecordSet {
records: [mr] -
Incompatible types in CMP .. How to read RAW
MY CMP bean has a few CMP fields which are of type byte[] in the database i
created dbfields having RAW datatype. Deployment is Successfull. but when i
try to create this CMP then the ejbexception is thrown and it is having a
nested exception SQLException Incompatible types
Please help"LJS Narayana" <[email protected]> wrote in message
news:[email protected]..
MY CMP bean has a few CMP fields which are of type byte[] in the databasei
created dbfields having RAW datatype. Deployment is Successfull. but wheni
try to create this CMP then the ejbexception is thrown and it is having a
nested exception SQLException Incompatible types
Please help
Maybe you are looking for
-
Apple TV (1st Gen) no longer appears in iTunes 10.
Hi there, my Apple TV (1st Gen) no longer appears in itunes 10. I have looked at as many of the forums as I can and I have followed all the advice to reset Apple TV, router and PC. No joy. I have then restored Apple TV, uninstalled and reinstalled it
-
Hi All, We have created sub-contracting P.O and while doing ME2O- create delivery. We are getting below error msg. Depending on the category of the delivery being created, the system needs the following transfer data: o Outbound delivery
-
Itunes won't open Windows Vista Home Premium 32 bit
Today I bought an Itouch 8GB. I downloaded iTunes to get the latest greatest version. I ran the program and agreed to everything, took all the defaults. However when I launch it I get nothing. Just an hourglass and then nothing. I did a system restor
-
IPhone 3gs reception and connection problems, HELP!
My iPhone 3GS is having mutiple issues, including battery life, making and receving calls, making and recieving texts, and connecting to the internet. Lots of calls that people try to make to me never show up, and ones that do drop. It takes a few tr
-
What is the probability to get the same public key twice?
when I encrypt a message using somebody's public key, what are the chances other person has generated the same key independently? Is it safe to identify a user with its public key?