Android Studio Emulator模拟器闪退解决方法

在Ubuntu 16.04系统下使用Android Studio的AVD Manager所创建的模拟器,在启动时可能会发生闪退的问题,Android Studio主界面左下角会显示 Emulator: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)错误,如下图所示。

分析原因,可能是由于电脑显卡硬件或驱动程序与模拟器不兼容所导致

此时,可以尝试打开AVD Manager,点击“Edit this AVD”按钮

  

在弹出的界面中,将Graphics选项从Automatic改为Software - GLES 2.0,并点击Finish

重启模拟器,问题修复,可以正常启动~

已标记关键词 清除标记
希望懂的大佬能帮帮忙,救救我,这个问题困扰我好久了,这个问题没解决就无法进行下一步。 1.最近使用Android studio编写了一个程序,写好代码后运行app到模拟器的时候会退(创建时程序版本和模拟器版本相同为5.1)。没有写代码时(也就是刚创建好程序,没添加任何东西时),在模拟器中能正常运行,但是当我写好代码后,运行app到模拟器上就会退了。 2.在代码部分,我是根据的SuperMap iMobile 9D(2019) for Android Guide的指导书写的,现在我也配置了许可,但还是会退 3.各个部分的代码如下: ``` <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.loadscence"> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|screenSize" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <supports-screens android:largeScreens="true" android:resizeable="true" android:normalScreens="true" android:anyDensity="true"/> </manifest> ///////////////////////////////////////////////////////////这是mainactivity.java的代码 package com.example.loadscence; import androidx.appcompat.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ZoomControls; import com.supermap.data.Environment; import com.supermap.data.Workspace; import com.supermap.data.WorkspaceConnectionInfo; import com.supermap.data.WorkspaceType; import com.supermap.mapping.MapControl; import com.supermap.mapping.MapView; public class MainActivity extends AppCompatActivity { private MapControl m_mapcontrol = null; private Workspace m_workspace; private MapView m_mapView; private ZoomControls m_zoom; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置一些系统需要用到的路径 String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath(); Environment. setLicensePath (rootPath + "/SuperMap/license/"); Environment. setTemporaryPath (rootPath + "/SuperMap/temp/"); Environment. setWebCacheDirectory (rootPath + "/SuperMap/WebCatch"); //组件功能必须在 Environment 初始化之后才能调用 Environment. initialization (this); //如果机器中默认不包括需要显示的字体,可以把相关字体文件放在参数所代表的路径中。 //例如,如果需要显示阿拉伯文字(若机器中原先不包括相关字体文件),可以把需要的字体文件放在参数所代表的路径中。 Environment. setFontsPath (rootPath + "/SuperMap/fonts/"); setContentView(R.layout. activity_main ); //打开工作空间 m_workspace = new Workspace(); WorkspaceConnectionInfo info = new WorkspaceConnectionInfo(); info.setServer(rootPath + "/SampleData/GeometryInfo/World.smwu"); info.setType(WorkspaceType. SMWU ); m_workspace.open(info); //将地图显示控件和工作空间关联 m_mapView = (MapView)findViewById(R.id. Map_view ); m_mapcontrol = m_mapView.getMapControl(); m_mapcontrol.getMap().setWorkspace(m_workspace); //打开工作空间中的第二幅地图 String mapName = m_workspace.getMaps().get(1); m_mapcontrol.getMap().open(mapName); m_zoom = (ZoomControls)findViewById(R.id. zoomControls1 ); m_mapView = (MapView)findViewById(R.id. Map_view ); m_zoom.setIsZoomInEnabled(true); m_zoom.setIsZoomOutEnabled(true); //放大按钮 m_zoom.setOnZoomInClickListener(new OnClickListener() { public void onClick(View v) { m_mapcontrol.getMap().zoom(2); m_mapcontrol.getMap().refresh(); } }); //缩小按钮 m_zoom.setOnZoomOutClickListener(new OnClickListener(){ public void onClick(View v) { m_mapcontrol.getMap().zoom(0.5); m_mapcontrol.getMap().refresh(); } }); m_mapcontrol.getMap().refresh(); } } ///////////////////////////////////////////////////////////这是activity的代码 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/main"> <RelativeLayout android:gravity="left" android:layout_width="match_parent" android:layout_height="match_parent"> <com.supermap.mapping.MapView android:id = "@+id/Map_view" android:layout_width="match_parent" android:layout_height = "match_parent"> </com.supermap.mapping.MapView> <ZoomControls android:id="@+id/zoomControls1" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ZoomControls> </RelativeLayout> </RelativeLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> ///////////////////////////////////////////////////////////报错日志如下: 03-23 22:32:10.438 22856-22856/com.example.loadscence E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.loadscence, PID: 22856 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.loadscence/com.example.loadscence.MainActivity}: java.lang.NullPointerException: Attempt to get length of null array at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.NullPointerException: Attempt to get length of null array at com.supermap.data.Environment.checkAndLoadLibrary64(Environment.java:1632) at com.supermap.data.Environment.initialization(Environment.java:576) at com.example.loadscence.MainActivity.onCreate(MainActivity.java:33) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)  at android.app.ActivityThread.access$800(ActivityThread.java:151)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5254)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)  ```
运行模拟器后,点击界面的任意控件都会弹出 很抱歉,”caihongpai“已停止运行 不知道这是为什么,求各位大神帮忙 logcat代码: ``` 03-09 07:50:14.924 3687-3687/? I/art: Late-enabling -Xcheck:jni 03-09 07:50:15.063 3687-3687/com.example.caihongpai W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 03-09 07:50:15.087 3687-3687/com.example.caihongpai I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper> 03-09 07:50:15.087 3687-3687/com.example.caihongpai I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper> 03-09 07:50:15.134 3687-3687/com.example.caihongpai D/AndroidRuntime: Shutting down VM 03-09 07:50:15.134 3687-3687/com.example.caihongpai E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.caihongpai, PID: 3687 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.caihongpai/com.example.caihongpai.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) at android.app.ActivityThread.access$800(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5305) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at com.example.caihongpai.MainActivity.onCreate(MainActivity.java:121) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)  at android.app.ActivityThread.access$800(ActivityThread.java:153)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5305)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)  下面的是.java代码: package com.example.caihongpai; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; public class MainActivity extends AppCompatActivity { Button b1; ImageButton ib1,ib2,ib3; ImageView i1,i2,i3; TextView t1; static int[] s1={R.drawable.fangpian,R.drawable.heitao,R.drawable.hongtao}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(Button)findViewById(R.id.button); ib1=(ImageButton) findViewById(R.id.ib1); ib2=(ImageButton) findViewById(R.id.ib2); ib2=(ImageButton) findViewById(R.id.ib2); i1=(ImageView) findViewById(R.id.i1); i2=(ImageView) findViewById(R.id.i2); i3=(ImageView) findViewById(R.id.i3); ib1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ib1.setImageResource(s1[0]); ib2.setImageResource(s1[1]); ib3.setImageResource(s1[2]); if(s1[0]==R.drawable.hongtao){ new AlertDialog.Builder(MainActivity.this) .setTitle("奥利给") .setMessage("小伙子,你答对了,真是个天才!!") .setPositiveButton("确认",null) .show(); i3.setVisibility(View.VISIBLE); ib1.setVisibility(View.INVISIBLE); ib2.setVisibility(View.INVISIBLE); ib3.setVisibility(View.INVISIBLE); }else{ new AlertDialog.Builder(MainActivity.this) .setTitle("向我开炮") .setMessage("小傻瓜,你答错了,真是个小笨蛋!!") .setPositiveButton("确认",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialogInterface, int which) { return; } }) .setNegativeButton("再试一次", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { xp(); } }) .show(); i3.setVisibility(View.VISIBLE); ib1.setVisibility(View.INVISIBLE); ib2.setVisibility(View.INVISIBLE); ib3.setVisibility(View.INVISIBLE); } } }); ib2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ib1.setImageResource(s1[0]); ib2.setImageResource(s1[1]); ib3.setImageResource(s1[2]); if(s1[1]==R.drawable.hongtao){ new AlertDialog.Builder(MainActivity.this) .setTitle("奥利给") .setMessage("小伙子,你答对了,真是个天才!!") .setPositiveButton("确认",null) .show(); i3.setVisibility(View.VISIBLE); ib1.setVisibility(View.INVISIBLE); ib2.setVisibility(View.INVISIBLE); ib3.setVisibility(View.INVISIBLE); }else{ new AlertDialog.Builder(MainActivity.this) .setTitle("向我开炮") .setMessage("小傻瓜,你答错了,真是个小笨蛋!!") .setPositiveButton("确认",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialogInterface, int which) { return; } }) .setNegativeButton("再试一次", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { xp(); } }) .show(); i3.setVisibility(View.VISIBLE); ib1.setVisibility(View.INVISIBLE); ib2.setVisibility(View.INVISIBLE); ib3.setVisibility(View.INVISIBLE); } } }); ib3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ib1.setImageResource(s1[0]); ib2.setImageResource(s1[1]); ib3.setImageResource(s1[2]); if(s1[2]==R.drawable.hongtao){ new AlertDialog.Builder(MainActivity.this) .setTitle("奥利给") .setMessage("小伙子,你答对了,真是个天才!!") .setPositiveButton("确认",null) .show(); i3.setVisibility(View.VISIBLE); ib1.setVisibility(View.INVISIBLE); ib2.setVisibility(View.INVISIBLE); ib3.setVisibility(View.INVISIBLE); }else{ new AlertDialog.Builder(MainActivity.this) .setTitle("向我开炮") .setMessage("小傻瓜,你答错了,真是个小笨蛋!!") .setPositiveButton("确认",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialogInterface, int which) { return; } }) .setNegativeButton("再试一次", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { xp(); } }) .show(); i3.setVisibility(View.VISIBLE); ib1.setVisibility(View.INVISIBLE); ib2.setVisibility(View.INVISIBLE); ib3.setVisibility(View.INVISIBLE); } } }); } private void xp() { for (int i = 0; i < 3; i++) { int tmp = s1[i]; int s = (int) (Math.random() * 2); s1[i] = s1[s]; s1[s] = tmp; } } } 下面的是xml代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#0CC6BB" tools:context=".MainActivity"> <TextView android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="猜猜红桃A在哪" android:textSize="30dp" android:gravity="center" android:layout_marginTop="50dp" /> <FrameLayout android:layout_width="match_parent" android:layout_height="180dp" android:layout_margin="10dp" android:orientation="horizontal"> <LinearLayout android:layout_width="match_parent" android:layout_height="180dp" android:orientation="horizontal"> <ImageButton android:id="@+id/ib1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:layout_weight="1" android:foregroundGravity="top" app:srcCompat="@drawable/beimian" /> <ImageButton android:id="@+id/ib2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:layout_weight="1" android:foregroundGravity="top" app:srcCompat="@drawable/beimian" /> <ImageButton android:id="@+id/ib3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:layout_weight="1" android:foregroundGravity="top" app:srcCompat="@drawable/beimian" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="180dp" android:orientation="horizontal"> <ImageView android:id="@+id/i1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:layout_weight="1" app:srcCompat="@drawable/heitao" android:visibility="invisible"/> <ImageView android:id="@+id/i2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:layout_weight="1" app:srcCompat="@drawable/fangpian" android:visibility="invisible"/> <ImageView android:id="@+id/i3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:layout_weight="1" app:srcCompat="@drawable/hongtao" android:visibility="invisible" /> </LinearLayout> </FrameLayout> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp" android:text="让我再玩一次噻" android:textSize="20dp" /> </LinearLayout> ```
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页