标签: runtimeexception

Android标签操作栏

我正在尝试3.0的android操作栏,我参考

http://www.youtube.com/watch?v=gMu8XhxUBl8

代码TabsActivity如下:

package com.test.actionbar;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment; 
import android.app.FragmentTransaction;
import android.os.Bundle;

public class TabsActivity extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.Tab tabA = bar.newTab().setText("A Tab");
    ActionBar.Tab tabB = bar.newTab().setText("B Tab");
    ActionBar.Tab tabC = bar.newTab().setText("C Tab");

    Fragment fragmentA = new AFragmentTab();
    Fragment fragmentB = new BFragmentTab();
    Fragment fragmentC = new CFragmentTab();

    tabA.setTabListener(new MyTabsListener(fragmentA));
    tabB.setTabListener(new MyTabsListener(fragmentB));
    tabC.setTabListener(new MyTabsListener(fragmentC));

    bar.addTab(tabA);
    bar.addTab(tabB);
    bar.addTab(tabC);

}

protected class MyTabsListener implements …
Run Code Online (Sandbox Code Playgroud)

tabs android runtimeexception android-3.0-honeycomb android-actionbar

6
推荐指数
1
解决办法
3万
查看次数

如何在Java中捕获所有已检查的异常(在单个块中)?

编辑:这个问题只涉及Java 1.6(及以下).抱歉没有在原帖中说清楚.

这里的层次结构显示Java Exception分为两种类型:RuntimeException不是RuntimeException:

Java异常层次结构

我可能会错过一些东西,但不会更好地分成类似的东西UncheckedExceptionCheckedException不是吗?例如,以下语句具有相当多的已检查异常:

try {
    transaction.commit();
} catch (SecurityException e) {
} catch (IllegalStateException e) {
} catch (RollbackException e) {
} catch (HeuristicMixedException e) {
} catch (HeuristicRollbackException e) {
} catch (SystemException e) {
}
Run Code Online (Sandbox Code Playgroud)

我只是真的对它是成功还是失败感兴趣所以想要将已检查的异常作为一个组来处理,而不是未经检查的异常,因为捕获意外错误不是好的做法.所以考虑到这一点,也许我可以这样做:

try {
    transaction.commit();
} catch (Exception e) {
    if (e instanceof RuntimeException) {
        // Throw unchecked exception
        throw e;
    }
    // Handle checked exception
    // ...
}
Run Code Online (Sandbox Code Playgroud)

但这看起来非常糟糕.有没有更好的办法?

java exception try-catch runtimeexception checked-exceptions

6
推荐指数
2
解决办法
1338
查看次数

Java- RuntimeException- 无法编译的源代码 - 错误的树类型

我是 Java 新手,也是这个网站的新手,所以如果错误很明显,我很抱歉,但我收到了一个错误,我不知道它意味着什么,我已尝试一切方法来修复它。

我目前正在编写一个基本的应用程序库,带有一些swing界面,但问题是当尝试创建书籍形式的窗口时,有相关代码。

这是主窗口。

 public class VentanaPrincipal extends javax.swing.JFrame {

   public VentanaPrincipal() {
     initComponents();
     this.setLocationRelativeTo(null);
}

private void bt_salirActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    EscribirBinario escritor = new EscribirBinario();
    //   Collections.sort(ListaClientes.clientes);

    if (escritor.abrir(Main.archivo1)) {
        for (int indice = 0; indice < ListaClientes.clientes.size(); indice++) {
            escritor.escribir(ListaClientes.clientes.get(indice));
        }
        escritor.cerrar();
    }
    System.exit(0);
}                                        

private void bt_clienteActionPerformed(java.awt.event.ActionEvent evt) {                                           

    MantenimientoCliente clientes = new MantenimientoCliente(this, true);
    clientes.setVisible(true);
}                                          

