Browsed by
Category: Besturingssystemen

SonarQube

SonarQube

7 axesSonarQube is an open platform to manage code quality. As such, it covers the 7 axes of code quality.

For some time a technology that is very popular with Java developers, but Microsoft has been working hard with Sonar Source to support it, starting from the release of Visual Studio 2015 for the .NET platform. The result is a great free Code Analysis tool to clarify Technical Debt, but also to show that it is eliminated.

Below a webinar (Dutch) from Delta-N about SonarQube.

SonarQube Dashboard Example

Apache service not starting on Window 10

Apache service not starting on Window 10

Having problems starting the Apache service on Windows 10? Probably port 80 is used by another process.

When you check which process is using port 80 (use Resource Monitor), it probably is the ‘System’ process (PID=4).

Resource Monitor

This means that a process by default installed and started by Windows is using port 80. Big chance that the ‘World Wide Web Publishing Service’ is running. Just stop it and set the Startup Type to ‘Manual’

e World Wide Web Publishing Service

Now try starting the Apache service again. If it is running, the Resource Monitor should now show that the ‘httpd.exe’ process is using port 80.

Resource Monitor

How to disable System service from listening to port 80

How to disable System service from listening to port 80

When you try to run Apache (or any other web server service), it can happen that Windows is not allowing to start it, because port 80 is already in use. To find out which process is using port 80, you can use the Resource Monitor (just run resmon.exe). Open the ‘Network’ tab and open the ‘Listening Ports’ section.

Resource Monitor

Another way to find out is to use ‘netstat -a -n -o | find “:80”‘.

How to solve the problem

If the process is just a ‘normal’ process, you just need to stop the associated service to free port 80. If it’s the System process (PID=4), that is using port 80, then we need to disable http.sys.

There are two ways to disable it:

  1. Go to device manager, select ‘View -> Show hidden devices’, go to ‘Non-plug and Play Driver -> HTTP’ and double click it to disable.
  2. Launch RegEdit, go to ‘HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP‘ and change to value of ‘start‘ to 4.
    After this you need to reboot your computer.

The following values are valid for the ‘start’ property:

0 Boot
1 System
2 Automatic
3 Manual
4 Disabled

 

Automatically check disk for errors the next time the computer is restarted

Automatically check disk for errors the next time the computer is restarted

chkdskIf you want to check your disk for errors you can use chkdsk, but chkdsk doesn’t have an option to schedule the check, so the check is performed on start-up.

With the utility fsutil, it is possible to schedule the check. Run the following command (as administrator), to schedule a check on start-up: fsutil dirty set d:

Reboot the computer after executing this command and the set drive will be checked on start-up.

See what process is using a TCP port

See what process is using a TCP port

In some cases you want to know which process is using a certain TCP port. By running the following command can determine which process is using which port:

[text]

netstat -a -n -o

[/text]

You will see an output like this:

[text highlight=”16″]
Active Connections

Proto Local Address Foreign Address State PID
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:81 0.0.0.0:0 LISTENING 11464
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 844
TCP 0.0.0.0:443 0.0.0.0:0 LISTENING 2620
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:554 0.0.0.0:0 LISTENING 5124
TCP 0.0.0.0:902 0.0.0.0:0 LISTENING 3396
TCP 0.0.0.0:912 0.0.0.0:0 LISTENING 3396
TCP 0.0.0.0:2103 0.0.0.0:0 LISTENING 2220
TCP 0.0.0.0:2105 0.0.0.0:0 LISTENING 2220
TCP 0.0.0.0:2107 0.0.0.0:0 LISTENING 2220
TCP 0.0.0.0:2869 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 10232
TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING 1408
TCP 0.0.0.0:5050 0.0.0.0:0 LISTENING 12904
TCP 0.0.0.0:5357 0.0.0.0:0 LISTENING 4
[/text]

If for example you are looking for the process that is using port 3306, than in this example this would be the process with PID 10232. By using the Windows Task Manager you could find the process using this port.

Another way to find the process would be using the tasklist command:
[text]
tasklist /svc /FI "PID eq 10232"
[/text]

The result of this command tells us that the MySQL daemon is using port 3306:

[text highlight=”3″]
Image Name PID Services
========================= ======== ==============
mysqld.exe 10232 asterix
[/text]

When you do a lot of these port searches, you can always create a script like this:

[text highlight=”8,16″]
@echo off

REM Check arguments
if (%1) == () goto usage

REM Find the process using the given port
set pid=
netstat -a -n -o | findstr %1 > port.txt
for /F "tokens=5" %%a in (port.txt) do set pid=%%a
del port.txt

REM Check if a process was found using the given port
if (%pid%) == () goto notfound

REM Show the process using the given port
tasklist /svc /FI "PID eq %pid%"
goto end

:usage
REM Show usage message
echo.
echo USAGE: %0 [port]
echo.
goto end

:notfound
REM Given port is not in use
echo.
echo Port %1 is not used
echo.
goto end

