Questions tagged «runtimeexception»

21
了解Java中的已检查异常与未检查异常
约书亚·布洛赫(Joshua Bloch)在《有效的Java》中说 将检查的异常用于可恢复的条件,将运行时异常用于编程错误(第二版中的项目58) 让我们看看我是否正确理解了这一点。 这是我对检查异常的理解: try{ String userInput = //read in user input Long id = Long.parseLong(userInput); }catch(NumberFormatException e){ id = 0; //recover the situation by setting the id to 0 } 1.以上是否被视为经过检查的异常? 2. RuntimeException是未经检查的异常吗? 这是我对未经检查的异常的理解: try{ File file = new File("my/file/path"); FileInputStream fis = new FileInputStream(file); }catch(FileNotFoundException e){ //3. …

16
Android 1.6:“ android.view.WindowManager $ BadTokenException:无法添加窗口-令牌null不适用于应用程序”
我试图打开一个对话框窗口,但是每次我尝试打开它时,都会引发此异常: Uncaught handler: thread main exiting due to uncaught exception android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application at android.view.ViewRoot.setView(ViewRoot.java:460) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) at android.app.Dialog.show(Dialog.java:238) at android.app.Activity.showDialog(Activity.java:2413) 我通过showDialog使用显示器的ID 进行调用来创建它。该onCreateDialog处理程序的日志记录很好,我可以毫无问题地逐步解决它,但是我附上了它,因为似乎我缺少了一些东西: @Override public Dialog onCreateDialog(int id) { Dialog dialog; Context appContext = this.getApplicationContext(); switch(id) { case …

6
NameError:全局名称“ xrange”未在Python 3中定义
运行python程序时出现错误: Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 110, in <module> File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 27, in __init__ File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\class\inventory.py", line 17, in __init__ builtins.NameError: global name 'xrange' is not defined 游戏是从这里开始的。 是什么导致此错误?

9
从Activity外部调用startActivity()?
我正在使用AlarmManager触发广播信号的意图。以下是我的代码: AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, Wakeup.class); try { PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0); Long elapsed += // sleep time; mgr.set(AlarmManager.RTC_WAKEUP, elapsed, pi); } catch(Exception r) { Log.v(TAG, "RunTimeException: " + r); } 我是从调用此代码的Activity,所以我不知道如何得到以下错误... ERROR/AndroidRuntime(7557): java.lang.RuntimeException: Unable to start receiver com.wcc.Wakeup: android.util.AndroidRuntimeException: Calling …

11
Android“无法添加窗口-令牌null不适用于应用程序”异常
尝试打开对话框时出现以下Android异常。有人可以帮我了解发生了什么,如何解决此问题? android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application at android.view.ViewRoot.setView(ViewRoot.java:509) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) at android.app.Dialog.show(Dialog.java:241)

13
ActionBarCompat:java.lang.IllegalStateException:您需要使用Theme.AppCompat
我在Android 2.3.5上遇到RuntimeException,但正在使用Theme.AppCompat(res / values / themes.xml)。这是电话:http : //www.gsmarena.com/samsung_galaxy_y_s5360-4117.php <!-- res/values/themes.xml --> <?xml version="1.0" encoding="utf-8"?> <resources> <style name="Theme.Styled" parent="@style/Theme.AppCompat"> <item name="actionBarStyle">@style/QueryActionBar</item> <item name="android:actionBarStyle">@style/QueryActionBar</item> </style> <style name="QueryActionBar" parent="@style/Widget.AppCompat.ActionBar"> <item name="background">@color/blueback</item> <item name="android:background">@color/blueback</item> <item name="backgroundSplit">@color/blueback</item> <item name="android:backgroundSplit">@color/blueback</item> </style> </resources> 这是值-v11的文件。 <!-- res/values-v11/themes.xml --> <?xml version="1.0" encoding="utf-8"?> <resources> <style name="QueryTheme" parent="@android:style/Theme.Holo"> <!-- Any customizations …

30
无法实例化android.gms.maps.MapFragment
我尝试通过非常简单的活动使用Google Maps android v2进行演示,只需从Google页面复制代码即可:https : //developers.google.com/maps/documentation/android/start#adding_the_api_key_to_your_application 活动: package com.example.mapdemo; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } 用于布局: <?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment"/> 我已经根据页面申请了一个api密钥并修改了我的androidmanifest.xml文件,就像这样: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wenhai.driverschool" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> …

6
无法在未调用Looper.prepare()的线程内创建处理程序
我有一个活动,并在那里上了一堂课。 text=new Dynamictext(...); text.setText("txt"); 在我的DynamicText Java中,我有以下代码: public void setText(String text) { this.text=text; new asyncCreateText().execute(); //this.createText(text); } //private Handler handler = new Handler(); private class asyncCreateText extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... unused) { return null; } @Override protected void onPostExecute(Void unused) { } } 我得到: ERROR / …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.