标签: runtimeexception

如何在线程中显示Toast消息?

我想Toast在线程中显示消息..但我得到了

RunTimeException:Can't create handler inside thread that has not called Looper.prepare()
Run Code Online (Sandbox Code Playgroud)

请帮我.提前致谢.

android toast runtimeexception

0
推荐指数
1
解决办法
9822
查看次数

运行时异常不终止程序

根据我的一点点java知识程序应该在它抛出运行时异常后终止.

但是在我的应用程序抛出运行时异常后它没有终止,并且因为我在linux上执行它我必须使用ctrl + c来终止它,否则它只是不会终止.

我在windows sytem上创建jar并将其复制粘贴到linux中.

我也在我的应用程序中启用了日志记录.

更新: 我没有捕获任何异常没有使用多线程.

java linux jar try-catch runtimeexception

0
推荐指数
1
解决办法
4572
查看次数

IntentService RuntimeException

可能重复:
Android RuntimeException:无法实例化服务

问题:开始IntentService生成一个RuntimeException.

我很无能为力.如果您需要更多信息,请询问.日志:

D/dalvikvm( 6839): newInstance failed: no <init>()
D/AndroidRuntime( 6839): Shutting down VM
W/dalvikvm( 6839): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 6839): FATAL EXCEPTION: main
E/AndroidRuntime( 6839): java.lang.RuntimeException: Unable to instantiate service org.xyz.android.service.MyService: java.lang.InstantiationException: org.xyz.android.service.MyService
E/AndroidRuntime( 6839):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:1929)
E/AndroidRuntime( 6839):    at android.app.ActivityThread.access$2500(ActivityThread.java:117)
E/AndroidRuntime( 6839):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
E/AndroidRuntime( 6839):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 6839):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 6839):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 6839):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 6839):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 6839):    at …
Run Code Online (Sandbox Code Playgroud)

android android-contentprovider runtimeexception intentservice

0
推荐指数
1
解决办法
2247
查看次数

java:异常:总是到达终点?

可能重复:
finally块是否始终运行?

让我们想象以下场景:

public void myMethod() throws MyException
  try
  {
     // do something
     // an Exception (for example an individual written MyException which extends 
     // "Exception" is thrown here
  }
  catch (OtherException e)
  {
    // do something
  }
  finally 
  {
    // do something else
  }
}
Run Code Online (Sandbox Code Playgroud)

如果在try块中抛出"MyException"并且不会被捕获 - 它们最终会被阻止,但是,对吗?

如果它是一个运行时异常会被抛出怎么办?最终块会到达吗?

有没有无法到达finally块的情况?

谢谢你的回答:-)

java exception-handling exception try-catch-finally runtimeexception

0
推荐指数
1
解决办法
1499
查看次数

MediaRecorder setAudioSource失败 - 应用程序崩溃(可能是由于CM13)

我按照视频教程编写了这段代码.我得到一个java.lang.RuntimeException: setAudioSource failed错误导致Unable to start activity

我在安装了Cyanogenmod 13的第一代Moto G上进行调试.我的假设是我的自定义ROM与MediaRecorder存在冲突.任何想法将不胜感激!

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Run Code Online (Sandbox Code Playgroud)

