Archivi categoria: Programming

Failed to create the Java Virtual Machine – How To

Ok, avete installato Eclipse ma al momento della partenza l’unico messaggio che ricevete è il seguente:
“Failed to create the Java Virtual Machine”
Significa solo che avete fatto qualche casino con l’installazione della JDK (magari l’avete installata dopo aver avviato eclipse per la prima volta), ma non è un problema, basta editare il file eclipse.ini che trovate nella stessa cartella dove c’è l’eseguibile eclipse.exe ed aggiungiate con i giusti percorsi il seguente comando:

-vm C:\Program Files\Java\jre6\bin\javaw

chiudete tutto, salvate
e … buona programmazione

al prossimo tip! 😀

Avoid Memory Leak in .NET

Problem: In .NET for some components like webBrowser component seems that occurs memory leaks, so we see a growth of RAM until we don’t stop our application.

Solution C#
First of all you need to declare this

[DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);

[DllImport("KERNEL32.DLL", EntryPoint = "GetCurrentProcess", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern IntPtr GetCurrentProcess();

and later in your code you need to write

IntPtr pHandle = GetCurrentProcess();
SetProcessWorkingSetSize(pHandle, -1, -1);

Solution Vb.NET
First of all you need to declare this

#Region "Stuff for Closing the Processes"
'# to close all the resources
Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean

Public Sub SetProcessWorkingSetSize()
Try
Dim Mem As Process
Mem = Process.GetCurrentProcess()
SetProcessWorkingSetSize(Mem.Handle, -1, -1)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
#End Region

and later you need to write in your code:

GC.Collect()
If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
End If

Reference Link:

Microsoft Forums

[ANDROID] Screen always turned on How to

This android code snippet is for keep alive the screen of your android device during the execution of your app, please read the note also.

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();

..screen will stay on during this section..

wl.release();

IMPORTANT: Remember to RELEASE the WakeLock when you have finished to use it, otherwise the screen will be ever turned on! 🙂

Android Color List

if you write android code you will need as soon as possible of a list of colors, i’ve found this that i think is very exaustive, you don’t think so? 🙂

 


< ?xml version="1.0" encoding="utf-8"?>

#FFFFFF #FFFFF0 #FFFFE0 #FFFF00 #FFFAFA #FFFAF0 #FFFACD #FFF8DC #FFF5EE #FFF0F5 #FFEFD5 #FFEBCD #FFE4E1 #FFE4C4 #FFE4B5 #FFDEAD #FFDAB9 #FFD700 #FFC0CB #FFB6C1 #FFA500 #FFA07A #FF8C00 #FF7F50 #FF69B4 #FF6347 #FF4500 #FF1493 #FF00FF #FF00FF #FF0000 #FDF5E6 #FAFAD2 #FAF0E6 #FAEBD7 #FA8072 #F8F8FF #F5FFFA #F5F5F5 #F5F5DC #F5DEB3 #F4A460 #F0FFFF #F0FFF0 #F0F8FF #F0E68C #F08080 #EEE8AA #EE82EE #E9967A #E6E6FA #E0FFFF #DEB887 #DDA0DD #DCDCDC #DC143C #DB7093 #DAA520 #DA70D6 #D8BFD8 #D3D3D3 #D2B48C #D2691E #CD853F #CD5C5C #C71585 #C0C0C0 #BDB76B #BC8F8F #BA55D3 #B8860B #B22222 #B0E0E6 #B0C4DE #AFEEEE #ADFF2F #ADD8E6 #A9A9A9 #A52A2A #A0522D #9ACD32 #9932CC #98FB98 #9400D3 #9370DB #90EE90 #8FBC8F #8B4513 #8B008B #8B0000 #8A2BE2 #87CEFA #87CEEB #808080 #808000 #800080 #800000 #7FFFD4 #7FFF00 #7CFC00 #7B68EE #778899 #708090 #6B8E23 #6A5ACD #696969 #66CDAA #6495ED #5F9EA0 #556B2F #4B0082 #48D1CC #483D8B #4682B4 #4169E1 #40E0D0 #3CB371 #32CD32 #2F4F4F #2E8B57 #228B22 #20B2AA #1E90FF #191970 #00FFFF #00FFFF #00FF7F #00FF00 #00FA9A #00CED1 #00BFFF #008B8B #008080 #008000 #006400 #0000FF #0000CD #00008B #000080 #000000

Download Files and AsyncTask in Android

This code snippet found here complete my previous snippet that i’ve used to grab a single file on a remote server


import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;

public class SimpleWebGrab extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

grabURL("http://android.com");
}

public void grabURL(String url) {
new GrabURL().execute(url);
}

private class GrabURL extends AsyncTask {
private final HttpClient Client = new DefaultHttpClient();
private String Content;
private String Error = null;
private ProgressDialog Dialog = new ProgressDialog(SimpleWebGrab.this);

protected void onPreExecute() {
Dialog.setMessage("Downloading source..");
Dialog.show();
}

protected Void doInBackground(String... urls) {
try {
HttpGet httpget = new HttpGet(urls[0]);
ResponseHandler responseHandler = new BasicResponseHandler();
Content = Client.execute(httpget, responseHandler);
} catch (ClientProtocolException e) {
Error = e.getMessage();
cancel(true);
} catch (IOException e) {
Error = e.getMessage();
cancel(true);
}

return null;
}

protected void onPostExecute(Void unused) {
Dialog.dismiss();
if (Error != null) {
Toast.makeText(SimpleWebGrab.this, Error, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(SimpleWebGrab.this, "Source: " + Content, Toast.LENGTH_LONG).show();
}
}

}
}