服务不工作-Android应用程序正在崩溃

服务不工作-Android应用程序正在崩溃,android,service,android-activity,manifest,Android,Service,Android Activity,Manifest,我正在尝试制作一个简单的应用程序来测试服务类。我想有一个按钮,当按下启动服务,并显示服务已启动祝酒词,然而,每当我按下按钮,应用程序崩溃,我不知道是什么问题。 测试等级: public class ControllerTestingScreen extends Activity{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV

我正在尝试制作一个简单的应用程序来测试服务类。我想有一个按钮,当按下启动服务,并显示服务已启动祝酒词,然而,每当我按下按钮,应用程序崩溃,我不知道是什么问题。 测试等级:

public class ControllerTestingScreen extends Activity{

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_controller_test_screen);
    //Set button colors to red, green, blue, and red, respectively
    Button button = (Button) findViewById(R.id.testbutton);
    button.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
    OnClickListener buttonListener = new View.OnClickListener(){
        public void onClick(View arg0) {

            startService(new Intent(getBaseContext(),Controller.class));
            //sendSMS("PutPhoneNumberHereForTesting","WhereYouApp Text Message Test");
        }
    };
    button.setOnClickListener(buttonListener);
}
清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.whereyouapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />
<activity

         android:name="com.example.whereyouapp.ControllerTestingScreen"
         android:label="YOLO">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

     </activity>

      <service android:name="com.example.whereyouapp.Controller"/>
      </application>
</manifest>
我得到的错误:

logcat error: 02-23 14:10:40.187: E/AndroidRuntime(1173): java.lang.RuntimeException: Unable to instantiate service com.example.whereyouapp.Controller: java.lang.InstantiationException: can't instantiate class com.example.whereyouapp.Controller; no empty constructor 

您的服务确实需要无参数构造函数,如果您定义:

public Controller(String name)

那么java不会自动添加参数小于1的,android需要它来使用
startService

实例化您的服务。我在您的清单中看不到
开始标记O_O

请发布您的stacktrace/错误日志。我在手机上测试它很可能是因为您无法从后台线程与UI交互。@AnidMonsur没有后台线程!打开USB调试,你会在IDE中看到你的logcat。你是什么意思?不是在上面吗?我不明白你指的是哪一部分,因为我看到了开头的标签。您能详细说明一下吗?@user35265您在上面发布的清单,它没有
开始标记:)如果您有,那么就可以:)对于第一个构造函数“构造函数字符串未定义”对不起,请删除您的构造函数-它不是一个意图服务简单地
公共控制器()
,或者删除所有构造函数
public Controller(String name)