Compile Error - Cannot Cast From Integer To Byte

May 29, 2014

I have a msg object that contains an ArrayList<Integer> collection. However, in order to send the elements in the array over the udp socket, it needs to be sent as a byte[] array. So why am I using ArrayList<Integer> over byte array in first place? Well when I receive data from socket from embedded c program, I need to get an unsigned representation of the data, and thus I need to store it in integers, since bytes in Java are unsigned and unsigned chars in c that are greater than 127 will yield incorrect values in java. But when I send an ack back over the socket, I need to send the data back as bytes. So I convert the ArrayList<Integer> to a byte array:

Java Code: byte[] data = msg.toByteArray();
DatagramPacket response = new DatagramPacket(data, data.length,
packet.getAddress(), packet.getPort());
public class Gprs {
...
public byte[] toByteArray(){

[Code] ....

The problem is I get an "Cannot cast from Integer to byte" when trying to cast the integer to byte: data[i] = (byte)m_data.get(i);

How can I resolve this?

View Replies


ADVERTISEMENT

Compile Error Using HashMap

Feb 9, 2015

I am a C# developer but need to do some java development. The code produces the following error.

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
...
HashMap<String, String > myMap = new HashMap<String, String>(){{
put("a","b");
}};
myMap.put("foo", "bar");
myMap.put("Sna", "foo");
...

Generates this error

C:/FSC/apache-tomcat-6.0.41/webapps/aspen/temp/x2_8656248460570782763/x2_5214718769032742331/StudentExport.java:47: error: <identifier> expected
myMap.put("foo", "bar");
^

What am I missing?

View Replies View Related

Cannot Find Symbol Compile Error

Jul 23, 2014

programming altogether and after almost reaching half way in the 'Head first java' book I decided to try and apply some of what I've learnt so far and write my first 'Object orientated' program. As this is pretty much the first program I've ever written, I decided to write a program to ask for two integers and add them both together and then present them to the user (the goal eventually being a basic fully working command line calculator with +,-,* and /. I'm expecting many compile errors but not the following errors below.

I have three .java files contained within a folder and after trying to figure out how to compile all three files (as they use one another) all at once, I came across this ---> javac *.java

so I typed this in the command line whilst in the directory containing the three files assuming *.java is the best approach and then I receive the following errors:

inputOutput.java:10: error: cannot find symb
c.addition() = intIn.nextInteger();
^
symbol: variable c
location: class inputOutput

[Code].....

View Replies View Related

Compile Error In Line Bufferedreader

Sep 24, 2014

import java.util.*;
import java.lang.*;
class Bank {
String name;
float acc_no,balance;
void accept(String str, float no, float bal)

[code]....

View Replies View Related

Compile Error - Empty String?

Jul 1, 2014

I'm writing basically my first program for school. I've written small ones, following instructions, but this is the most vague. I'm having issues. I can't figure out what the error means. I'm not done with the code, but I think the ArrayList is throwing me off. I'm trying to gather user input and sum the total. Here's the code:

package graduationplanner;
import java.util.ArrayList;
import java.util.Scanner;
import java.lang.Double;
 public class GraduationPlanner {
public static void main(String[] args) {

[Code] ....

View Replies View Related

Compile Error When Running JGrasp

Feb 3, 2015

I keep getting the error Admit.java:10 cannot find symbol

import java.util.*;
public class Admit {
public static void main(String[] args) {
sayIntro();
Scanner console = new Scanner(System.in);
System.out.println("Information for applicant #1:");
getScore(console);
getGPA(console);

[Code] ....

The compiler then reads:

Admit.java:10: error: cannot find symbol
score1(ACTScore, SATScore, GPAScore);
^
symbol: variable ACTScore
location: class Admit
Admit.java:10: error: cannot find symbol

[Code] .....

10 errors

View Replies View Related

Compile Error In Hello Java Program

Dec 23, 2014

i wrote this program:

class hellojava
{
public static void main(string[] args)
{
system.out.println("hello java");
}
}

Then i saved this file with name hellojava.java(notepad) in C drive in separate folder c:myjavaapp(not in c:java folder).

When I am compiling(with javac hellojava.java) it shows following error:

cannot find symbol public static void main(string[] args), and also says package system doesnot exists system.out.println("hello java");

View Replies View Related

Compile Error - Code Uses Or Overrides Deprecated API

Feb 24, 2014

I found an error in these code when I compile it

"uses or overrides a deprecated api"

Java Code :

import oauth.signpost.OAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
 import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
public class JavaRestTweet {

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Compile Error - Cannot Find Symbol With SetDefaultCloseOperation

Jul 21, 2014

This is likely a simple matter, but my error is confusing given the line it flags matches a working project I have. I get the following error on line 6 in the Controller:

cannot find symbol
v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
...........................................^
(carrot at the J)

My view file:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class View extends JFrame{
private JLabel lbl;
private JButton btn;

[Code] ....

View Replies View Related

Amount Of Money - Compile Error / Unreachable Statement

Feb 14, 2014

This method accepts 1 integer, amount (the amount of money). Output the minimum number of in quarters, dimes, nickels and pennies used to make up the amount. For example, an amount of 32 would require 1 quarter, 1 nickel and 2 pennies.

This is the question^

My codes are:

public static int change (int amount) {
int quarters = amount / 25 ;
int firstresult = amount % 25 ;
return quarters ;
int nickel = firstresult / 5 ;

[Code] .....

The codes were working when i used System.out.println instead of return, but our teacher required us to use return (functions).

I get the compile error: Unreachable statement.

View Replies View Related

Grading System Program - No Syntax Error But Got Compile Errors

May 23, 2015

Netbeans do not detect any syntax errors, but I when I check the build it retuned areas they were a few; It's a simple program name 5 people, gade them then do final calulatoins it's called "grade tool.

heres the code

package gradingapplication;
import java.util.Scanner;
public class GradingApplication {
public static double score(double score){
if(score >= 90){
System.out.println("A");

[code]...

~Problems~

1. It has no gui, I don't know java fx, is java groove used? awt is useful for creating spam bots in robot class, I know it's not very useful but it's so much fun.

2. the sections where I use the scanner.

View Replies View Related

Overriding In Java - Foo Method Of Class X Is Not Throwing Compile Error

Jul 29, 2013

class SubB{
public void foo(){
System.out.println(" x");
}
}
public class X extends SubB {
public void foo() throws RuntimeException{
super.foo();
if(true) throw new RuntimeException();
System.out.println(" B");
}
public static void main(String [] args){
new X().foo();
}
}

Why the foo method of class X is not throwing a compile error because according to the override rule, if the superclass method has not declared exception, the subclass method can't declare a new exception...

View Replies View Related

Compile Time Error - Cannot Invoke Read On Primitive Data Type Int

Jul 10, 2014

I have a code in which I am reading input from System.in and Destination is some where else

Here is my code

File file=new File("D:/output.txt");
OutputStream os=new java.io.FileOutputStream(file);
Scanner scanner=new Scanner(System.in);
System.out.println("Enter Data to write on File");
String text=scanner.nextLine();
int c=Integer.parseInt(text);
int a;
while((a=c.read())!=-1)
os.write(a);
System.out.println("File Written is Successful");

In the line while((a=c.read())!=-1)

a compile time error is shown "cannot invoke read on primitive data type int"

Where I am going wrong?

View Replies View Related

Check For Upper Case Letters From User Input - Cannot Find Symbol Compile Error

Apr 15, 2015

I decided to code this quiz I took in class about asking the user to input a string and the code is suppose to check for upper case letters. If a upper case letter is found, it should increase a count by one. Once the check is done, it should display the number of uppercase letters. For some reason I am getting this weird compile error stating that symbols can't be found...

Java Code:

import java.util.*;
import java.lang.*;
public class StringCheck{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("please enter a string: " );
String s = input.nextLine();

[Code] ......

View Replies View Related

Using Static Method To Convert A String To Integer Object - Compiler Error

Mar 1, 2014

I am using a static method to convert a string to an Integer object. Next using a instance method to convert Integer object to an int.

Compiler is giving me two "cannot find symbol" errors:

One pointing to the dot operator between "Integer.valueOf(s)"

The other pointing to the dot operator between "obj.intValue()"

I have latest JDK installed: jdk-7u51-windows-x64.exe

Looks like JCL installed correctly with rt.jar file located in "lib" directory under "Program Files"

Following is source code:

Java Code:

public class StringToInt
{
public static void main (String args [])
{
String s = "125";
Integer obj = Integer.valueOf(s);
int i = obj.intValue();
i += 10;
System.out.println(i);
}
} mh_sh_highlight_all('java');

View Replies View Related

Trying To Cast One Object As Another

Oct 13, 2014

Im trying to loop through a hashmap of objects. They are defined as People objects. People has two subclasses , Instructor and Student. As I am looping through the map of People, I am searching for class Instructor. If I find it, I want to access its method getDepartment in a println by casting to Instructor. When I do I get a runtime error:

Exception in thread "main" java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to uStaff.Instructor
at uStaff.PersonApp.menu(PersonApp.java:108)
at uStaff.PersonApp.main(PersonApp.java:21)

//Instantiate the different Person, student and instructor objects
Person thisPerson = new Person(01,fName,mName,lName,email,ssn,age);
Student thisStudent = new Student(02,"Stacey","Marie","Morgan","smorgan@gmail.com","213-45-6789",20);
thisStudent.setMajor("music");
Instructor thisInstructor = new Instructor(03,"Joe","Douglass","Wells","joe@drumhaven.com","555-98-3029",46);
thisInstructor.setDepartment("Computer Science");

[code]....

View Replies View Related

Cannot Cast From Object To Double

Nov 9, 2014

ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("js");
String expres = calc.getText().toString();
calc.setText(expres);
try {
calc.setText(((double)engine.eval(expres)) + "");
} catch (Exception e) {
}

This line: calc.setText(((double)engine.eval(expres)) + "");

*The error message for this line: Cannot cast from object to Double

View Replies View Related

Cast 2D Array To ArrayList

Jan 23, 2014

I ve got a 2d array and I want to cast it in an 2d arraylist. I ve create a function that cast an array to arraylist. My problem arises, when I tried to parse the whole 2d matrix to the arraylist. I use the following code:

Java Code: double sums[][] = computeSums(lab, projections);
ArrayList<ArrayList<Double>> lists = new ArrayList<ArrayList<Double>>();
ArrayList<Double> nu = new ArrayList<Double>();
System.out.println(sums[0].length);
for (int i = 0; i < sums.length; i++) {

ArrayList<Double> tt = toList(sums[i], nu);
lists.add(tt);
} mh_sh_highlight_all('java');

The problem is that only the first matrix sums[0] is copied to the 2d arraylist sums.length times. How is is possible to store all the different sums matrices to the arraylist??

View Replies View Related

JSP :: Cannot Cast From String To ArrayList

Apr 30, 2012

I'm actually trying to complete the excersise of the Servlets and JSP book in page 303 but I'm getting the following error in Eclipse Cannot cast from String to ArrayList(JSP).Here is the code

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hobbies Sharing</title>
</head>

[code]...

The error as it appears in line <% ArrayList al = (ArrayList)request.getParameter("Names"); %>

View Replies View Related

Cannot Cast From File To String

Jan 24, 2014

I have Java code that iterates through files in a directory like this:

for (File child : dir.listFiles()) {
}

Inside that for loop I want to put the filename into a HashMap like this: autocompleteMap.put((String)child,itemList);

The java compiler doesn't like my cast attempt: "Cannot cast from File to String".How do I convert the filename into a String to put into my hash?

View Replies View Related

When Does Internal Cast Actually Happen

Nov 3, 2014

When does an internal cast actually happen? I am aware that compound assignment operator do an internal cast. Does it happen in Assignment 1?Assignment 2?Assignment 3?Assignment 4?

Java Code:

public class Parser{
public static void main( String[] args){
byte b=1;
short s=1;
int i=1;
s=b;//Assignment 1
s<<=b;//Assignment 2
b<<=s;//Assignment 3
s +=i;//Assignment 4
}
} mh_sh_highlight_all('java');

View Replies View Related

String Cannot Be Cast To Boolean

Apr 6, 2014

JAVA CODE:

package gui.dialog;

import cli.data001;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;

[Code] ....

OUTPUT:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at javax.swing.plaf.synth.SynthTableUI$SynthBooleanTa bleCellRenderer.getTableCellRendererComponent(Synt hTableUI.java:731)
at javax.swing.JTable.prepareRenderer(JTable.java:573 1)
at javax.swing.plaf.synth.SynthTableUI.paintCell(Synt hTableUI.java:684)

[Code] ....

View Replies View Related

Need Cast For Covariant Method

May 21, 2014

import java.util.ArrayList;
 public class Demo {
        class Expr {}
        abstract class Factory <T extends Expr> {
                abstract T generate();

[Code] ....

Doesn't Factory2 produce Statements?

View Replies View Related

Using Byte Instead Of Int?

Jan 1, 2015

Is there an advantage in using byte instead of int beyond the space savings? In my program, I'll never need close to the max value of a byte, let alone int, so it seems like a waste to make my primitives ints.

View Replies View Related

How To Cast Floating Point Number To Int

Jan 7, 2015

the output of this:

int x = (int) 24.6;

View Replies View Related

JSP :: JSTL And EL - Long Value Cast To String

Mar 27, 2015

I'm trying to write a condition to jstl if tag,

<c:forEach var="ledg" items="user_ledgers">
<c:if test="${ledg.transactionID == param['trns']}">
<c:out value="${ledg.name}"/>
</c:if>
</c:forEach>

Ledg is an object of ledger class and transactionID is a field of type long.

I found this error while runtime.

javax.el.PropertyNotFoundException: Property 'transactionID' not found on type java.lang.String

I tried to convert transactioID value to String by several ways. But not working.

String concatenation
<c:if test="${(ledg.transactionID+’’) == param['trns']}">
Using custom tag
<c:set var="equals" scope="page">
<z:doTheyEquals v1="${ledg.transactionID}" v2="${param['trns']}"/>
</c:set>

It also expects String type.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved