2013-01-24 31 views
-1

我想在手机完成启动时启动service(检查时间)。这似乎工作,但我的应用程序立即崩溃。我收到以下错误“java.lang.RuntimeException: Unable to start receiver com.example.alarmtest.MyReceiver: java.lang.UnsupportedOperationException: Not yet implemented”。我试图解决这个问题一直没有成功。我不确定我是否从manifest中遗漏了某些东西(我对于开发Android相当新颖)。 这是我MyReceiver的代码。 (出现这个log.d)android无法启动接收器尚未实现

public class MyReceiver extends BroadcastReceiver { 
public MyReceiver() { 
} 

@Override 
public void onReceive(Context context, Intent intent) { 
     Intent startServiceIntent = new Intent(context, CheckTime.class); 
     context.startService(startServiceIntent); 
     Log.d("evan alarm", "Started on Launch, android autostart"); 
    throw new UnsupportedOperationException("Not yet implemented"); 
     } 
} 

和(从未出现log.d此),用于检查时间码

public class CheckTime { 
     public void loglab(){ 
     Log.d("evan alarm", "We are now in CheckTime"); 
     } 
} 

,最终清单。

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.alarmtest" 
android:versionCode="1" 
android:versionName="1.0" > 

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

<permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <service 
     android:name="com.example.alarmtest.MyService" > 
     <intent-filter 
      android:label="com.example.alarmtest.MyService"> 
     </intent-filter> 
    </service> 
    <service android:name="com.example.alarmtest.CheckTime" /> 

    <activity 
     android:name="com.example.alarmtest.AlarmActivity" 
     android:label="@string/title_activity_alarm" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.alarmtest.ChangeTime" 
     android:label="@string/title_activity_change_time" > 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value="com.example.AlarmTest.AlarmActivity" /> 
    </activity> 

    <receiver 
     android:name="com.example.alarmtest.MyReceiver"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 
</application> 

</manifest> 

回答

10
throw new UnsupportedOperationException("Not yet implemented"); 

这是你的接收器的最后一行。你自己扔了。

+1

......不,我觉得很傻。 – Mr404servererror

+0

@ Mr404servererror发生在我们身上! – ninehundredt

+0

Lol Same,这就是为什么来到这里。 –

1

删除此行

throw new UnsupportedOperationException("Not yet implemented"); 
相关问题