Loading screen in j2me - java-me

I want loading screen in my application such that it appear when the internet connection starts and loading screen get hide when I got the data from webservice.
I had tried to use .gif file. It is working properly in the simple application which I made which shows only .gif file. But when I integrate this code with my applicationj it is showing the error.
The error is:
TRACE: <at java.lang.IllegalArgumentException>, Exception caught in Display class
java.lang.IllegalArgumentException
at javax.microedition.media.Manager.createPlayer(), bci=8
at com.semaphore.GifCanvas.<init>(GifCanvas.java:41)
at com.semaphore.CompanySplashScreen.dismiss(CompanySplashScreen.java:89)
at com.semaphore.CompanySplashScreen.keyPressed(CompanySplashScreen.java:78)
at javax.microedition.lcdui.CanvasLFImpl.uCallKeyPressed(), bci=19
at javax.microedition.lcdui.DisplayableLFImpl.uCallKeyEvent(), bci=146
at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=30
at com.sun.midp.lcdui.DisplayEventListener.process(), bci=277
at com.sun.midp.events.EventQueue.run(), bci=179
at java.lang.Thread.run(Thread.java:619)
the code which i am using to for executing .gif file is:-
InputStream ins = getClass().getResourceAsStream("/loading.gif");
try {
player = Manager.createPlayer(ins, "image/gif");
player.prefetch();
player.setLoopCount(10);
player.start();
} catch (IOException ex) {
ex.printStackTrace();
} catch (MediaException ex) {
ex.printStackTrace();
}
if ((vidc = (VideoControl) player.getControl("VideoControl")) != null)
vidc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
try {
vidc.setDisplayLocation(2, 2);
vidc.setDisplaySize(getWidth()/2,getHeight()/2);
}
catch (MediaException me) {}
vidc.setVisible(true);
How can I resolve this?

According to the documentation, your InputStream is null.
Check if you have your resource properly placed. With that path, it should be on the root dir of your project (or the src dir, I'm not sure). But just check it.

Related

Axis fault : faultString: java.io.IOException for suitetalk

I am trying to use NetSuite's suiteTalk java api for writing an interface between our lotus notes system and NetSuite.
The first error thrown by the code was a class def not found error.
for :
sun/security.provider/sun.class
sun/security.provider/sun$1.class
sun/security.provider/NativePRNG.class
I figured out that rt.jar in lotus notes was actually missing this files. So I added these class files from the jdk1.6 i had downloaded separately. Once I fixed that I started getting axis.Faults error.
Here is the simple login code that I am trying to execute from lotus note agent:
public void loginTest(){
NetSuitePortType _port=null;
// In order to use SSL forwarding for SOAP message. Refer to FAQ for details
System.setProperty("axis.socketSecureFactory","org.apache.axis.components.net.SunFakeTrustSocketFactory");
// Locate the NetSuite web service
NetSuiteServiceLocator serviceLocator= new NetSuiteServiceLocator();
//Get the service port
try {
_port=serviceLocator.getNetSuitePort();
} catch (ServiceException e) {
System.out.println("Error in intializing GlobalSuiteTalkSetup");
e.printStackTrace();
}
// Setting client timeout to 2 hours for long running operatotions
((NetSuiteBindingStub) _port).setTimeout(60*60*1000*2);
try {
// Populate Passport object with all login information
Passport passport = new Passport();
RecordRef role = new RecordRef();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
passport.setEmail("username");
passport.setPassword("password.");
role.setInternalId("3");
passport.setRole(role);
passport.setAccount("111111");
// Login to NetSuite
System.out.print("\nLogging into NetSuite");
System.out.print(" Username: " + passport.getEmail());
System.out.print(" Account: " + passport.getAccount());
System.out.print(" password: " + passport.getPassword());
System.out.print(" role: " + passport.getRole());
Status status;
status = (_port.login(passport)).getStatus();
// Process the response
if (status.isIsSuccess() == true)
{
System.out.print("\nThe login was successful and a new session has been created.");
} else
{
// Should never get here since any problems with the
// login should have resulted in a SOAP fault
System.out.print("Login failed");
//System.out.print(getStatusDetails(status));
}
} catch (InvalidVersionFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidCredentialsFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InsufficientPermissionFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExceededRequestLimitFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnexpectedErrorFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidAccountFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Error thrown by code:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.io.IOException
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.io.IOException
at org.apache.axis.components.net.SunJSSESocketFactory.initFactory(SunJSSESocketFactory.java:88)
at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:79)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.netsuite.webservices.platform_2015_1.NetSuiteBindingStub.login(NetSuiteBindingStub.java:12799)
at Login.loginTest(Unknown Source)
at JavaAgent.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
{http://xml.apache.org/axis/}hostname:
java.io.IOException
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.netsuite.webservices.platform_2015_1.NetSuiteBindingStub.login(NetSuiteBindingStub.java:12799)
at Login.loginTest(Unknown Source)
at JavaAgent.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
Caused by: java.io.IOException
at org.apache.axis.components.net.SunJSSESocketFactory.initFactory(SunJSSESocketFactory.java:88)
at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:79)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
... 14 more
I found the solution for this issue. For anyone who might get similar issue can get some clue from this solution :
The issue was because of the following statement that I had put in the code.
System.setProperty("axis.socketSecureFactory","org.apache.axis.components.net.SunFakeTrustSocketFactory");
This statement is necessary when using Sun' JVM but since Lotus Notes uses IBM's JVM, setting axis.socketSecureFactory to org.apache.axis.components.net.SunFakeTrustSocketFactory made the system to look for Sun classes which not absent in IBM's JVM.
No need to add the missing classes from Sun JVM to rt.jat as I had done before. Just comment that statement and use the axis path available frpm NetSuite
Don't forget to put the patch in Note's /JVM/Lib/EXT folder and restart Lotus Notes before trying to run the code..

Out of Memory exception when retrieving Images from Website Link url

Hello i am creating an android application , and i have on my website about more than 1500 photos that i want to display on a ListView using an Array adapter
One solution i found is downloading the images from a URL link i have .
Here is the stacktrace
My problem is that i get an Out of Memory exception
: E/AndroidRuntime(1123): FATAL EXCEPTION: Thread-79
: E/AndroidRuntime(1123): Process:
android.quotations, PID: 1123
** : E/AndroidRuntime(1123): java.lang.OutOfMemoryError : E/AndroidRuntime(1123):
at** android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
: E/AndroidRuntime(1123): at
android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:613)
: E/AndroidRuntime(1123): at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:589)
: E/AndroidRuntime(1123): at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
: E/AndroidRuntime(1123): at
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
: E/AndroidRuntime(1123): at
android.graphics.drawable.Drawable.createFromStream(Drawable.java:791)
: E/AndroidRuntime(1123): at
com.c.fragments.AuthorImageFragment.loadImageFromWebOperations(AuthorImageFragment.java:77)
: E/AndroidRuntime(1123): at
com.c.fragments.AuthorImageFragment.access$0(AuthorImageFragment.java:72)
: E/AndroidRuntime(1123): at
com.c.fragments.AuthorImageFragment$1.run(AuthorImageFragment.java:109)
and here is the code from the adapter:
private ImageView imageDetail(View v, int resId, Drawable drawable) {
ImageView value = (ImageView) v.findViewById(resId);
BitmapDrawable draw = (BitmapDrawable)drawable;
// value.setAdjustViewBounds(true);
Bitmap bmp=draw.getBitmap();
// value.setLayoutParams(new android.widget.TableRow.LayoutParams((width/4), (height/4)));
value.setImageBitmap(bmp);
return value;
}
Thread networkThread = new Thread() {
#Override
public void run() {
Author author;
// This is just a test i want to do :)))
for (int i=0;i<=1000;i++){
author=new Author();
try {
author.setAuthorImage(loadImageFromWebOperations("http://mySite/Directory/images/"+5+".jpg",i));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
list.add(author);
}
getActivity().runOnUiThread (new Runnable(){
public void run() {
adapter= new AuthorImageAdapter(getActivity().getApplicationContext(),list);
}
});
}
}; networkThread.start();
****Here is the Method i use to retrieve the Image****
private Drawable loadImageFromWebOperations(String url,int id) throws MalformedURLException, IOException
{ InputStream is=null;
try{
is = (InputStream) new java.net.URL(url).getContent();
LOGGER.info("Drawable -----");
Drawable d = Drawable.createFromStream(is, id+".jpg");
return d;
}catch (Exception e) {
// log Exception
LOGGER.info("Exception "+e.toString());
return null;
}
finally {
if (is!=null){
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LOGGER.info("Exception "+e.toString());
// log Exception
return null;
}
}
}
}
any help would be appreciated ..
Best regards :)))
Now to help more i will add the code i use to retrieve the images .
There's no way you're going to be able to hold that many images in memory. I'd suggest that you download the images to local file storage and then in your Adapter when you want to actually draw the item that has the image, you should kick off a Loader that will load the image from disk on-demand. Sorry, there's just not enough memory to store that many images at once.
A more advanced strategy is to insert a cache using WeakReferences into the loading process. You load the image from disk and insert into something like a HashMap> and see if the image you want is in there first and if not, then do a load from disk as you normally would.
If you want to get architecturally really fancy what happens is the WeakReference cache I list above, try to load from disk, but if the file isn't present on disk only then load from the network. This then becomes a two-tier cache memory, then disk, before finally hitting the web.

Midlet crashes when calling bluetooth API