:end
[/text]

Android: issue with updating apps

Android: issue with updating apps

When you have an Android smartphone and get an error with code ‘RPC:S-5:AEC-0’ when updating your Apps, carry out the following steps to get it working again:

  1. Goto Settings > Apps > All > Google Play Store and press ‘Clear data’ and ‘Stop now’
  2. Goto Settings > Google (in the Account section) en select your e-mail adres. Choose ‘Remove Account’ from the menu.
  3. Still in Settings, add a Google account, choose existing and enter your e-mail address and password.

Now you should be able to update your Apps as usual.

Remark: On my Google Nexus device with Android version 4.1.2,  I got this error after clearing the data of the ‘Google Service Framework’.

Galaxy Nexus Factory Reset

Galaxy Nexus Factory Reset

If you are ever in the situation that your Galaxy Nexus gets in a reboot loop, then you probably need to perform a factory reset.

These are the steps to do a factory reset:

  1. Remove the battery and put it back in
  2. Hold down the ‘volume up’ + ‘volume down’ + ‘power button’ at the same time
  3. In the menu select ‘Recovery mode’
  4. When you see an Android with an exclamation mark, hold down the ‘volume up’ + ‘power button’ at the same time
  5. In the menu select ‘wipe data/factory reset’
  6. Confirm by selecting ‘Yes’

The system will now completely erase your phone. So also the contents of the SD card will be erased.

After this select the reboot option and you can start setting up your phone.

After connecting to your (WiFi) network and logging in with your Google account the phone will start downloading all the Apps you had installed. Apps installed by using a .apk will not be installed automatically, so you will have to install them manually.

Tip: Setup your phone to automatically upload your photos and videos by using Apps like Google+ or DropBox

How to install Apps on the SD card with Android 2.2 (Froyo) by default

How to install Apps on the SD card with Android 2.2 (Froyo) by default

Also constantly have the problem after installing a new app on your device that you get a warning that the memory is almost full and that for example you don’t receive any new e-mails anymore?

When you own a device with at least Android 2.2 (Froyo), here’s a road map to try to solve the problem. The idea is to setup the device in such a way that by default all Apps are being installed on the SD card instead of the internal memory.

Perform the following steps so your device will install Apps on the SD card instead of internal memory:

  1. Goto Settings -> Applications -> Development and tick the checkbox for ‘USB-debugging‘.
  2. Goto www.oracle.com/technetwork/java/javase/downloads/ and download and install the Java SE JDK.
  3. Goto http://developer.android.com/sdk/ and download and install the Android SDK. Make sure that you select ‘USB Driver package’ during installation.
  4. Connect the device with a USB-cable to your PC. The operating system will now install the needed driver.
    Remark: only connect the cable and do not mount the device’s SD card to the PC.
  5. Open a command-prompt and goto the directory [android-sdk-dir]\platform-tools.
    Open command-prompt:  press Windows-key + R, type cmd and press Enter.
  6. Execute the following command to check if the connect device is recognized: adb devices.
    You should see some like this:
  7. Execute the following command: adb shell pm setInstallLocation 2. From now on the Apps get installed on the SD card by default.
  8. Untick the checkbox for ‘USB-debugging’ (see step 1)

Remarks:

  • If you want the Apps being installed in internal memory by default again, just execute the following command: adb shell pm setInstallLocation 0.
  • Keep in mind that not all Apps will run fine when they are installed in SD card. If an App also has Widgets, they probably will not work. Also Apps that install a service to regularly gets data will not work when installed on SD card.
Android – Customizing list view item layout

Android – Customizing list view item layout

In a previous article I described how to use a ListView to display data. In the example the data was shows using a string without any formatting. This article will show you how to change the code so the data will be shown in a better looking way. The data will be formatted by using a custom ArrayAdapter which will use a custom item layout.

Let’s start with the basics: the main.xml and the used data class.

main.xml:

[xml highlight=”16,17-20″]

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:textSize="20sp"
android:textColor="#FF0000"
android:text="ListView using standard ArrayAdapter and simple list layout"
/>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

[/xml]

The following code shows the data class which will hold the temperature data.

TemperatureData.java:

[java highlight=”14,15-37″]

package nl.jestersoft.listviewtryout;

import android.text.format.Time;

public class TemperatureData
{
// The data
String SensorName;
double CurrentTemperature;
double MinimumTemperature;
double MaximumTemperature;
String TimeStamp;

public String GetSensorName()
{
return SensorName;
}

public double GetCurrentTemperature()
{
return CurrentTemperature;
}

public double GetMinimumTemperature()
{
return MinimumTemperature;
}

public double GetMaximumTemperature()
{
return MaximumTemperature;
}

public String GetTimeStamp()
{
return TimeStamp;
}

public TemperatureData(String sensorName, double currentTemperature, double minimumTemperature, double maximumTemperature, String timeStamp )
{
SensorName = sensorName;
CurrentTemperature = currentTemperature;
MinimumTemperature = minimumTemperature;
MaximumTemperature = maximumTemperature;
TimeStamp = timeStamp;
}

@Override
public String toString()
{
String item;

// Just out out the data as a string
item = SensorName + ": " + CurrentTemperature + ", " + MinimumTemperature + ", " + MaximumTemperature + " (" + TimeStamp + ")";

return item;
}
}
[/java]

