问题描述
如果称为由另一个应用程序自定义我的相机应用程式崩溃。
例如像,我的相机是我的轨道调用。如果preSS我的轨道的摄像机图标,会弹出并让用户选择什么样的相机要使用。我试图用我的相机,但它崩溃。但是,如果我从应用程序菜单中单击摄像头,我的相机能正常工作。
的AndroidManifest.xml
<使用许可权的android:NAME =android.permission.CAMERA/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用许可权的android:NAME =android.permission.WRITE_INTERNAL_STORAGE/>
<使用特征的android:NAME =android.hardware.camera/>
<使用特征的android:NAME =android.hardware.camera.autofocus/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
<使用许可权的android:NAME =com.android.launcher.permission.INSTALL_SHORTCUT/><应用机器人:主题=@风格/ AppTheme
机器人:标签=@字符串/ APP_NAME
机器人:图标=@绘制/ ic_launcher
机器人:allowBackup =真正的> <活动机器人:CameraActivityNAME =机器人:clearTaskOnLaunch =假>
&所述;意图滤光器>
<作用机器人:名字=android.media.action.IMAGE_CAPTURE/>
<类机器人:名字=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT; <活动机器人:标签=@字符串/ APP_NAME
机器人:名字=com.joules.prdpcamera.GPSInitialize
机器人:screenOrientation =画像
机器人:configChanges =keyboardHidden |方向>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/>
<类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT; <活动机器人:标签=@字符串/ APP_NAME
机器人:名字=com.joules.prdpcamera.MainActivity
机器人:screenOrientation =画像
机器人:configChanges =keyboardHidden |方向> &所述;意图滤光器>
<类机器人:名字=android.intent.category.DEFAULT/>
<作用机器人:名字=android.intent.action.MAINACTIVITY/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
我的的onCreate()
方法:
保护无效的onCreate(捆绑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 =((按钮)findViewById(R.id.btnCamera)); LM的LocationManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener的LL =新myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,LL);
}
LogCat中:
8月3日至4日:32:02.049:I /编舞(3273):56跳过帧!该应用程序可能会做它的主线程的工作太多了。
8月3日至4日:32:02.479:D / gralloc_goldfish(3273):无仿真模拟GPU检测。
8月3日至4日:32:13.809:D / dalvikvm(3273):GC_FOR_ALLOC释放127K,7%的游离2970K / 3164K,暂停222ms,223ms总
8月3日至4日:32:13.819:I / dalvikvm堆(3273):成长堆(frag的情况下),以4.133MB为1228816字节分配
8月3日至4日:32:14.089:D / dalvikvm(3273):GC_FOR_ALLOC释放< 1K,5%的游离4170K / 4368K,暂停235ms,235ms总
8月3日至4日:32:14.339:D / dalvikvm(3273):GC_FOR_ALLOC释放< 1K,5%的游离4170K / 4368K,暂停143ms,144ms总
8月3日至4日:32:14.489:I / dalvikvm堆(3273):成长堆(frag的情况下),以5.304MB为1228816字节分配
8月3日至4日:32:14.629:D / dalvikvm(3273):GC_FOR_ALLOC释放< 1K,4%免费5370K / 5572K,暂停138ms,138ms总
8月3日至4日:32:16.269:D / dalvikvm(3273):GC_FOR_ALLOC释放1200K,25%的自由4254K / 5656K,暂停256毫秒,总257ms
8月3日至4日:32:16.349:I / dalvikvm堆(3273):成长堆(frag的情况下),以6.471MB为2366704字节分配
8月3日至4日:32:17.609:D / dalvikvm(3273):GC_FOR_ALLOC释放< 1K,18%免费6565K / 7968K,暂停226ms,227ms总
8月3日至4日:32:18.529:D / AndroidRuntime(3273):关闭VM
8月3日至4日:32:18.529:W / dalvikvm(3273):主题ID = 1:螺纹未捕获的异常(组= 0xb3adfba8)退出
8月3日至4日:32:18.549:E / AndroidRuntime(3273):致命异常:主要
8月3日至4日:32:18.549:E / AndroidRuntime(3273):工艺:com.joules.prdpcamera,PID:3273
8月3日至4日:32:18.549:E / AndroidRuntime(3273):显示java.lang.NullPointerException
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在android.media.ExifInterface.saveAttributes(ExifInterface.java:265)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在com.joules.prdpcamera.MainActivity.UpdateGeoTag(MainActivity.java:635)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在com.joules.prdpcamera.MainActivity $ 4.onPictureTaken(MainActivity.java:590)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在android.hardware.Camera $ EventHandler.handleMessage(Camera.java:917)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在android.os.Handler.dispatchMessage(Handler.java:102)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在android.os.Looper.loop(Looper.java:136)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在android.app.ActivityThread.main(ActivityThread.java:5017)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在java.lang.reflect.Method.invokeNative(本机方法)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在java.lang.reflect.Method.invoke(Method.java:515)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
8月3日至4日:32:18.549:E / AndroidRuntime(3273):在dalvik.system.NativeStart.main(本机方法)
8月3日至4日:32:28.839:I /流程(3273):发送信号。 PID:3273 SIG:9
8月3日至4日:33:05.939:D / dalvikvm(3327):GC_FOR_ALLOC释放35K,4%免费2852K / 2956K,暂停过48ms,总51ms
8月3日至4日:33:05.989:I / dalvikvm堆(3327):成长堆(frag的情况下),以6.385MB为3712464字节分配
8月3日至4日:33:06.029:D / dalvikvm(3327):GC_FOR_ALLOC释放2K,2%自由6474K / 6584K,暂停39MS,39MS总
8月3日至4日:33:06.839:D / gralloc_goldfish(3327):无仿真模拟GPU检测。
8月3日至4日:33:26.809:I /编舞(3327):跳过144帧!该应用程序可能会做它的主线程的工作太多了。
8月3日至4日:33:35.429:D / dalvikvm(3327):GC_FOR_ALLOC释放87K,3%的自由6765K / 6920K,暂停220ms内,总223ms
8月3日至4日:33:36.019:D / dalvikvm(3327):GC_FOR_ALLOC释放4K,3%的自由7961K / 8124K,暂停188ms,189ms总
8月3日至4日:33:37.609:D / dalvikvm(3327):GC_FOR_ALLOC释放1200K,15%的可用8045K / 9412K,暂停220ms内,总222ms
8月3日至4日:33:37.729:I / dalvikvm堆(3327):成长堆(frag的情况下),以10.173MB为2366704字节分配
8月3日至4日:33:38.119:D / dalvikvm(3327):GC_FOR_ALLOC释放< 1K,12%免费10356K / 11724K,暂停44ms,总45ms
8月3日至4日:33:38.719:D / AndroidRuntime(3327):关闭VM
8月3日至4日:33:38.719:W / dalvikvm(3327):主题ID = 1:螺纹未捕获的异常(组= 0xb3adfba8)退出
8月3日至4日:33:38.729:E / AndroidRuntime(3327):致命异常:主要
8月3日至4日:33:38.729:E / AndroidRuntime(3327):工艺:com.joules.prdpcamera,PID:3327
8月3日至4日:33:38.729:E / AndroidRuntime(3327):显示java.lang.NullPointerException
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在android.media.ExifInterface.saveAttributes(ExifInterface.java:265)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在com.joules.prdpcamera.MainActivity.UpdateGeoTag(MainActivity.java:635)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在com.joules.prdpcamera.MainActivity $ 4.onPictureTaken(MainActivity.java:590)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在android.hardware.Camera $ EventHandler.handleMessage(Camera.java:917)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在android.os.Handler.dispatchMessage(Handler.java:102)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在android.os.Looper.loop(Looper.java:136)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在android.app.ActivityThread.main(ActivityThread.java:5017)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在java.lang.reflect.Method.invokeNative(本机方法)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在java.lang.reflect.Method.invoke(Method.java:515)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
8月3日至4日:33:38.729:E / AndroidRuntime(3327):在dalvik.system.NativeStart.main(本机方法)
8月3日至4日:33:55.149:I /流程(3327):发送信号。 PID:3327 SIG:9
8月3日至4日:33:58.609:D / dalvikvm(3361):GC_FOR_ALLOC释放39K,4%免费2852K / 2960K,暂停58ms,总62ms
8月3日至4日:33:58.659:I / dalvikvm堆(3361):成长堆(frag的情况下),以6.385MB为3712464字节分配
8月3日至4日:33:58.719:D / dalvikvm(3361):GC_FOR_ALLOC释放2K,2%自由6475K / 6588K,暂停51ms,总51ms
8月3日至4日:33:59.899:D / gralloc_goldfish(3361):无仿真模拟GPU检测。
摄像头活动:
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
Toast.makeText(MainActivity.this,存储图像......请稍候......,Toast.LENGTH_LONG).show();
参数PARAMS = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_AUTO);
Camera.Parameters参数= cam.getParameters(); params.set(方向,肖像);
cam.setParameters(PARAMS); cam.takePicture(shutterCallback,空,jpegCallback); }
}); SurfaceView表面=(SurfaceView)findViewById(R.id.surfaceview);
SurfaceHolder支架= surface.getHolder();
holder.addCallback(本);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.setFixedSize(400,300); LM的LocationManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener的LL =新myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,LL); // vlatitude = df.format(CLAT);
// vlongitude = df.format(CLNG)
}
这是我启动时,我的应用程序启动在第一次调用:
公共类GPSInitialize延伸活动{
公共静态最后的字符串标记= NULL;
按钮btnCam;
TextView的marginError;
TextView的textLat;
TextView的textLong;
TextView的tvview;
TextView的txtIni; 公共无效onBack pressed()
{
super.onBack pressed();
完();
System.exit(0);
} 保护无效的onCreate(捆绑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 =((按钮)findViewById(R.id.btnCamera)); LM的LocationManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener的LL =新myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,LL);
} 公共布尔onCreateOptionsMenu(菜单paramMenu)
{
getMenuInflater()膨胀(2131165184,paramMenu)。
返回true;
} 保护无效onResume()
{
super.onResume();
} 公共无效startCamera(查看paramView)
{
startActivity(新意图(这一点,MainActivity.class));
} 私有类myLocationListener实现LocationListener的
{
私人myLocationListener()
{
} 公共无效onLocationChanged(位置paramLocation)
{
如果(paramLocation!= NULL)
{
双D1 = paramLocation.getLatitude();
双D2 = paramLocation.getLongitude();
浮F = paramLocation.getAccuracy();
GPSInitialize.this.textLat.setText(Double.toString(D1));
GPSInitialize.this.textLong.setText(Double.toString(D2));
GPSInitialize.this.txtIni.setText(GPS锁定);
GPSInitialize.this.tvview.setText(坐标找到);
GPSInitialize.this.marginError.setText(Float.toString(F));
PSInitialize.this.btnCam.setEnabled(真);
}
} 公共无效onProviderDisabled(字符串中的paramString)
{
Log.v(GPSInitialize.tag,您的GPS目前并未开启);
Toast.makeText(GPSInitialize.this,GPS找不到,请打开你的GPS,1).show();
意图localIntent =新意图(android.settings.LOCATION_SOURCE_SETTINGS);
GPSInitialize.this.startActivity(localIntent);
} 公共无效onProviderEnabled(字符串中的paramString)
{
Toast.makeText(GPSInitialize.this。GPS找到初始化GPS,1).show();
} 公共无效onStatusChanged(字符串中的paramString,INT paramInt,捆绑paramBundle)
{
}
}
}
我的主要活动的某些部分。
公共类MainActivity扩展活动实现SurfaceHolder.Callback {受保护的静态最后弦乐TAG = NULL;
私人布尔聚焦;私人相机凸轮;
SurfaceHolder持有人;
私人布尔isDoubleBack preSSD = FALSE;串vlatitude;
串vlongitude;
字符串的文件名;
字符串的timeStamp;
串持平;
串flong;
串latref;
串longref;
串outbar;
串outbar2;
串digitake;
串datePic;@覆盖
保护无效的onCreate(捆绑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 =新的LinearLayout(本);
l.setLayoutParams(新的LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
l.setOrientation(LinearLayout.VERTICAL);的ImageButton B =(的ImageButton)findViewById(R.id.Button1);
b.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
Toast.makeText(MainActivity.this,存储图像......请稍候......,Toast.LENGTH_LONG).show();
参数PARAMS = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_AUTO);
Camera.Parameters参数= cam.getParameters();
params.set(方向,肖像);
cam.setParameters(PARAMS);cam.takePicture(shutterCallback,空,jpegCallback);}
});
SurfaceView表面=(SurfaceView)findViewById(R.id.surfaceview);
SurfaceHolder支架= surface.getHolder();
holder.addCallback(本);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.setFixedSize(400,300);LM的LocationManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener的LL =新myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,LL);// vlatitude = df.format(CLAT);
// vlongitude = df.format(CLNG)
}私有静态最终诠释白色= 0xFFFFFFFF的;
私有静态最终诠释BLACK = 0xFF000000;私有类myLocationListener实现LocationListener的{@覆盖
公共无效onLocationChanged(地点){
如果(位置!= NULL){双CLAT = location.getLatitude();
双CLNG = location.getLongitude();DecimalFormat的DF =新的DecimalFormat(### ######);
vlatitude = df.format(CLAT);
vlongitude = df.format(CLNG)INT num1Lat =(INT)Math.floor(CLAT);
INT num2Lat =(INT)Math.floor((CLAT - num1Lat)* 60);
双num3Lat =(CLAT - ((双)num1Lat +((双)num2Lat / 60)))* 3600000;INT num1Lon =(INT)Math.floor(CLNG)
INT num2Lon =(INT)Math.floor((CLNG - num1Lon)* 60);
双num3Lon =(CLNG - ((双)num1Lon +((双)num2Lon / 60)))* 3600000;平= num1Lat +/ 1,+ num2Lat +/ 1,+ num3Lat +/ 1000;
flong = num1Lon +/ 1,+ num2Lon +/ 1,+ num3Lon +/ 1000;//编辑:vlatitude,vlongitude,平,flong,outbar,outbar2
如果(CLAT大于0){
latref =N;
}其他{
latref =S;
}
如果(CLNG大于0){
longref =E;
}其他{
longref =W;
}
//Toast.makeText(MainActivity.this,GPS是优秀,Toast.LENGTH_LONG).show();}}
@覆盖
公共无效onProviderDisabled(字符串提供商){
// TODO自动生成方法存根}@覆盖
公共无效onProviderEnabled(字符串提供商){ // --------------}@覆盖
公共无效onStatusChanged(字符串提供商,INT状态,
捆绑演员){
// TODO自动生成方法存根}}/ *
*启动自动对焦
* /
AutoFocusCallback myAutoFocusCallback =新AutoFocusCallback(){
@覆盖
公共无效onAutoFocus(布尔为arg0,ARG1相机){
// TODO自动生成方法存根
cam.autoFocus(本);
重点= TRUE;
//Toast.makeText(getApplicationContext(),聚焦,Toast.LENGTH_SHORT).show();
}
};
@覆盖
公共无效surfaceChanged(SurfaceHolder为arg0,ARG1 INT,INT ARG2,诠释ARG3){
// TODO自动生成方法存根
cam.stop preVIEW();
cam.start preVIEW();
}@覆盖
公共无效surfaceCreated(SurfaceHolder为arg0)
{
// TODO自动生成方法存根
尝试
{
Camera.Parameters参数= cam.getParameters();
如果(parameters.getSupportedFocusModes()。包括(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)){
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
cam.autoFocus(新AutoFocusCallback(){
公共无效onAutoFocus(布尔成功,相机摄像头){
//Log.d(TAG,自动对焦+(?成功成功:失败));
//cam.autoFocus(myAutoFocusCallback);
}
});cam.set previewCallback(新previewCallback()
{
@覆盖
在previewFrame公共无效(字节[]数据,相机摄像头)
{
INT质量= 100;
大小previewSize = camera.getParameters()获得previewSize()。
YuvImage形象=新YuvImage(数据,ImageFormat.NV21,previewSize.width,previewSize.height,NULL);
ByteArrayOutputStream的OutputStream =新ByteArrayOutputStream();
image.com pressToJpeg(新的Rect(0,0,previewSize.width,previewSize.height),质量的OutputStream);}});定时器恬=新的Timer();
tim.schedule(新的TimerTask(){@覆盖
公共无效的run(){
// TODO自动生成方法存根
cam.start preVIEW();}
},3000);
}
cam.set previewDisplay(为arg0);
cam.setDisplayOrientation(90);
cam.start preVIEW();
//如果需要TODO绘制在preVIEW。
}赶上(IOException异常E)
{
//Log.d(TAG,IO异常,E);
}}@覆盖
公共无效surfaceDestroyed(SurfaceHolder为arg0){
// TODO自动生成方法存根
参数PARAMS = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
holder.removeCallback(本);cam.stop preVIEW();
cam.release();
重点= FALSE;
凸轮= NULL;}
由于 LogCat中
说: NullPointerException异常
的文件 ExifInterface.java
的行 265
。
看 MainActivity.java
行 590
和 635
或发表您的 MainActivity
code。
My custom camera apps crash if called by another application.
Like for example, my camera was called by my tracks. If you press the camera icon of my tracks, it will popup and let the user select what camera want to use. I have tried to use my camera but it crashes. But if I click the camera from the application menu, my camera works fine.
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>
My onCreate()
method :
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);
}
LogCat:
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.
Camera activity:
@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);
}
This is my launcher which is called first when my apps start:
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)
{
}
}
}
Some part of my main activity
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 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);
}
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;
}
As LogCat
said: NullPointerException
at file ExifInterface.java
in line 265
.
Look at MainActivity.java
lines 590
and 635
or post your MainActivity
code.
这篇关于相机崩溃,如果所谓的其他应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!