When I run following code on my phone I get black screen saying there was uncaught exception but whole block is wrapped in try/catch block so it is weird, anyway when I proceed with execution code just gets to "Getting device.." so it obviously fails on this line:
LocalDevice local = LocalDevice.getLocalDevice();
Here is whole method:
public void startBT()
{
try
{
f.append("Getting device..");
LocalDevice local = LocalDevice.getLocalDevice();
f.append("Got local device..");
DiscoveryAgent agent = local.getDiscoveryAgent();
f.append("Got local discovery agent..");
connString = agent.selectService(new UUID(
"86b4d249fb8844d6a756ec265dd1f6a3", false),
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
f.append("Got connection string - >" + connString);
}
catch (Exception ex)
{
Alert message = new Alert("info");
message.setString(ex.getMessage());
Display.getDisplay(this).setCurrent(message);
}
}
Any ideas?
It looks like device I used doesn't support JSR-82 which is J2ME Bluetooth API(this is built into phone, no way of "installing" it) required to use Bluetooth from J2ME Midlets,here is snippet which should check for JSR-82 support:
public static boolean IsBtJsrComaptible() {
try {
Class.forName("javax.bluetooth.LocalDevice");
return true;
} catch (Exception e) {
return false;
}
}
Please note that I got uncaught exception trying to run above snippet, but maybe it would work on some other device.

Unable to open camera on samsung phone in j2me

I have written following piece of code. It is used to create camera player. I tested it on nokia phones. It's working fine and I am able to see camera and use its functionality.
But the issue is that when the code is tested on samsung phone it throws Media exception and eventually have to make an exit from the application. Due to this code, my inbuilt camera functionality (i.e. on samsung phone) also stops working. So what's the reason to it?
public void startCamera()
{
try
{
try
{
// if player==null
player = createPlayer();
}
catch (Exception ex)
{
ex.printStackTrace();
ErrorDialog.show(ex, "We are exiting the application.",
"Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
public void actionPerformed() {
m_objMIDlet.exitApp();
}
});
}
try
{
player.realize();
player.prefetch();
}
catch (MediaException ex)
{
ex.printStackTrace();
ErrorDialog.show(ex, "We are exiting the application.",
"Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
public void actionPerformed() {
m_objMIDlet.exitApp();
}
});
}
//Grab the video control and set it to the current display.
videoControl = (VideoControl)(player.getControl("VideoControl"));
if (videoControl == null)
{
//discardPlayer();
stopCamera();
ErrorDialog.show("Unsupported:\n"+
"Can't get video control\n"+
"We are exiting the application.",
"Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
public void actionPerformed() {
m_objMIDlet.exitApp();
}
});
}
mediaComponent = new MediaComponent(player);
mediaComponent.setFocusable(false);
m_cameraScreen.showCamera(mediaComponent);
start();
}
catch(Exception ex)
{
ex.printStackTrace();
//discardPlayer();
stopCamera();
ErrorDialog.show("Sorry,Resources unavailable.\nWe are exiting the application.",
"Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
public void actionPerformed() {
m_objMIDlet.exitApp();
}
});
}
}
private Player createPlayer()throws MediaException, Exception
{
Player mPlayer = null;
// try capture://image first for series 40 phones
try
{
mPlayer = Manager.createPlayer("capture://image");
}
catch (Exception e)
{
e.printStackTrace();
}
catch (Error e)
{
e.printStackTrace();
}
// if capture://image failed, try capture://video
if (mPlayer == null)
{
try
{
mPlayer = Manager.createPlayer("capture://video");
}
catch (Exception e)
{
e.printStackTrace();
throw new MediaException("Sorry,Resources unavailable.");
}
}
if(mPlayer == null)
throw new Exception("Sorry,Resources unavailable.");
return mPlayer;
}
First things first, you have to realize that printStackTrace() is pretty much useless outside of the emulator unless you are using a Symbian phone.
You can also use java.lang.Throwable instead of separating Exception and Error
You can figure out exactly what happens by gathering information as a String and appending it to a simple lcdui Form while you are testing:
try {
// do something that could potentially fail
} catch (Throwable th) {
myDebugLcduiForm.append("potential failure number xx." + th + th.getMessage());
// if necessary, throw a new RuntimeException
}
You might want to update/repost your question once you know exactly what line of code throws what exception.

j2me audio player

I created a audio player using following code.
try {
InputStream is = getClass().getResourceAsStream("bell.wav");
player = Manager.createPlayer(is, "audio/X-wav");
player.realize();
player.prefetch();
player.start();
}
catch (IOException ex) {
ex.printStackTrace();
}
catch (MediaException ex) {
ex.printStackTrace();
}
This code works on the simulator without any problem. But it is not working in the phone.
MediaException is thrown. I think phone does not support for this player.
Have there any solutions for this ?
It might help to check what mime types are supported by the device by checking
Manager.getSupportedContentTypes(String protocol);
and
Manager.getSupportedProtocols(String content_type);
You can also try using an URL instead of InputStream
Manager.createPlayer(String url);

Resources