我还应该提一下,我在AndroidManifest中拥有正确的权限

    import android.media.MediaPlayer;
    import android.media.MediaRecorder;
    import android.os.Bundle;
    import android.os.Environment;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;

    import java.io.IOException;

    public class MainActivity extends AppCompatActivity {

    MediaRecorder myAudioRecorder;
    private String outputFile = null;
    private Button start, stop, play;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        start = (Button) findViewById(R.id.button1);
        stop = (Button) findViewById(R.id.button2);
        play = (Button) findViewById(R.id.button3);

        stop.setEnabled(false);
        play.setEnabled(false);
        outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myrec.3pg"; …
Run Code Online (Sandbox Code Playgroud)

java android runtimeexception mediarecorder

0
推荐指数
1
解决办法
2847
查看次数

如果继承类中没有构造函数,如何抛出异常?

我不确定这个问题是否合适,但我会尽我所能.

这是我的作业问题.如果两条线平行或相等,则作业要求我抛出异常.

原始代码由我的教授提供,我的工作是修改它以使其能够抛出异常.

line.h

class RuntimeException{
 private:
 string errorMsg;
 public:
 RuntimeException(const string& err) { errorMsg = err; }
 string getMessage() const { return errorMsg; }
};

class EqualLines: public RuntimeException{
 public:
 //empty
};

class ParallelLines: public RuntimeException{
 public:
 //empty
};

class Line{
 public:
 Line(double slope, double y_intercept): a(slope), b(y_intercept) {};
 double intersect(const Line L) const throw(ParallelLines,
                    EqualLines);
 //...getter and setter
 private:
 double a;
 double b;
};
Run Code Online (Sandbox Code Playgroud)

教授告诉我们不要修改头文件,只能修改.cpp文件.

line.cpp

double Line::intersect(const Line L) const throw(ParallelLines,
                       EqualLines){
 //below is my own code …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance exception-specification runtimeexception

0
推荐指数
1
解决办法
192
查看次数

未检测到主班

问题是,当我打开“ cmd.exe”并转到名为chesschallenge6的目录以输入“ sbt”命令并随后“运行”时,它不起作用。我收到一条错误消息,提示未指定主类。我检查了主类名称是否与它的文件名相同,甚至尝试了“对象ChessChallenge6扩展应用程序”,但仍然无法正常工作。解决方案很简单,但我看不到。

??? _chesschallenge6
    ??? _project
    ??? _target
    ??? _src      
        ??? _test
        ??? _main
            ??? _algorithm
            ??? _model
            ??? ChessChallenge6.scala
Run Code Online (Sandbox Code Playgroud)

program-entry-point scala class sbt runtimeexception

0
推荐指数
1
解决办法
7326
查看次数

为什么ideone.com这样做?

我最近试图在ideone.com中运行此代码...

#include <iostream>
#include <string>

using namespace std;

int getVal(string name)
{
    if (name == "Devashish") return 0;
    return 1;
}

int main()
{
    cout << 5 / getVal("Devashish");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

有趣的是,这段代码没有抛出任何异常并在输出中打印5.有意编写代码以产生异常.以下是成功编译和执行错误代码的ideone链接:http://ideone.com/ogDzDU

当我尝试在Visual Studio上执行相同的代码时,我得到了一个异常(这是预期的).只是好奇.为什么ideone表现如此?它是编译器或其他程序中的错误吗?

c++ exception runtimeexception

0
推荐指数
1
解决办法
292
查看次数

为什么在向量中的shared_ptr上调用方法会抛出运行时异常?

为什么以下代码抛出

Exception thrown at 0x53A5C6DC (nvoglv32.dll) in RenderEngine.exe: 0xC0000005: Access violation reading location 0x0002B174.
Run Code Online (Sandbox Code Playgroud)

在运行时,什么是一个很好的解决方案?

std::vector<std::shared_ptr<Static>> statics;

void drawStatics() {
    for (std::shared_ptr<Static> stat: statics) {
        Static *statptr = stat.get();

        statptr->Draw(); //This is what triggers the runtime exception.
    }
}

void addStatic(Mesh &mesh, Texture &texture, Transform transform) {
    statics.push_back(
        std::make_shared<Static>(
            mesh,
            texture,
            transform,
            shader,
            camera
        ));
}

int main() {
    addStatic(playerMesh, playerTexture, platformTransform);
    drawStatics();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Static头文件如下:

#pragma once

#include "mesh.h"
#include "texture.h"
#include "transform.h"
#include "camera.h"
#include "shader.h"

class …
Run Code Online (Sandbox Code Playgroud)

c++ shared-ptr runtimeexception

-3
推荐指数
1
解决办法
127
查看次数