开发问题及解决 E/AndroidRuntime(15377): Caused by: java.lang.InstantiationException: can't instantiate clas
2015-04-03 13:36
645 查看
在使用IntentService时,没有定义无参的构造函数。
如下所示。
代码段1:
这样我们用以下方式使用IntentService的时,就会报如标题所示的错误。
代码段2:
解决方法就是将代码段1中被注释掉的部分放开。
如下所示。
代码段1:
public class CustomIntentService extends IntentService { private static final String TAG = CustomIntentService.class.getSimpleName(); static String s = "test"; // public CustomIntentService() { // super("CustomIntentService"); // } public CustomIntentService(String name) { super(name); Log.i(TAG, "CustomIntentService"); } @Override public void setIntentRedelivery(boolean enabled) { super.setIntentRedelivery(enabled); Log.i(TAG, "setIntentRedelivery"); } @Override public void onCreate() { super.onCreate(); Log.i(TAG, "onCreate"); } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Log.i(TAG, "onStart"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { return super.onStartCommand(intent, flags, startId); } }
这样我们用以下方式使用IntentService的时,就会报如标题所示的错误。
代码段2:
Intent startServiceIntent1 = new Intent(); startServiceIntent1.setClass(this, CustomIntentService.class); Bundle bundle = new Bundle(); bundle.putString("param", "oper1"); startServiceIntent1.putExtras(bundle); startService(startServiceIntent1);
解决方法就是将代码段1中被注释掉的部分放开。
相关文章推荐
- Android Apk包安装应用闪退,出现 java.lang.RuntimeException Unable to instantiate application Caused by: java
- android中遇到java.lang.NumberFormatException: unable to parse 'null' as integer此类问题的原因及解决方法
- java.lang.InstantiationException: can't instantiate class
- Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
- Android异常总结---E/AndroidRuntime(23439): Caused by: java.lang.IllegalArgumentException: column '_id' d
- 解决问题: Javassist Enhancement failed:Caused by: java.lang.InstantiationException
- Android问题:Test run failed: Instrumentation run failed due to 'java.lang.RuntimeException'
- Android错误总结-E/AndroidRuntime(23439): Caused by: java.lang.IllegalArgumentException: column 'id' d
- Android异常总结---E/AndroidRuntime(23439): Caused by: java.lang.IllegalArgumentException: column '_id' d
- setLayoutParams 开发问题及解决 java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams
- ERROR/AndroidRuntime: Caused by: java.lang.ClassCastException: android.widget.button
- E/AndroidRuntime(30895): Caused by: java.lang.ClassCastException: android.widget.ImageButton
- Android广播接收器注册问题:Caused by: java.lang.IllegalArgumentException: Receiver not registered
- Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface androi
- android开发常见异常解析:java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
- Android开发,实例化异常,java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
- 开发问题及解决 java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams
- Android开发中java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx}: java.lang.NullPointerException 错误的集中原因及解决办法
- 开发问题及解决 java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams
- Android 问题异常 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo