Java Android 致命信号 11 (SIGSEGV),代码 1,tid 29092 中的故障地址 0x0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35250816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 16:27:48  来源:igfitidea点击:

Android Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 29092

javaandroidandroid-animationfatal-error

提问by hashcode55

I'm try to play a loading animation on my loading screen, and I read somewhere that android doesn't support gifs so either you have to break in into frames and then play it or we can use the Movie class.

我试图在我的加载屏幕上播放加载动画,我在某处读到 android 不支持 gif,所以要么你必须插入帧然后播放它,要么我们可以使用 Movie 类。

Heres the leading activity -

这是主要活动 -

package com.myapp.mehul.login.activity;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;

import com.myapp.mehul.login.MYGIFView;
import com.myapp.mehul.login.MainActivity;
import com.myapp.mehul.login.R;
import com.myapp.mehul.login.app.Constants;

import org.json.JSONException;
import org.json.JSONObject;

import java.net.URISyntaxException;

import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;


/**
 * Created by mehul on 2/6/16.
 */
public class LoadingScreen extends Activity {

    /** Duration of wait **/
    private final int SPLASH_DISPLAY_LENGTH = 1000;

    /** Called when the activity is first created. */
    private Socket mSocket;
    String you;
    String opponentId;
    String username;

    {
        try {
            mSocket = IO.socket(Constants.CHAT_SERVER_URL);
        } catch (URISyntaxException e) {

            throw new RuntimeException(e);
        }
    }
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(new MYGIFView(getApplicationContext()));
        //initialise the socket
        mSocket.connect();
        //call add user
        mSocket.emit("add user");
        //start a listener for opponent
        mSocket.on("opponent", onOpponent);
        //initialise the username
        username = getIntent().getExtras().getString("username");
    }

    private Emitter.Listener onOpponent = new Emitter.Listener(){
        @Override
        public  void call(final Object... args){
            LoadingScreen.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    JSONObject data = (JSONObject) args[0];

                    try {
                        you = data.getString("you");
                        opponentId = data.getString("opponent");
                        Log.d("LoadingScreen", data.toString());


                        //setResult(RESULT_OK, i);


                        finish();
                    } catch (JSONException e) {
                        return;
                    }
                    Intent i = new Intent(LoadingScreen.this, MainActivity.class);
                    i.putExtra("opponentId", opponentId);
                    i.putExtra("you", you);
                    i.putExtra("username", username);
                    Log.d("goToChat", username);
                    startActivity(i);
                }
            });
        }
    };

    @Override
    public void onBackPressed(){

        AlertDialog.Builder builder = new AlertDialog.Builder(LoadingScreen.this);
        builder.setMessage("I knew you didn't have BALLS.").setCancelable(
                false).setPositiveButton("I am a LOSER",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        //send the logout information to the server
                        JSONObject discon = new JSONObject();
                        try {
                            discon.put("opponent", opponentId);
                            discon.put("you", you);
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        mSocket.emit("discon", discon);
                        mSocket.disconnect();

                        //finish the current activity.
                        Intent intent = new Intent(LoadingScreen.this, MainMenu.class);
                        startActivity(intent);
                        LoadingScreen.this.finish();

                    }
                }).setNegativeButton("I'll fkin face it",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }

}

In the above code I've set content view by passing it an instance of MYGIFView.class -

在上面的代码中,我通过传递一个 MYGIFView.class 的实例来设置内容视图 -

Heres MYGIFView.class

继承人 MYGIFView.class

package com.myapp.mehul.login;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.view.View;

import java.io.InputStream;

/**
 * Created by mehul on 2/7/16.
 */
public class MYGIFView extends View{
    Movie movie,movie1;

    InputStream is=null,is1=null;

    long moviestart;
    public MYGIFView(Context context) {
        super(context);

        is=context.getResources().openRawResource(+ R.drawable.loading);

        movie=Movie.decodeStream(is);

    }
    @Override
    protected void onDraw(Canvas canvas) {

        canvas.drawColor(Color.WHITE);
        super.onDraw(canvas);
        long now=android.os.SystemClock.uptimeMillis();
        System.out.println("now="+now);
        if (moviestart == 0) { // first time
            moviestart = now;

        }
        System.out.println("\tmoviestart="+moviestart);
        int relTime = (int)((now - moviestart) % movie.duration()) ;
        System.out.println("time="+relTime+"\treltime="+movie.duration());
        movie.setTime(relTime);
        movie.draw(canvas,this.getWidth()/2-20,this.getHeight()/2-40);
        this.invalidate();
    }
}

