如果被其他应用程序调用,我的自定义相机应用程序会崩溃。
例如,我的相机是由我的音轨调用的。如果你按下我音轨的相机图标,它会弹出并让用户选择要使用的相机。我试过使用我的相机,但它崩溃了。但是如果我从应用程序菜单中单击相机,我的相机就可以正常工作。
AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<application android:theme="@style/AppTheme"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:allowBackup="true">
<activity android:name=".CameraActivity" android:clearTaskOnLaunch="false">
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:label="@string/app_name"
android:name="com.joules.prdpcamera.GPSInitialize"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="@string/app_name"
android:name="com.joules.prdpcamera.MainActivity"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.MAINACTIVITY" />
</intent-filter>
</activity>
</application>
我的创建()
方法:
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(R.layout.gpsinitial);
this.textLat = ((TextView)findViewById(R.id.vLatitude));
this.textLong = ((TextView)findViewById(R.id.vLongitude));
this.txtIni = ((TextView)findViewById(R.id.textView1));
this.marginError = ((TextView)findViewById(R.id.vME));
this.tvview = ((TextView)findViewById(R.id.tvView));
this.btnCam = ((Button)findViewById(R.id.btnCamera));
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
日志猫:
03-04 08:32:02.049: I/Choreographer(3273): Skipped 56 frames! The application may be doing too much work on its main thread.
03-04 08:32:02.479: D/gralloc_goldfish(3273): Emulator without GPU emulation detected.
03-04 08:32:13.809: D/dalvikvm(3273): GC_FOR_ALLOC freed 127K, 7% free 2970K/3164K, paused 222ms, total 223ms
03-04 08:32:13.819: I/dalvikvm-heap(3273): Grow heap (frag case) to 4.133MB for 1228816-byte allocation
03-04 08:32:14.089: D/dalvikvm(3273): GC_FOR_ALLOC freed <1K, 5% free 4170K/4368K, paused 235ms, total 235ms
03-04 08:32:14.339: D/dalvikvm(3273): GC_FOR_ALLOC freed <1K, 5% free 4170K/4368K, paused 143ms, total 144ms
03-04 08:32:14.489: I/dalvikvm-heap(3273): Grow heap (frag case) to 5.304MB for 1228816-byte allocation
03-04 08:32:14.629: D/dalvikvm(3273): GC_FOR_ALLOC freed <1K, 4% free 5370K/5572K, paused 138ms, total 138ms
03-04 08:32:16.269: D/dalvikvm(3273): GC_FOR_ALLOC freed 1200K, 25% free 4254K/5656K, paused 256ms, total 257ms
03-04 08:32:16.349: I/dalvikvm-heap(3273): Grow heap (frag case) to 6.471MB for 2366704-byte allocation
03-04 08:32:17.609: D/dalvikvm(3273): GC_FOR_ALLOC freed <1K, 18% free 6565K/7968K, paused 226ms, total 227ms
03-04 08:32:18.529: D/AndroidRuntime(3273): Shutting down VM
03-04 08:32:18.529: W/dalvikvm(3273): threadid=1: thread exiting with uncaught exception (group=0xb3adfba8)
03-04 08:32:18.549: E/AndroidRuntime(3273): FATAL EXCEPTION: main
03-04 08:32:18.549: E/AndroidRuntime(3273): Process: com.joules.prdpcamera, PID: 3273
03-04 08:32:18.549: E/AndroidRuntime(3273): java.lang.NullPointerException
03-04 08:32:18.549: E/AndroidRuntime(3273): at android.media.ExifInterface.saveAttributes(ExifInterface.java:265)
03-04 08:32:18.549: E/AndroidRuntime(3273): at com.joules.prdpcamera.MainActivity.UpdateGeoTag(MainActivity.java:635)
03-04 08:32:18.549: E/AndroidRuntime(3273): at com.joules.prdpcamera.MainActivity$4.onPictureTaken(MainActivity.java:590)
03-04 08:32:18.549: E/AndroidRuntime(3273): at android.hardware.Camera$EventHandler.handleMessage(Camera.java:917)
03-04 08:32:18.549: E/AndroidRuntime(3273): at android.os.Handler.dispatchMessage(Handler.java:102)
03-04 08:32:18.549: E/AndroidRuntime(3273): at android.os.Looper.loop(Looper.java:136)
03-04 08:32:18.549: E/AndroidRuntime(3273): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-04 08:32:18.549: E/AndroidRuntime(3273): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 08:32:18.549: E/AndroidRuntime(3273): at java.lang.reflect.Method.invoke(Method.java:515)
03-04 08:32:18.549: E/AndroidRuntime(3273): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-04 08:32:18.549: E/AndroidRuntime(3273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-04 08:32:18.549: E/AndroidRuntime(3273): at dalvik.system.NativeStart.main(Native Method)
03-04 08:32:28.839: I/Process(3273): Sending signal. PID: 3273 SIG: 9
03-04 08:33:05.939: D/dalvikvm(3327): GC_FOR_ALLOC freed 35K, 4% free 2852K/2956K, paused 48ms, total 51ms
03-04 08:33:05.989: I/dalvikvm-heap(3327): Grow heap (frag case) to 6.385MB for 3712464-byte allocation
03-04 08:33:06.029: D/dalvikvm(3327): GC_FOR_ALLOC freed 2K, 2% free 6474K/6584K, paused 39ms, total 39ms
03-04 08:33:06.839: D/gralloc_goldfish(3327): Emulator without GPU emulation detected.
03-04 08:33:26.809: I/Choreographer(3327): Skipped 144 frames! The application may be doing too much work on its main thread.
03-04 08:33:35.429: D/dalvikvm(3327): GC_FOR_ALLOC freed 87K, 3% free 6765K/6920K, paused 220ms, total 223ms
03-04 08:33:36.019: D/dalvikvm(3327): GC_FOR_ALLOC freed 4K, 3% free 7961K/8124K, paused 188ms, total 189ms
03-04 08:33:37.609: D/dalvikvm(3327): GC_FOR_ALLOC freed 1200K, 15% free 8045K/9412K, paused 220ms, total 222ms
03-04 08:33:37.729: I/dalvikvm-heap(3327): Grow heap (frag case) to 10.173MB for 2366704-byte allocation
03-04 08:33:38.119: D/dalvikvm(3327): GC_FOR_ALLOC freed <1K, 12% free 10356K/11724K, paused 44ms, total 45ms
03-04 08:33:38.719: D/AndroidRuntime(3327): Shutting down VM
03-04 08:33:38.719: W/dalvikvm(3327): threadid=1: thread exiting with uncaught exception (group=0xb3adfba8)
03-04 08:33:38.729: E/AndroidRuntime(3327): FATAL EXCEPTION: main
03-04 08:33:38.729: E/AndroidRuntime(3327): Process: com.joules.prdpcamera, PID: 3327
03-04 08:33:38.729: E/AndroidRuntime(3327): java.lang.NullPointerException
03-04 08:33:38.729: E/AndroidRuntime(3327): at android.media.ExifInterface.saveAttributes(ExifInterface.java:265)
03-04 08:33:38.729: E/AndroidRuntime(3327): at com.joules.prdpcamera.MainActivity.UpdateGeoTag(MainActivity.java:635)
03-04 08:33:38.729: E/AndroidRuntime(3327): at com.joules.prdpcamera.MainActivity$4.onPictureTaken(MainActivity.java:590)
03-04 08:33:38.729: E/AndroidRuntime(3327): at android.hardware.Camera$EventHandler.handleMessage(Camera.java:917)
03-04 08:33:38.729: E/AndroidRuntime(3327): at android.os.Handler.dispatchMessage(Handler.java:102)
03-04 08:33:38.729: E/AndroidRuntime(3327): at android.os.Looper.loop(Looper.java:136)
03-04 08:33:38.729: E/AndroidRuntime(3327): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-04 08:33:38.729: E/AndroidRuntime(3327): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 08:33:38.729: E/AndroidRuntime(3327): at java.lang.reflect.Method.invoke(Method.java:515)
03-04 08:33:38.729: E/AndroidRuntime(3327): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-04 08:33:38.729: E/AndroidRuntime(3327): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-04 08:33:38.729: E/AndroidRuntime(3327): at dalvik.system.NativeStart.main(Native Method)
03-04 08:33:55.149: I/Process(3327): Sending signal. PID: 3327 SIG: 9
03-04 08:33:58.609: D/dalvikvm(3361): GC_FOR_ALLOC freed 39K, 4% free 2852K/2960K, paused 58ms, total 62ms
03-04 08:33:58.659: I/dalvikvm-heap(3361): Grow heap (frag case) to 6.385MB for 3712464-byte allocation
03-04 08:33:58.719: D/dalvikvm(3361): GC_FOR_ALLOC freed 2K, 2% free 6475K/6588K, paused 51ms, total 51ms
03-04 08:33:59.899: D/gralloc_goldfish(3361): Emulator without GPU emulation detected.
相机活动:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "Storing image... Please wait...", Toast.LENGTH_LONG).show();
Parameters params = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_AUTO);
Camera.Parameters parameters = cam.getParameters();
params.set("orientation", "portrait");
cam.setParameters(params);
cam.takePicture(shutterCallback, null, jpegCallback);
}
});
SurfaceView surface = (SurfaceView)findViewById(R.id.surfaceview);
SurfaceHolder holder = surface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.setFixedSize(400, 300);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
//vlatitude = df.format(clat);
//vlongitude = df.format(clng);
}
这是我的启动器,当我的应用程序启动时首先调用它:
public class GPSInitialize extends Activity {
public static final String tag = null;
Button btnCam;
TextView marginError;
TextView textLat;
TextView textLong;
TextView tvview;
TextView txtIni;
public void onBackPressed()
{
super.onBackPressed();
finish();
System.exit(0);
}
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(R.layout.gpsinitial);
this.textLat = ((TextView)findViewById(R.id.vLatitude));
this.textLong = ((TextView)findViewById(R.id.vLongitude));
this.txtIni = ((TextView)findViewById(R.id.textView1));
this.marginError = ((TextView)findViewById(R.id.vME));
this.tvview = ((TextView)findViewById(R.id.tvView));
this.btnCam = ((Button)findViewById(R.id.btnCamera));
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
public boolean onCreateOptionsMenu(Menu paramMenu)
{
getMenuInflater().inflate(2131165184, paramMenu);
return true;
}
protected void onResume()
{
super.onResume();
}
public void startCamera(View paramView)
{
startActivity(new Intent(this, MainActivity.class));
}
private class myLocationListener implements LocationListener
{
private myLocationListener()
{
}
public void onLocationChanged(Location paramLocation)
{
if (paramLocation != null)
{
double d1 = paramLocation.getLatitude();
double d2 = paramLocation.getLongitude();
float f = paramLocation.getAccuracy();
GPSInitialize.this.textLat.setText(Double.toString(d1));
GPSInitialize.this.textLong.setText(Double.toString(d2));
GPSInitialize.this.txtIni.setText("GPS Locked");
GPSInitialize.this.tvview.setText("Coordinates found");
GPSInitialize.this.marginError.setText(Float.toString(f));
PSInitialize.this.btnCam.setEnabled(true);
}
}
public void onProviderDisabled(String paramString)
{
Log.v(GPSInitialize.tag, "Your GPS is not currently turn ON");
Toast.makeText(GPSInitialize.this, "GPS not found. Please turn ON your GPS", 1).show();
Intent localIntent = new Intent("android.settings.LOCATION_SOURCE_SETTINGS");
GPSInitialize.this.startActivity(localIntent);
}
public void onProviderEnabled(String paramString)
{
Toast.makeText(GPSInitialize.this, "GPS found. Initializing GPS", 1).show();
}
public void onStatusChanged(String paramString, int paramInt, Bundle paramBundle)
{
}
}
}
我主要活动的一部分
public class MainActivity extends Activity implements SurfaceHolder.Callback {
protected static final String TAG = null;
private boolean focusing;
private Camera cam;
SurfaceHolder holder;
private boolean isDoubleBackPressd = false;
String vlatitude;
String vlongitude;
String filename;
String timeStamp;
String flat;
String flong;
String latref;
String longref;
String outbar;
String outbar2;
String digitake;
String datePic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
LinearLayout l = new LinearLayout(this);
l.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
l.setOrientation(LinearLayout.VERTICAL);
ImageButton b=(ImageButton) findViewById(R.id.Button1);
b.setOnClickListener(new View.OnClickListener() {
@Override公共空白上单击(查看 v) { // TODO 自动生成的方法存根 Toast.make 文本(MainActivity.this, “存储图像...请稍候...“,Toast.LENGTH_LONG)显示();参数参数 = 凸轮参数();params.setFlashMode(Parameters.FLASH_MODE_AUTO);相机参数参数 = 凸轮参数();
params.set("orientation", "portrait");
cam.setParameters(params);
cam.takePicture(shutterCallback, null, jpegCallback);
}
});
SurfaceView surface = (SurfaceView)findViewById(R.id.surfaceview);
SurfaceHolder holder = surface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.setFixedSize(400, 300);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
//vlatitude = df.format(clat);
//vlongitude = df.format(clng);
}
private static final int WHITE = 0xFFFFFFFF;
private static final int BLACK = 0xFF000000;
private class myLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if(location !=null){
double clat=location.getLatitude();
double clng=location.getLongitude();
DecimalFormat df = new DecimalFormat("###.######");
vlatitude = df.format(clat);
vlongitude = df.format(clng);
int num1Lat = (int)Math.floor(clat);
int num2Lat = (int)Math.floor((clat - num1Lat) * 60);
double num3Lat = (clat - ((double)num1Lat+((double)num2Lat/60))) * 3600000;
int num1Lon = (int)Math.floor(clng);
int num2Lon = (int)Math.floor((clng - num1Lon) * 60);
double num3Lon = (clng - ((double)num1Lon+((double)num2Lon/60))) * 3600000;
flat = num1Lat+"/1,"+num2Lat+"/1,"+num3Lat+"/1000";
flong = num1Lon+"/1,"+num2Lon+"/1,"+num3Lon+"/1000";
//edit: vlatitude, vlongitude, flat, flong, outbar, outbar2
if (clat > 0) {
latref = "N";
} else {
latref = "S";
}
if (clng> 0) {
longref = "E";
} else {
longref = "W";
}
//Toast.makeText(MainActivity.this, "GPS is Excellent", Toast.LENGTH_LONG).show();
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
//--------------
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
}
/*
* initiate auto focus
*/
AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean arg0, Camera arg1) {
// TODO Auto-generated method stub
cam.autoFocus(this);
focusing = true;
//Toast.makeText(getApplicationContext(), "Focused", Toast.LENGTH_SHORT).show();
}
};
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
cam.stopPreview();
cam.startPreview();
}
@Override
public void surfaceCreated(SurfaceHolder arg0)
{
// TODO Auto-generated method stub
try
{
Camera.Parameters parameters = cam.getParameters();
if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
cam.autoFocus(new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
//Log.d(TAG, “AutoFocus: “ + (success ? “Succeeded” : “Failed”));
//cam.autoFocus(myAutoFocusCallback);
}
});
cam.setPreviewCallback(new PreviewCallback()
{
@Override
public void onPreviewFrame(byte[] data, Camera camera)
{
int quality = 100;
Size previewSize = camera.getParameters().getPreviewSize();
YuvImage image = new YuvImage(data, ImageFormat.NV21,previewSize.width, previewSize.height, null);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
image.compressToJpeg(new Rect(0, 0,previewSize.width, previewSize.height),quality, outputStream);
}
});
Timer tim=new Timer();
tim.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
cam.startPreview();
}
}, 3000);
}
cam.setPreviewDisplay(arg0);
cam.setDisplayOrientation(90);
cam.startPreview();
// TODO Draw over the preview if required.
} catch (IOException e)
{
//Log.d(TAG, “IO Exception”, e);
}
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
Parameters params = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
holder.removeCallback(this);
cam.stopPreview();
cam.release();
focusing = false;
cam=null;
}
正如LogCat
所说:NullPointerException
在文件ExifInterface.java
行265
。
查看MainActivity。java
lines590
和635
或发布您的
我制作了一个OpenGL应用程序,用于测试Framebuffer Objects,该应用程序适用于我制作的笔记本电脑,我拥有的另一台笔记本电脑和我的台式PC。但是,对于我要求为我测试该应用程序的其他人来说,它似乎崩溃了。 到目前为止,我已经将它缩小到在我调用的第一个扩展(在本例中为glGenBuffers)上崩溃,我100%确定在调用该函数(见下文)之前不会调用该扩展。在浏览了许多答案后,我确定了
一调用方法,我的计时器应用程序就崩溃了,它显示的对象引用为空,尽管我做得正确,但我找不到问题。请,某人,看看下面的代码:(我也附上logcat) 原因:java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“void android.os.CountDownTimer.Cancel()”
我使用Android11,目标是: compileSdkVersion 31 defaultConfig { applicationId “com.pro.prowh” minSdkVersion 24 targetSdkVersion 31 versionCode 16 versionName “22.01.12” } 在清单中,我使用: MyApp创建文件夹/storage/emulated/
我们的应用程序作为后台服务运行,不断从前置摄像头获取图像,然后处理图像。然而,当用户尝试打开另一个使用摄像头的应用程序时,会发生两件事:要么新应用程序崩溃,我们的应用程序继续,要么我们崩溃,新应用程序访问摄像头。 现在,如果我们的应用程序失去了对摄像头的控制,我们可以捕捉到一个异常,然后我们可以开始尝试访问它,直到我们获得访问权限,一切恢复正常。 问题是当其他应用程序因我们的应用程序而崩溃时。有什
如果我设置,则应用程序在打开使用第三方库的活动时就会开始崩溃。 art/runtime/java_vm_ext.cc:410]JNI检测到应用程序中的错误:调用了JNI NewGlobalRef,但出现了挂起的异常java.lang.NoSuchFielderRror:类“LCOM/nTreaming/nPlayerEngine/nFactory;”或其超类中没有“I”字段“MalFactoryC