Read-in Data From Bluetooth Transmitter

Mar 8, 2014

I have the following code which reads in data from a bluetooth transmitter, however the program is crashing upon read-in. The bluetooth connects to the device just fine, as indicated by the indicator LED on the transmitter. However during the read-in:

void beginListenForData()

is where the exception happens. Specifically, it is at the line

readBuffer[readBufferPosition++] = b;

However I don't know why it is crashing. My transmitter is sending 1 byte (0x02) at 9600 baud every 1 sec for testing purposes.
 
package com.example.bluetoothtest2;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;

[Code] ....

View Replies


ADVERTISEMENT

Writing A Program To Search Bluetooth Devices

May 2, 2014

Im trying to write a java program to search nearby bluetooth devices.. Im using Bluecove-glp-2.1.0 and bluecove 2.1.0..Im working on Ubuntu 13.04 LTS.I typend a code to get the local Device name..

public class BluetoothSearch {
public static void main(String[] args) {
LocalDevice ld= null ;
String name = ld.getBluetoothAddress();
System.out.print(name);
}
}

this is my code.. It returns me null. doesn't return me the local Device.

View Replies View Related

Bluetooth Client Program To Communicate With Micro Controller

Jan 30, 2014

I use a bluetooth module (dwengo) in combination with a microcontroller (PIC16F877A). I want write a bluetooth client program in java to communicate with the microcontoller. Examples of clients on internet do not work or give errors I cant'n resolve. There is one program ( SampleSPPClient ) that give no errors and shows the bluetooth devices present.

But when I choose my bluetooth module I got an error (Device does not support Simple SPP Service). I think that I have to use an other service of bluetooth but I don't know how to implement. Here is the program I tried to use ....
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Vector;
import javax.bluetooth.DataElement;

[Code] ......

View Replies View Related

Data Read From File And Being Placed Into Arrays

Feb 8, 2015

I am creating a program where it reads the data inside a file and then places this data into arrays. The file I created has numbers 1-30 in it, file named, testing1.txt .

I am unable to post my code, it redirects me to a 'Page not found' page.

The problem with my program is a variable that I have initialized, is being said its not being initialized.

View Replies View Related

How To Read In A File And Extract Data

Nov 15, 2014

I am supposed to read in a file and extract the data. I am trying to add a Long into an Array that I initialized. So this is how my method looks like :

Java Code:

public void readOSMWay(File osm){
try {
Scanner output = new Scanner(osm);
while(output.hasNext()){
String line = output.nextLine().replace("^s+","");
if(line.startsWith(" <way")){
Road way = new Road(line,true);

[Code]...

I am having problem with the else if block. I am supposed to add all the Long values into the array.

error: Java Code: The method add(Long) in the type ArrayList<Long> is not applicable for the arguments (String) mh_sh_highlight_all('java');

View Replies View Related

JSF :: How To Read / Insert Data Into Database

May 2, 2014

I need getting detailed examples about how I can read/insert into database using JSF code for its different components. I am a beginner in JSF and I have the basics, however, I need the best source which it has useful, easy and detailed steps to understand the techniques for connecting to the DB and how to insert or read data from the database.

I tried to search, but I found the lessons are not useful or not described in details.

View Replies View Related

Read CSV Files And Organize Data In Java?

Apr 13, 2014

I am trying to write a program that read from a csv file called matches.csv.

A single football match can end with a win or a draw: in first case the winner team get 3 points and the loser none, in the second case of draw each of the two teams get 1 point.

For example, the first line of the file matches.txt is as follow:

In the file it contains the following data.

17/08/2013ArsenalAston Villa13
24/08/2013Aston VillaLiverpool01

This means that a match has been played on the 17/08/2013 where Arsenal scored 1 goal while Aston Villa 3 goals: thus Arsenal got 0 points while Aston Villa 3 points.

How can I structure my output to make it make it read

Position Team Played Points
1 Aston Villa 2 3
2 Liverpool 1 3
3 Arsenal 1 0

import java.io.File;

import java.io.FileNotFoundException;
import java.util.Scanner;
 public class Teams { 
public static void main(String[] args) {
String fileName = "matches.csv";
File file = new File(fileName);

[code]....

View Replies View Related

Use Data Read From File To Create Instances?

Sep 10, 2014

"Write a program (save the program as ProductInventory.java) that will read data about 5 products from a text file (Products.txt. The program should use the data read from the file to create instances (objects) of Product.java(Use Product class as a Reference Type)."

I'm yet to discover how I will get the info from the textfile using scanners but I don't know how to "create instances of a reference type".

This is the code of Product.java that came with the exercise.

public class Product {
private String productCode = "";
private String productName = "";
private int quantity;
private String supplierName = "";
private String supplierAddress = "";
private double price;

[Code] .....

By the way, the exercise also required me to use the abstract class ProductLister. To be clearer, the text file is kinda like this:

54643
Rizer Mouse
Mark5s Merchandising
Marquee Mall
4
205.50
23412
Acer Ultrabook
JohnJade Merchandise
Cornal City
2
62200.00
93112
Dell Ultrabook
Octagon Marketing
Cornal City
3
68900.00
22126
Macbook Air Pro
Computerware Services
San Beda, Chad
2
93500.00

View Replies View Related

To Decrypt Data - File Containing Keys Is Not Being Read

Aug 27, 2014

I am developing a java code using netbeans for encryption decryption by RSA algorithm. Swings and file handling play a major role in these code. My encryption code is working nicely but the code for decryption is not since keys file is not being read. That is why variable mod and pri are getting null values and the following error stack is coming. I know where the problem is somewhere in void readkeys() function but cannot solve it.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.math.BigInteger.modPow(BigInteger.java:1579)
at rsakeydecryption1.RsaKeyDecryption.decryption(RsaKeyDecryption1.java:167)
at rsakeydecryption1.RsaKeyDecryption.read_output(RsaKeyDecryption1.java:294)
at rsakeydecryption1.RsaKeyDecryption.actionPerformed(RsaKeyDecryption1.java:330)

[Code] .....

My code for decryption is

package rsakeydecryption1;
import java.math.BigInteger;
import java.util.Random;
import java.io.*;
import javax.swing.*;

[Code] ....

View Replies View Related

Best Way To Read Data From CSV File Then Compare And Display

Jun 13, 2014

I have 3 csv files as follows -

author file columns - emailID | firstname | lastname
books file columns - title | isbn | author_email | description
magazine file Columns - title | isbn | author_email | releasedate

I need to display -

1) Based on the ISBN display all books and magazines
2) All books and magazines by an author
3) All books and magazines by title

I am using Buffered reader as of now -

String csvFileToRead = "csvFiles/authors.csv";
BufferedReader br = null;
String line = "";
String splitBy = ";";

[Code] ....

I am confused about how to proceed with multiple files. Here are the approaches that i have considered -

1) change string csv csvFileToRead to a string array -

String[] csvFileToRead = {"data/autoren.csv", "data/buecher.csv", "data/zeitschriften.csv"};

Pass each index each time to a method returning all rows but getting stuck with DS to use. I think ArrayList wont suffice since i need separated data. Should i use a 2D array? Do i need to read and store data in a DS in order to achieve the goal?

2) Should i make 3 different classes with getters and setters for authors, book and magazine?

View Replies View Related

Read CSV Files And Organizing Data In Java

Apr 14, 2014

I am trying to write a program that read from a csv file called matches.csv.

A single football match can end with a win or a draw: in first case the winner team get 3 points and the loser none, in the second case of draw each of the two teams get 1 point.

For example, the first line of the file matches.txt is as follow:

In the file it contains the following data.

17/08/2013 Arsenal Aston Villa 1 3
24/08/2013 Aston Villa Liverpool 0 1

This means that a match has been played on the 17/08/2013 where Arsenal scored 1 goal while Aston Villa 3 goals: thus Arsenal got 0 points while Aston Villa 3 points.

How can I structure my output to make it make it read

Position Team Played Points

1 Aston Villa 2 3
2 Liverpool 1 3
3 Arsenal 1 0

Java Code:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Teams
{
public static void main(String[] args)
{
String fileName = "matches.csv";

[Code] ....

View Replies View Related

How To Read Data From Random Access File

Jul 10, 2014

I have a random access file stream. I have below code I want to written data that is currently pointed by pointer till the end and display that data on System.out Stream but it is not working my code is

//Create a Random Access File
java.io.RandomAccessFile random=new java.io.RandomAccessFile("D:/input.txt","rw");
//Position the pointer to a seek
try {
random.seek(300);
long pointer=random.getFilePointer();
System.out.println("Current Pointer is:"+pointer);
int a;
while((a=random.read())!=-1) {
System.out.println(a);
}

Where am I wrong? Although it is returning actual position of pointer in pointer using

View Replies View Related

Read CSV File From Disk And Manipulate Data Inside

Nov 17, 2014

I need to read a csv file from the disk and manipulate the data inside. My problem is that if the csv (excel format) contains "" in any of it's values the whole string line gets saved/displayed incorrectly . For example for the line in the csv file :

1,393275,57319 57321 57323 57325 57327,5_5,200000,393277,57329 57331 57333 57335 57337,3_3,200000,400000,"gi,gi",,,,,,BASS/2.4,,1

it gets read in java as :

"1,393275,57319 57321 57323 57325 57327,5_5,200000,393277,57329 57331 57333 57335 57337,3_3,200000,400000,""gi,gi"",,,,,,BASS/2.4,,1";;;;

instead as :

1,393275,57319 57321 57323 57325 57327,5_5,200000,393277,57329 57331 57333 57335 57337,3_3,200000,400000,"gi,gi",,,,,,BASS/2.4,,1

My code is :

String csvFile = "resources/testcsxs.csv" ;
String l = "";
try {
BufferedReader cz = new BufferedReader(new FileReader(csvFile));
while ((l = cz.readLine()) != null ){
System.out.println(l);
}

What am i doing wrong , how can i read a csv file (excel saved) without getting "" added incorrectly ?

View Replies View Related

Read Text And Extract Data And Display It In JTables?

May 20, 2014

My problem is to read a text file which contains lines of text data

{e.g: #1115=CLOSED_SHELL(",(#166,#208,#250.....#1114));}

I need to break it and #numbers in braces are assigned to string array and they should cal by one by one. similarly next level on calling #166 same operation should perform

{#166=ADVANCED_FACE(",(#165),#129,.F.);}

like this 8 levels were there, finally at each level the Calling number should display in JTable.

View Replies View Related

How To Read Data From Text File And Place Into Array

Nov 15, 2014

I'm trying to figure out the necessary code for reading integers from a text file, then placing them withing the two-dimensional array I have created, and then finally printing the array using a nested for-loop. I have attached the file I would like to read from. I'm having trouble figuring out how to reference the text file with the integers, and also how to properly create a dynamic preface for each row of the array. I want the preface to display as "Week #: ", with # being the row number. I tried to create an integer to be used that way, but NetBeans tells me whatever integer I declare has already been defined in method main. I know I need to use scanner to read the file. I would like the output to display like this:

Quote
Temperature Data

Week 1: 73 71 68 69 75 77 78
Week 2: 76 73 72 72 75 79 76
Week 3: 79 82 84 84 81 78 78
Week 4: 75 72 68 69 65 63 65

View Replies View Related

Second Packet Read From Input Stream Has Incomplete Data

May 8, 2015

I a simple server that receives bytes using TCP and then saves them to a file stream.Through many tests I have seen that the first packet received is always just the filename with no other data. The second packet received only has one byte and it is the first letter of the input text file. After this all packets are sent correctly, but I can't seem to figure out what is messing up the second packet. It also appears that the last packet is written twice.

Here is an example Input/Output: [URL] .....

InputStream in = clntSock.getInputStream(); //server's input stream - gets data from the client
OutputStream out = clntSock.getOutputStream(); //server's output stream - server sends data to the client
byte[] byteBuffer = new byte[BUFSIZE];
int count = in.read(byteBuffer, 0, BUFSIZE);
String firstRead = new String(byteBuffer, 0, count);

[Code] ....

Another peculiarity to me is that the second to last packet is always just "-" and then the last packet has the remainder of the magic string which terminates the file output stream.

I am aware that it is not safe to make the assumption that the file name will be sent in one go before the loop, but I wil fix that later. I am not concerned about it at all now. THe problem si that the loop should account for any amount read in, but for some reason the first packet always contains one letter, and the second packet picks up around 16000 bytes later for some reason. Why would this be?I can't edit my above post so here is the code with code tags.

InputStream in = clntSock.getInputStream(); //server's input stream - gets data from the client
OutputStream out = clntSock.getOutputStream(); //server's output stream - server sends data to the client
byte[] byteBuffer = new byte[BUFSIZE];
int count = in.read(byteBuffer, 0, BUFSIZE);
String firstRead = new String(byteBuffer, 0, count);

[Code] ....

View Replies View Related

Converting Primitive Data Types To Read Integers With Decimal

Sep 13, 2014

I get an error when I try to divide 500 miles by 25.5 gallons

Exception in thread "main" java.lang.NumberFormatException: For input string: "25.5"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at Mileage.main(Mileage.java:42)
Java Result: 1

[Code] .....

View Replies View Related

Error In Program To Read Int Or Float Type Data From Keyboard

Aug 9, 2014

Here is a code and error .....

View Replies View Related

Java For Data Carving - How To Read Any Of Known Digital Forensics Image

Sep 26, 2014

I am looking to do it on data carving which is a technique used in digital forensics to extract known file information from unstructered raw data.

So, Lets say I make a bit for bit image of a usb drive that has some deleted images on it, jpeg maybe.

I can still recover this file by locating its header and footer information as its raw data is still on the drive after it has been deleted.

I would like to build a java application to automate this task. My problem is I dont know how to read any of the known digital forensics image (bit for bit copy of the driv) formats such as aff, e01 or raw dd.

Is it possible for me to read bytes from a raw data file in java, maybe search that file for the bytes I need and pull them out of there, perhaps to an array or something ??

I was thinking, if I could get all the raw data into a binary file in java it might be easier to work from there. What I really need is to get access to those bytes. If I could even write them all out to a text file, Id have something to work with.

View Replies View Related

Java Servlet :: Read Data From Excel File To Table

Oct 19, 2014

If I want to load data in excel file into table. what is the best way to do it?

View Replies View Related

I/O / Streams :: Reading From And Writing To A File Then Read Again Including Data Written

Oct 11, 2014

I'm having a bit of trouble with using the Scanner and the Printwriter. I start with a file like this (1 = amount of Houses in the file)

1
FOR SALE:
Emmalaan 23
3051JC Rotterdam
7 rooms
buyprice 300000
energylevel C

The user gets (let's say for simplicity) 3 options:

1. Add a House to the file,
2. Get all Houses which fullfil requirements (price, FOR SALE / SOLD etc.) and
3. Close the application.

This is how I start:

Scanner sc = new Scanner (System.in);
while (!endLoop) {
System.out.println("Make a choice);
System.out.println("1) Add House");
System.out.println("2) Show Houses");
System.out.println("3) Exit");
int choice = sc.nextInt();

Then I have a switch for all of the three cases. I keep the scanner open, so Java can get the user input (house = for sale or sold, price = ... etc). If the user chose option 1, and all information needed is inputted and scanned, the House will be written to the file (which looks like what I typed above).

For this, I use try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("Makelaar.txt", false)))). This works perfectly (at least so it seems.)

If the user chose option 1, and all requirements are inputted and scanned, the Houses will be read (scanner) from the file and outputted. For this I use the same Scanner sc. This also works perfectly (so it seems atleast).

My problem is as follows: If a House has been added, I can only read the House(s) which were already in the file. Let's say I have added 2 houses, and there were from the start 3 houses. If option 2 is chosen, the first 3 houses will be scanned perfectly. An exception will be caught for the remaining 2 (just added) Houses. How can I solve this? I tried to close the Scanner, and reopening it, but apparently Java doesn't agree with this

View Replies View Related

Read Data From File And Place Larger Of Two Numbers In Corresponding Position Of Third Array

Apr 14, 2015

I am learning about arrays in my class and my professor has a habit of throwing in code without explaining. We are doing a program called storing largest numbers where we read data from a file and place the larger of the two numbers in the corresponding position of a third array. They are in 4 by 4 format. Here is the ending code

import java.io.*;
import java.util.*;
public class prog464aStoringLargestNums
{
public static void main(String[] args)

[code]....

View Replies View Related

Hurricane Java Project - Read Information From Data File And Run It Through But Program

Dec 2, 2014

I am now stuck. I am writing a program that reads information from a data file and runs it through but program. However, I am almost finished with the program, but cannot figure out the last few parts.

public class Storm {
private final double KnotsToMPH = 1.15;
// global user-defined types:
private int beginDate;
private int duration;
private String name;

[Code] .....

I have not attached the data file because it contains a total of 360 lines of hurricane information.

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

Create A Java Program That Can Read Specific Data Within Csv File To Work Out Averages

Aug 7, 2014

i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..

[CSV FILE]

year ,month,average rainfall etc

1946 15.70.616108.131.5
1946 28.23.56111.871
1946 38.82932.9 102.9
1946 414.16.3029.2 150.5
1946 513.96060.7 143.6

[code]...

I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.

View Replies View Related

Read Date From File / Calculate And Then Displays That Data In Table Format On Screen

Apr 22, 2015

The intent of the code is to read date from a file, does calculation and then displays that data in a table format on the screen. Then creates another file with those values:

Reads file: Beginningbalance.txt
Displays Data with calculation
Creates a file called "Newbalance.txt" with the following values:

111
251.41
222
402.00

With the way the code is written I can get it to create the file but it only displays one of the customers (111). I know that I need to create a loop but I am not sure how to build that. I tried creating another while loop and changing it to outFile but that was without success.

import java.io.*;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Output {
public static void main(String[]args) throws IOException {

[Code] .....

View Replies View Related







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