The data class has been extended with public methods so we can access the internal data fields. Below the adjusted main code is shown.

ListViewTryout.java:

[java highlight=”25,26,27″]
package nl.jestersoft.listviewtryout;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;

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

// Add some dummy data to the list
ArrayList<TemperatureData> tempData = GetDummyData();

// Get list to view data in
ListView list = (ListView)findViewById(R.id.list);

// Show data in the list
int layoutID = R.layout.listitem;
TemperatureAdapter tempAdapter = new TemperatureAdapter(this, layoutID, tempData);
list.setAdapter(tempAdapter);
}

public ArrayList<TemperatureData> GetDummyData()
{
ArrayList<TemperatureData> dummyData = new ArrayList<TemperatureData>();

TemperatureData data1 = new TemperatureData("Balcony", 18.0, 16.0, 20.0, "30-07-2011 13:14");
dummyData.add(data1);

TemperatureData data2 = new TemperatureData("Living room", 24.0, 20.0, 25.0, "30-07-2011 13:14");
dummyData.add(data2);

TemperatureData data3 = new TemperatureData("Bath room", 18.0, 21.0, 27.0, "30-07-2011 13:15");
dummyData.add(data3);

return dummyData;
}
[/java]

In this version of the main code we are not using the standard ArrayAdapter but a custom adapter (TemperatureAdapter). The adapter is now using a custom layout (R.layout.listitem) instead of the simple list item layout. Below the code for the custom adapter and list item layout is shown.

listitem.xml

[xml]

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<!– Column 1 –>
<TextView
android:id="@+id/currentTemp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="28sp"
android:text="18"/>

<!– Column 2 –>
<TableLayout
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="1">
<TableRow>
<TextView
android:id="@+id/sensorDescr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="16sp"
android:text="Balkon"/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/timestamp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="8sp"
android:text="30-07-2011 13:14"/>
</TableRow>
</TableLayout>

<!– Column 3 –>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right">
<TableRow>
<TextView
android:id="@+id/maxLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textSize="8sp"
android:text="max"/>
<TextView
android:id="@+id/maxTemp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="14sp"
android:layout_margin="1dip"
android:textStyle="bold"
android:text="20"/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/minLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textSize="8sp"
android:text="min"/>
<TextView
android:layout_height="wrap_content"
android:text="16"
android:textSize="14sp"
android:layout_width="fill_parent"
android:layout_margin="1dip"
android:textStyle="bold"
android:id="@+id/minTemp"></TextView>
</TableRow>
</TableLayout>
</LinearLayout>
[/xml]

You can create a layout just the way you want it. The custom adapter will ensure that the data will be displayed in the layout.

TemperatureAdapter.java

[java highlight=”34,35,38,62″]
package nl.jestersoft.listviewtryout;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TemperatureAdapter extends ArrayAdapter<TemperatureData>
{
private ArrayList<TemperatureData> items;
private Context context;

public TemperatureAdapter(Context context, int resource, ArrayList<TemperatureData> items)
{
super(context, resource, items);
this.items = items;
this.context = context;
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View temperatureView = convertView;

if ( temperatureView == null)
{
LayoutInflater inflator = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
temperatureView = inflator.inflate(R.layout.listitem, null);
}

TemperatureData item = this.items.get(position);

String sensorName = item.GetSensorName();
double currentTemperature = item.GetCurrentTemperature();
double minimumTemperature = item.GetMinimumTemperature();
double maximumTemperature = item.GetMaximumTemperature();
String timeStamp = item.GetTimeStamp();

TextView tvCurrentTemp = (TextView)temperatureView.findViewById(R.id.currentTemp);

TextView tvSensorDescr = (TextView)temperatureView.findViewById(R.id.sensorDescr);
TextView tvTimestamp = (TextView)temperatureView.findViewById(R.id.timestamp);
TextView tvMinTemp = (TextView)temperatureView.findViewById(R.id.minTemp);
TextView tvMaxTemp = (TextView)temperatureView.findViewById(R.id.maxTemp);

tvCurrentTemp.setText(String.valueOf(currentTemperature));
tvSensorDescr.setText(sensorName);
tvTimestamp.setText(timeStamp);

String min = String.valueOf(minimumTemperature);
tvMinTemp.setText(min);
String max = String.valueOf(maximumTemperature);
tvMaxTemp.setText(max);

return temperatureView;
}
}
[/java]

The most important code in this class is where an inflator is created and used to load the custom list item layout.

When you run the code you will see the following result.