The loading activity IS creating an instance of MYGIFView.class and it logs the data but then it gives fatal signal 11. I tried to search but I didn't get any answer.

加载活动正在创建 MYGIFView.class 的一个实例,它记录数据,但随后给出致命信号 11。我尝试搜索,但没有得到任何答案。

console log -

控制台日志 -

02-07 12:22:30.321 29092-29092/? I/art: Late-enabling -Xcheck:jni
02-07 12:22:30.341 29092-29102/? I/art: Debugger is no longer active

02-07 12:22:30.422 29092-29092/? D/SQLiteHandler: Fetching user from Sqlite: {username=Harsh}
02-07 12:22:30.422 29092-29092/? D/LoginActivity: already logged in
02-07 12:22:30.425 29092-29092/? I/Timeline: Timeline: Activity_launch_request id:com.myapp.mehul.login time:71360781
02-07 12:22:30.487 29092-29092/? D/MainMenu: painted again
02-07 12:22:30.490 29092-29092/? D/SQLiteHandler: Fetching user from Sqlite: {username=Harsh}
02-07 12:22:30.554 29092-29149/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-07 12:22:30.559 29092-29092/? D/Atlas: Validating map...
02-07 12:22:30.596 29092-29149/? I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.01.00.042.030_msm8974_LA.BF.1.1.1_RB1__release_AU ()
                                               OpenGL ES Shader Compiler Version: E031.25.03.06
                                               Build Date: 04/15/15 Wed
                                               Local Branch: mybranch9068252
                                               Remote Branch: quic/LA.BF.1.1.1_rb1.19
                                               Local Patches: NONE
                                               Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.01.00.042.030 +  NOTHING
02-07 12:22:30.597 29092-29149/? I/OpenGLRenderer: Initialized EGL, version 1.4
02-07 12:22:30.611 29092-29149/? D/OpenGLRenderer: Enabling debug mode 0
02-07 12:22:30.660 29092-29092/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@387f1572 time:71361016
02-07 12:22:31.898 29092-29092/com.myapp.mehul.login D/go?to?chat: was called
02-07 12:22:31.899 29092-29092/com.myapp.mehul.login I/Timeline: Timeline: Activity_launch_request id:com.myapp.mehul.login time:71362255
02-07 12:22:31.997 29092-29092/com.myapp.mehul.login I/System.out: now=71362353
02-07 12:22:31.997 29092-29092/com.myapp.mehul.login I/System.out:  moviestart=71362353
02-07 12:22:31.997 29092-29092/com.myapp.mehul.login I/System.out: time=0   reltime=1850
02-07 12:22:32.007 29092-29092/com.myapp.mehul.login A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 29092 (app.mehul.login)
02-07 12:22:32.541 29092-29092/com.myapp.mehul.login W/app.mehul.login: type=1701 audit(0.0:302): auid=4294967295 uid=10250 gid=10250 ses=4294967295 subj=u:r:untrusted_app:s0 reason="memory violation" sig=11

采纳答案by hashcode55

I received a batch for this question which means its being viewed a lot, so I'll answer this question -

我收到了这个问题的一批,这意味着它被查看了很多,所以我来回答这个问题 -

What I figured out was the line below was throwing the error -

我发现下面的行抛出了错误 -

movie.draw(canvas,this.getWidth()/2-20,this.getHeight()/2-40);

Now the problem is that this error specifically can be caused by lots of reasons, its never a specific reason.. the reason mine wasn't working out was because my device didn't work well with hardware acceleration, so I just had to disable it in the manifest application, like this -

现在的问题是,这个错误可能是由很多原因引起的,它从来都不是一个特定的原因。它在清单应用程序中,像这样 -

<android:hardwareAccelerated="false">

Now its possible that the reason might not be the same....but the core reason is the same, its memory related, and most chances are its a bug in the firmware of the device or emulator you are testing upon.

现在可能原因可能不一样......但核心原因是相同的,它的内存相关,并且最有可能是您正在测试的设备或模拟器的固件中的错误。

回答by George Sideris

In the Manifest set in your activity :

在您的活动中的清单集中:

    <activity
        android:name="LoadingScreen"
        android:hardwareAccelerated="false">
    </activity>