FATAL异常main(RuntimeException)

时间:2011-05-04 08:26:52

标签: java android sdk

源(osmand)中没有错误

我使用googlecode的eclipse和sdk模拟器2.2 checkout (osmand申请)

我的代码:

public void onCreate(){ 
    super.onCreate(); 
    routingHelper = new RoutingHelper(OsmandSettings.getApplicationMode(OsmandSettings.getPrefs(OsmandAp­plication.this)), OsmandApplication.this, player); 
    manager = new ResourceManager(this); 
    daynightHelper = new DayNightHelper(this); 
    uiHandler = new Handler(); 
    startApplication(); 
} 

这些都是logcat中的错误:

05-04 07:53:01.807: ERROR / AndroidRuntime (308): FATAL EXCEPTION:     main 
05-04 07:53:01.807: ERROR / AndroidRuntime (308): java.lang.RuntimeException: Unable to create application net.osmand.activities.OsmandApplication: java.lang.IllegalArgumentException: InputStream can not be null 
05-04 07:53:01.807: ERROR / AndroidRuntime (308): Has android.app.ActivityThread.handleBindApplication (ActivityThread.java: 4247) 
05-04 07:53:01.807: ERROR / AndroidRuntime (308): Has android.app.ActivityThread.access $ 3000 (ActivityThread.java: 125) 
05-04 07:53:01.807: ERROR / AndroidRuntime (308): at $ android.app.ActivityThread H.handleMessage (ActivityThread.java: 2071) 
05-04 07:53:01.807: ERROR / AndroidRuntime (308): Has android.os.Handler.dispatchMessage (Handler.java: 99) 
05-04 07:53:01.807: ERROR / AndroidRuntime (308): Has android.os.Looper.loop (Looper.java: 123) 
05-04 07:53:01.807: ERROR / AndroidRuntime (308): Has android.app.ActivityThread.main (ActivityThread.java: 4627) 
05-04 07:53:01.807: ERROR / AndroidRuntime (308): Has java.lang.reflect.Method.invokeNative (Native Method 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at java.lang.reflect.Method.invoke(Method.java:521) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:868) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at dalvik.system.NativeStart.main(Native Method) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308): Caused by: java.lang.IllegalArgumentException: InputStream cannot be null 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at javax.xml.parsers.SAXParser.parse(SAXParser.java:185) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.OsmandRenderingRulesParser.parseRenderingRules(OsmandRend­eringRulesParser.java: 104) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.BaseOsmandRender.init(BaseOsmandRender.java:41) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.RendererRegistry.loadRenderer(RendererRegistry.java: 116) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.RendererRegistry.loadRenderer(RendererRegistry.java: 103) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.RendererRegistry.getRenderer(RendererRegistry.java: 93) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.RendererRegistry.getRenderer(RendererRegistry.java: 84) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.RendererRegistry.defaultRender(RendererRegistry.java: 54) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.OsmandRenderer.<init>(OsmandRenderer.java:239) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.MapRenderRepositories.<init>(MapRenderRepositories.java: 79) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.ResourceManager.<init>(ResourceManager.java:98) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.activities.OsmandApplication.onCreate(OsmandApplication.java: 51) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java: 969) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4244) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):     ... 10 more

1 个答案:

答案 0 :(得分:1)

在运行时(执行时),您将null值传递给某个期望/需要InputStream(或任何子类)实例的方法。编译器无法检测到这种错误,因此您的源代码会编译。

要调试:在源中找到导致该运行时异常的代码行。在该行,您将找到一些InputStream变量,您必须分析源以回答为什么在哪些条件变量保持null而不是流引用。


从你的堆栈跟踪中我看到这三行给出了问题的提示:

05-04 07:53:01.807: ERROR/AndroidRuntime(308): Caused by: java.lang.IllegalArgumentException: InputStream cannot be null 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at javax.xml.parsers.SAXParser.parse(SAXParser.java:185) 
05-04 07:53:01.807: ERROR/AndroidRuntime(308):at net.osmand.render.OsmandRenderingRulesParser.parseRenderingRules(OsmandRend­eringRulesParser.java: 104) 

应用程序尝试打开xml文件(该名称在日志中未知),并且应用程序找不到此xml。

所以你必须找出需要哪个文件(该文件应包含某种呈现规则)和其中存储为应用程序找到它。解析器加载丢失的文件后,错误就消失了。