---
title: "调用service静态方法抛RuntimeException问题"
author: "hemowolf"
date: "2013-02-06T10:50:32Z"
tags: ["Service", "runtimeexception", "static"]
categories: ["移动开发"]
slug: "service-runtimeexception"
draft: false
lastmod: "2013-02-06T10:50:32Z"
id: 1796756
url: "https://obacow.iteye.com/blog/1796756"
---

假设有一个service类是 AbcSvr在其内有一个static方法供外调用启动自己。

```
    public static void startAbcSvr(Context ctx ) {
	      ctx.startService(new Intent(ctx, AbcSvr.class));
    }
```

   在某种情况下回抛出Exception

   Exception Ljava/lang/RuntimeException; thrown while initializing Lcom/XXXX/AbcSvr;  
   

    应是Dalvik的一个bug。解决的办法是将startAbcSvr方法移动到其他类去即可。