java-me

How to filter an array in Java?

偶尔善良 提交于 2019-11-27 23:12:29
问题 How can I filter an array in Java? I have an array of objects, for example cars: Class: public class Car{ public int doors; public Car(int d){ this.doors = d; } } Use: Car [] cars = new Cars[4]; cars[0] = new Car(3); cars[1] = new Car(2); cars[2] = new Car(4); cars[3] = new Car(6); Now I want to filter the array of cars, keeping only 4 doors and more: for(int i = 0; i<cars.length; i++){ if(cars[i].doors > 4) //add cars[i] to a new array } } How should I do this? Before I did it with a Vector:

Stop thread and again start giving IllegalThreadStateException in blackberry

╄→гoц情女王★ 提交于 2019-11-27 23:00:46
I am getting IllegalThreadStateException exception when using following code: I have already started this thread once(by using thread.start() ) and again trying to start it at another place, so used following code: thread.interrupt(); thread.start(); But thread.start() is throwing IllegalThreadStateException . What should I use to solve it? Thread objects are only meant to be started once. If you need to stop/interrupt a Thread , and then want to start it again, you should create a new instance, and call start() on it: thread.interrupt(); // if you need to make sure thread's run() method stops

J2ME/Blackberry - how to read/write text file?

女生的网名这么多〃 提交于 2019-11-27 19:30:16
please give me a sample code for read/write text file in blackberry application. Maksym Gontar My code snippet for string read/write files: private String readTextFile(String fName) { String result = null; FileConnection fconn = null; DataInputStream is = null; try { fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE); is = fconn.openDataInputStream(); byte[] data = IOUtilities.streamToBytes(is); result = new String(data); } catch (IOException e) { System.out.println(e.getMessage()); } finally { try { if (null != is) is.close(); if (null != fconn) fconn.close(); } catch

AES Encryption/Decryption with Bouncycastle Example in J2ME

懵懂的女人 提交于 2019-11-27 19:12:15
i want to Encrypt and Decrypt data in J2ME using AES Algorithm with bouncy castle can any one give me sample code for that i want to use ECB with PKCS5Padding Thanks in Advance. I'm sure there are examples out there but I haven't found them. Here are a few hints to help you get started. You need to learn how to connect the BC classes together. First, get the bouncycastle source code and be prepared to look at it when you have questions. It's actually very readable so don't be afraid to examine it when the documentation is poor. For example, many classes want an instance of a CipherParameters

Java Convert Object[] Array to Vector

牧云@^-^@ 提交于 2019-11-27 18:05:07
问题 What's the best way to convert an Object array to a Vector? JDE < 1.5 public Vector getListElements() { Vector myVector = this.elements; return myVector; } this.elements is an Object[] Thanks, rAyt I should clarify my question My target platform is a blackberry. Collections aren't supported. Array.asList() isn't, either :/ Full Class package CustomElements; import net.rim.device.api.ui.component .*; import net.rim.device.api.collection.util.*; import net.rim.device.api.util.*; import java

How to use GPS indoors on a mobile device?

旧城冷巷雨未停 提交于 2019-11-27 16:55:07
问题 I am new to mobile applications. Basically I want to get the user's GPS coordinates indoors. I have no problem detecting the mobile device outdoors, only when indoors it is giving me problems. I have tried setting the accuracy, but no avail. Is there a solution to it? Here is my code: new Thread() { public void run() { try { Criteria cr= new Criteria(); cr.setHorizontalAccuracy(1000); LocationProvider lp= LocationProvider.getInstance(cr); Location l = lp.getLocation(60); Coordinates c = l

What does preverification of J2ME application mean?

时间秒杀一切 提交于 2019-11-27 16:05:29
问题 I read the following: J2ME applications, unlike normal Java applications are preverified. What exactly does the preverification of J2ME jar file mean? Is it something like checksum? 回答1: From here: Answer Preverification is a new phase in the development and deployment cycle for Java applications designed to run on the J2ME CLDC. Preverification performs certain checks on the Java bytecodes ahead of runtime. If this first verification pass is ok, the preverifier annotates the classfiles

What is the difference between strings allocated using new operator & without new operator in java J2ME?

我们两清 提交于 2019-11-27 15:46:09
what is the Difference between String str=new String("Thamilan"); and String str="Thamilan"; in java J2ME. In first case new object will be created always, in second case object from a string pool can be reused. Read more about String pool here: What is String pool? The difference is that the new String creates a new object with the same value as the literal passed in: String s = "abc"; String t = new String("abc"); System.out.println(s==t); //false String u = "abc"; String v = "abc"; System.out.println(u==v); //true This is because the literal are always from the internal pool. You might want

Can I compress HTTP Requests using GZIP?

天涯浪子 提交于 2019-11-27 14:54:58
问题 I am communicating to a Tomcat Server using a Java ME application on my mobile device. I was wondering if I could compress my requests/responses using Gzip to reduce the number of bytes sent over the network. 回答1: Modern phones have so much CPU power and the network is relatively slow so compression makes perfect sense. It's quite easy to do also. On the J2ME side, you do something like this (assuming you use HttpConnection), hc.setRequestProperty("Accept-Encoding", "gzip, deflate"); if (hc

Providing Java library, but hiding some classes

梦想的初衷 提交于 2019-11-27 14:49:37
问题 I am developing an application in Java ME that I want to provide as a library. Is there no way to hide classes that I don't want everyone to use, but is essential still in order for the library to work? UPDATE: I get that I can omit the public specifier, but how can I structure the library itself while developing without creating different packages? I like to view different packages as different folders simply which allows me to structure the code in a good way. However, in some cases I might