Błąd, nie można utworzyć obiektu, Java i Android

0

Kod:

 
  @Override
  public void onCreate() {
    // Start up the thread running the service.  Note that we create a
    // separate thread because the service normally runs in the process's
    // main thread, which we don't want to block.  We also make it
    // background priority so CPU-intensive work will not disrupt our UI.
	
    HandlerThread thread = 
			new HandlerThread( "gfcjc", 
			Process.THREAD_PRIORITY_BACKGROUND);
   
	thread.start();
    
    // Get the HandlerThread's Looper and use it for our Handler 
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);
  }

Netbeans wyrzuca błąd:
internal error; cannot instantiate HandlerThread(java.lang.String,int) at android.os.HandlerThread to ()
przykłąd kodu jest ze strony Androida: http://developer.android.com/guide/components/services.html

1

nie masz gdzieś własnej klasy abstrakcyjnej o tej nazwie?

0

@ŁF
Nie, skopiowałem kod ze strony Oracl-a, edytowałem Android manifest file, żeby Service było kodem automatycznie uruchamianym i jest błąd od samego początku.

manifest file

 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="Server_5.app"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <service android:name="Server_5_Service"
		 android:label="@string/app_name">
	    <intent-filter>
                <action android:name="android.intent.action.onCreate" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
	</service>
	<activity android:name="MainActivity"
                  android:label="@string/app_name">
        </activity>
	
    </application>
</manifest>

@ŁF
EDIT:
Dzięki za podpowiedź, problem rozwiązałem, trzeba było wskazać skąd jest HandlerThread w klasie tzn. android.os.
Nie wiem czemu wcześniej mi nie działało w ten sposób.

 
@Override
  public void onCreate() {
    // Start up the thread running the service.  Note that we create a
    // separate thread because the service normally runs in the process's
    // main thread, which we don't want to block.  We also make it
    // background priority so CPU-intensive work will not disrupt our UI.
	
    android.os.HandlerThread thread = 
			new android.os.HandlerThread("",
			android.os.Process.THREAD_PRIORITY_BACKGROUND);
   
	thread.start();
    
    // Get the HandlerThread's Looper and use it for our Handler 
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);
  }

1 użytkowników online, w tym zalogowanych: 0, gości: 1