private void bt_libroActionPerformed(java.awt.event.ActionEvent evt) {                                         

    MantenimientoLibro book = new MantenimientoLibro(this, true);
    book.setVisible(true); …
Run Code Online (Sandbox Code Playgroud)

java swing netbeans runtimeexception

6
推荐指数
1
解决办法
3万
查看次数

通过intent将对象作为Parcel(带有文件描述符)发送会导致异常

我正在尝试将一组StatusBarNotifications发送给我的另一个服务,所以我这样做了:

扩展的服务NotificationListenerService:

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    // TODO Auto-generated method stub
    StatusBarNotification[] activeN = super.getActiveNotifications();               

    Intent i = new Intent(this, CoreTwo.class);
    i.putExtra("activenotifications", activeN);
    startService(i);
}
Run Code Online (Sandbox Code Playgroud)

但我得到一个关于文件描述符的RuntimeException.

我只找到几个环节解决这一问题,例如这一个在这里.答案提到了以下内容:

使用Bundle.putBinder()传递一个Binder,它将使用ParcelFileDescriptor(来自API 18)返回一个Parcel.但我不明白如何实现这一点.

此链接中的另一个人在这里提到以下内容:

如果我从ContentProvider返回PaecelFileDescriptor,它可以正常工作.

但我不明白他的意思.

最后一个环节是这个位置.它解决了与我相同的问题,但似乎没有解决方案.

有人理解我链接的这些潜在解决方案吗?是否有针对此问题的解决方法,可能是另一种发送数据的方式(StatusBarNotification [](它扩展了Parcelable))?

这是日志:

    08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): Error running onNotificationPosted
08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): java.lang.RuntimeException: Not allowed to write file descriptors here
08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804):   at android.os.Parcel.nativeAppendFrom(Native Method)
08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804):   at android.os.Parcel.appendFrom(Parcel.java:431)
08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804):   at android.os.Bundle.writeToParcel(Bundle.java:1679)
08-23 …
Run Code Online (Sandbox Code Playgroud)

android android-intent runtimeexception

6
推荐指数
0
解决办法
1130
查看次数

java.lang.IllegalArgumentException:找不到片段FmMenu的id 0x7f090047("项目名称":id/content)的视图

只是想与我为客户做的项目分享一个问题.

每当我进入我的IntroActivity并按下按钮带我去MenuActivity,它就会崩溃.

这是错误日志:

02-16 18:49:49.393    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? No view found for id 0x7f090047 (com.wlodsgn.bunbunup:id/linear) for fragment FmMenu{b1e537f0 #0 id=0x7f090047}
02-16 18:49:49.393    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? Activity state:
02-16 18:49:49.423    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? Local FragmentActivity b1e1d1b8 State:
02-16 18:49:49.423    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? mCreated=falsemResumed=false mStopped=false mReallyStopped=false
02-16 18:49:49.423    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? mLoadersStarted=false
02-16 18:49:49.443    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? FragmentManager misc state:
02-16 18:49:49.443    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? mActivity=com.wlodsgn.bunbunup.MenuActivity@b1e1d1b8
02-16 18:49:49.443    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? mContainer=android.support.v4.app.FragmentActivity$2@b1e1ed08
02-16 18:49:49.453    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? mCurState=1 mStateSaved=false mDestroyed=false
02-16 18:49:49.453    1208-1208/com.wlodsgn.bunbunup E/FragmentManager? View Hierarchy:
02-16 …
Run Code Online (Sandbox Code Playgroud)

java xml android illegalargumentexception runtimeexception

6
推荐指数
1
解决办法
3万
查看次数

为日志记录目的捕获RuntimeException是不好的做法吗?

我发现捕获RuntimeException通常被认为是不好的做法,因为它们无法纠正,通常是程序员错误.

但是,我们有一个(疯狂的)大型应用程序,其中任何部分的更改都可能产生无法预料的后果(是的,这本身就是一个问题).

现在,我们开始在应用程序的顶层开始捕获和记录RuntimeExceptions,这样我们就可以更有效地修复出现这样的流失问题.

像每个优秀的Java团队一样,我们有一个可爱的热心鲍勃非常追随者,绝对禁止我们这样做.

这样做有多糟糕?真的没有这种情况可以接受甚至推荐吗?

java exception-handling runtimeexception

6
推荐指数
2
解决办法
2493
查看次数

无法启动接收器com.google.firebase.iid.FirebaseInstanceIdInternalReceiver

我的应用程序集成了FCM以接收推送通知,它可以正常工作.但是,我面临的问题是,在安装时它会随机崩溃.它是非常随机的,发生在OS 6.0+设备上直到最新但随机发生.

代码方面,在服务类中只显示通知代码,并在清单中添加服务.

我在应用程序加载时遇到异常

Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.google.firebase.iid.FirebaseInstanceIdInternalReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.firebase.INSTANCE_ID_EVENT pkg=com.xx.xx cmp=com.xx.xx/com.google.firebase.iid.FirebaseInstanceIdService (has extras) }: app is in background uid UidRecord{997e286 u0a92 RCVR idle procs:1 seq(0,0,0)}
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:3259)
       at android.app.ActivityThread.-wrap17(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6540)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.firebase.INSTANCE_ID_EVENT pkg=com.xx.xx cmp=com.xx.xx/com.google.firebase.iid.FirebaseInstanceIdService (has extras) }: app is in background uid UidRecord{997e286 u0a92 RCVR …
Run Code Online (Sandbox Code Playgroud)

android runtimeexception illegalstateexception firebase firebase-cloud-messaging

6
推荐指数
1
解决办法
5856
查看次数

在 Java 中序列化自定义异常中的字段

假设我有我的 custom RuntimeExceptionMyEntityJPA在哪里@Entity

@Getter
public class MyEntityAlreadyExistingException extends RuntimeException {

    private final MyEntity myEntity;

    public MyEntityAlreadyExistingException(MyEntity myEntity) {
        super(MessageFormat.format("MyEntity with name \"{0}\" already exists", myEntity.getName()));
        this.myEntity = myEntity;
    }
}
Run Code Online (Sandbox Code Playgroud)

声纳提示我进行myEntity瞬态或可序列化。

我应该如何处理这种情况?

我不使用任何 RMI,也不使用任何远程处理。它是一个相对简单的 Spring Boot Web 应用程序,带有 JPA。

如果我可以myEntity序列化,我以后可以利用哪些优势?

java serialization transient throwable runtimeexception

6
推荐指数
1
解决办法
792
查看次数

使用Java11运行Javafx应用程序时出现“ java.lang.RuntimeException:找不到工具包”错误

我们最近从Java 8迁移到了openJdk11。现在,我正在尝试使用两个操作系统上都安装的openJdk在Windows和ubuntu上测试我的应用程序。我可以在ubuntu上运行它。但是在Windows10中没有使用java11.Error_Message执行相同的操作:

在此处输入图片说明

java.lang.RuntimeException: No toolkit found
at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

runtimeexception windows-10 java-11 javafx-11

6
推荐指数
1
解决办法
2318
查看次数

Laravel 7 致命错误:未捕获运行时异常:尚未设置外观根

我查看了针对类似问题提出的几个答案,但对我的案例没有任何作用。仅供参考,这是我在 Laravel 7 中的第一个项目,在我的 Mac 上运行良好。我已按照本文在我的服务器上部署了该项目。在网络上运行该项目时,出现以下错误:

致命错误:未捕获运行时异常:尚未设置外观根。在 /usr/www/users/utopiqwvpw/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:258

堆栈跟踪:#0 /usr/www/users/utopiqwvpw/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(425): Illuminate\Support\Facades\Facade::__callStatic('replaceNamespac.. .', 数组) #1 /usr/www/users/utopiqwvpw/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(402): Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths() # 2 /usr/www/users/utopiqwvpw/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(313): Illuminate\Foundation\Exceptions\Handler->renderHttpException(Object(Symfony\Component\HttpKernel\)异常\HttpException))#3 /usr/www/users/utopiqwvpw/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(210):照亮\Foundation\Exceptions\Handler->prepareResponse(对象( Illuminate\Http\Request), Object(Symfony\Component\HttpKernel\Exception\HttpExcepti in /usr/www/users/utopiqwvpw/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php 第 258 行

我该如何修复它?

deployment runtimeexception composer-php laravel-facade laravel-7

6
推荐指数
1
解决办法
3万
查看次数