我对Android编程很新,因此我需要一些帮助。当我运行程序时,它只能显示第一页(键入页面的IP地址),当我点击连接按钮时,它无法运行下一个活动
我添加了3个相关的Manifest用于相机许可&硬件使用。
我希望用户键入IP地址(将对匹配器进行检查),如果匹配,则会导致下一个活动,即摄像机。我试图在2个不同的项目中单独运行IP地址匹配器和摄像头,它们工作得很好。
在旁注中,有时我一直得到这个NullPointerException,我认为我能够使用我的OnclickListener的if语句和MainActivity类中的addView修复
这是我的MainActivity Class
public class MainActivity extends AppCompatActivity
{
private EditText ipAddr;
private String ipAddress;
private static final String IPADDRESS_PATTERN =
"^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
private Camera mCamera = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button connectButton = (Button) findViewById(R.id.connectButton);
ipAddr = (EditText)findViewById(R.id.ipAddr);
if (connectButton != null) {
connectButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
ipAddress = ipAddr.getText().toString();
if(checkIpAddressFormat(ipAddress))
{
Intent changePageIntent = new Intent(MainActivity.this,CameraView.class);
startActivity(changePageIntent);
Log.d("ERROR","Able to go next class");
}
else
{
Toast.makeText(MainActivity.this, "This is an invalid IP", Toast.LENGTH_SHORT).show();
}
}
});
}
try
{
mCamera = Camera.open();
Log.d("ERROR","get camera");
}
catch(Exception e)
{
Log.d("ERROR","Failed to get camera" + e.getMessage());
}
if(mCamera !=null)
{
CameraView mCameraView = new CameraView(MainActivity.this, mCamera);
FrameLayout camera_view = (FrameLayout)findViewById(R.id.camera_view);
if (camera_view != null) {
camera_view.addView(mCameraView);
}
Log.d("ERROR","ABLE TO PREVIEW camera" );
}
}
private boolean checkIpAddressFormat(String qducIpAddress) // using a method called checkIpAddressFormat and using string qducIpAddress
{
boolean checkIpAddressFormatResult = false;
Pattern pattern = Pattern.compile(IPADDRESS_PATTERN);
Matcher matcher = pattern.matcher(qducIpAddress);
checkIpAddressFormatResult = matcher.matches();
return checkIpAddressFormatResult;
}
}
CameraView类
public class CameraView extends SurfaceView implements SurfaceHolder.Callback
{
private SurfaceHolder mHolder;
private Camera mCamera;
public CameraView(Context context, Camera camera)
{
super(context);
mCamera = camera;
mCamera.setDisplayOrientation(90);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_HARDWARE);
}
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder)
{
try
{
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
Log.d("ERROR", "GOOD");
}
catch (IOException e)
{
Log.d("ERROR","Camera error on surfaceCreated"+ e.getMessage());
}
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int width, int height)
{
if (mHolder.getSurface() == null)
return;
mCamera.stopPreview();
try
{
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
}
catch (IOException e)
{
Log.d("ERROR","Camera error on SurfaceChanged" + e.getMessage());
}
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder)
{
mCamera.stopPreview();
mCamera.release();
}
}
以下是我的Logcat
01-01 18:35:09.773 15622-15622/? D/AndroidRuntime: >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-01 18:35:09.773 15622-15622/? D/AndroidRuntime: CheckJNI is ON
01-01 18:35:09.988 15622-15622/? I/ethernet: Loading ethernet jni class
01-01 18:35:10.047 15622-15622/? D/AndroidRuntime: Calling main entry com.android.commands.pm.Pm
--------- beginning of /dev/log/system
01-01 18:35:10.070 1415-1433/system_process W/ActivityManager: No content provider found for permission revoke: file:///data/local/tmp/com.video.newfirstworkingapp
01-01 18:35:10.808 1415-1433/system_process W/ActivityManager: No content provider found for permission revoke: file:///data/local/tmp/com.video.newfirstworkingapp
01-01 18:35:10.898 1415-1417/system_process D/dalvikvm: GC_CONCURRENT freed 383K, 13% free 10545K/12103K, paused 2ms+3ms
01-01 18:35:10.941 1415-1433/system_process D/dalvikvm: GC_FOR_ALLOC freed 99K, 14% free 10507K/12103K, paused 42ms
01-01 18:35:10.996 1415-1433/system_process D/dalvikvm: GC_FOR_ALLOC freed 86K, 14% free 10514K/12103K, paused 37ms
01-01 18:35:11.093 1415-1433/system_process D/dalvikvm: GC_FOR_ALLOC freed 211K, 12% free 10754K/12103K, paused 39ms
01-01 18:35:11.386 1415-1417/system_process D/dalvikvm: GC_CONCURRENT freed 637K, 11% free 10872K/12103K, paused 3ms+3ms
01-01 18:35:11.492 1415-1417/system_process D/dalvikvm: GC_CONCURRENT freed 698K, 11% free 10870K/12103K, paused 3ms+3ms
01-01 18:35:11.601 1415-1417/system_process D/dalvikvm: GC_CONCURRENT freed 701K, 11% free 10874K/12103K, paused 3ms+3ms
01-01 18:35:11.707 1415-1417/system_process D/dalvikvm: GC_CONCURRENT freed 700K, 11% free 10879K/12103K, paused 3ms+4ms
01-01 18:35:11.832 1415-1417/system_process D/dalvikvm: GC_CONCURRENT freed 729K, 11% free 10889K/12103K, paused 3ms+4ms
01-01 18:35:11.886 1415-1433/system_process I/PackageManager: Removing non-system package:com.video.newfirstworkingapp
01-01 18:35:11.890 1415-1430/system_process I/ActivityManager: Force stopping package com.video.newfirstworkingapp uid=10067
01-01 18:35:11.984 1415-1433/system_process I/PackageManager: Package com.video.newfirstworkingapp codePath changed from /data/app/com.video.newfirstworkingapp-1.apk to /data/app/com.video.newfirstworkingapp-2.apk; Retaining data and using new
01-01 18:35:11.992 1415-1433/system_process I/PackageManager: Running dexopt on: com.video.newfirstworkingapp
01-01 18:35:14.125 15633-15633/? D/dalvikvm: DexOpt: couldn't find field Landroid/app/Notification;.actions
01-01 18:35:14.992 15633-15633/? D/dalvikvm: DexOpt: load 245ms, verify+opt 1076ms
01-01 18:35:15.472 1415-1430/system_process I/ActivityManager: Force stopping package com.video.newfirstworkingapp uid=10067
01-01 18:35:15.472 1415-1433/system_process W/PackageManager: Code path for pkg : com.video.newfirstworkingapp changing from /data/app/com.video.newfirstworkingapp-1.apk to /data/app/com.video.newfirstworkingapp-2.apk
01-01 18:35:15.472 1415-1433/system_process W/PackageManager: Resource path for pkg : com.video.newfirstworkingapp changing from /data/app/com.video.newfirstworkingapp-1.apk to /data/app/com.video.newfirstworkingapp-2.apk
01-01 18:35:15.543 1415-1417/system_process D/dalvikvm: GC_CONCURRENT freed 652K, 10% free 10927K/12103K, paused 3ms+7ms
01-01 18:35:15.644 1415-1433/system_process D/PackageManager: New package installed in /data/app/com.video.newfirstworkingapp-2.apk
01-01 18:35:15.742 1415-1433/system_process I/ActivityManager: Force stopping package com.video.newfirstworkingapp uid=10067
01-01 18:35:15.785 1583-1583/com.android.launcher D/dalvikvm: GC_EXPLICIT freed 202K, 8% free 9639K/10439K, paused 3ms+5ms
01-01 18:35:15.914 1624-1624/android.process.acore D/dalvikvm: GC_EXPLICIT freed 250K, 6% free 8022K/8455K, paused 2ms+4ms
01-01 18:35:15.972 1415-1429/system_process D/dalvikvm: GC_EXPLICIT freed 931K, 15% free 10320K/12103K, paused 4ms+5ms
01-01 18:35:15.976 1415-1429/system_process D/PackageManager: generateServicesMap(android.accounts.AccountAuthenticator): 1 services unchanged
01-01 18:35:15.984 1415-1429/system_process D/PackageManager: generateServicesMap(android.content.SyncAdapter): 4 services unchanged
01-01 18:35:15.984 1415-1429/system_process D/BackupManagerService: Received broadcast Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:com.video.newfirstworkingapp flg=0x10000010 (has extras) }
01-01 18:35:16.019 1415-1429/system_process D/PackageManager: generateServicesMap(android.accounts.AccountAuthenticator): 1 services unchanged
01-01 18:35:16.019 1415-1429/system_process D/PackageManager: generateServicesMap(android.content.SyncAdapter): 4 services unchanged
01-01 18:35:16.043 1415-1429/system_process W/ResourceType: Failure getting entry for 0x7f060000 (t=5 e=0) in package 0 (error -75)
01-01 18:35:16.062 1415-1429/system_process D/BackupManagerService: Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.video.newfirstworkingapp flg=0x10000010 (has extras) }
01-01 18:35:16.062 1415-1429/system_process V/BackupManagerService: updatePackageParticipantsLocked: com.video.newfirstworkingapp
01-01 18:35:16.293 1415-1429/system_process D/BackupManagerService: Received broadcast Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:com.video.newfirstworkingapp flg=0x10000010 (has extras) }
01-01 18:35:16.293 1415-1429/system_process V/BackupManagerService: updatePackageParticipantsLocked: com.video.newfirstworkingapp
01-01 18:35:16.320 2403-2404/com.android.gallery3d D/dalvikvm: GC_CONCURRENT freed 438K, 8% free 7802K/8455K, paused 1ms+2ms
01-01 18:35:16.367 1415-1417/system_process D/dalvikvm: GC_CONCURRENT freed 575K, 14% free 10417K/12103K, paused 3ms+5ms
01-01 18:35:16.558 1415-1433/system_process D/dalvikvm: GC_EXPLICIT freed 324K, 15% free 10325K/12103K, paused 7ms+6ms
01-01 18:35:16.617 15622-15622/? D/AndroidRuntime: Shutting down VM
01-01 18:35:16.629 15622-15626/? D/dalvikvm: GC_CONCURRENT freed 101K, 83% free 458K/2560K, paused 0ms+0ms
01-01 18:35:16.629 15622-15628/? D/jdwp: Got wake-up signal, bailing out of select
01-01 18:35:16.629 15622-15628/? D/dalvikvm: Debugger has detached; object registry had 1 entries
01-01 18:35:16.636 15622-15638/? I/AndroidRuntime: NOTE: attach of thread 'Binder Thread #3' failed
01-01 18:35:17.054 15645-15645/? D/AndroidRuntime: >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-01 18:35:17.054 15645-15645/? D/AndroidRuntime: CheckJNI is ON
01-01 18:35:17.297 15645-15645/? I/ethernet: Loading ethernet jni class
01-01 18:35:17.367 15645-15645/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
01-01 18:35:17.375 1415-1609/system_process I/ActivityManager: START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.video.newfirstworkingapp/.MainActivity} from pid 15645
01-01 18:35:17.445 15645-15645/? D/AndroidRuntime: Shutting down VM
01-01 18:35:17.453 15645-15649/? D/dalvikvm: GC_CONCURRENT freed 102K, 81% free 487K/2560K, paused 1ms+0ms
01-01 18:35:17.453 15645-15651/? D/jdwp: Got wake-up signal, bailing out of select
01-01 18:35:17.453 15645-15651/? D/dalvikvm: Debugger has detached; object registry had 1 entries
01-01 18:35:17.461 15645-15655/? I/AndroidRuntime: NOTE: attach of thread 'Binder Thread #3' failed
01-01 18:35:17.476 15656-15656/? D/dalvikvm: Not late-enabling CheckJNI (already on)
01-01 18:35:17.480 1415-1415/system_process I/ActivityManager: Start proc com.video.newfirstworkingapp for activity com.video.newfirstworkingapp/.MainActivity: pid=15656 uid=10067 gids={1006}
01-01 18:35:17.504 15656-15662/? D/dalvikvm: Debugger has detached; object registry had 1 entries
01-01 18:35:17.582 15656-15656/? W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
01-01 18:35:17.582 15656-15656/? I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
01-01 18:35:17.582 15656-15656/? W/dalvikvm: VFY: unable to resolve interface method 19589: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
01-01 18:35:17.582 15656-15656/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-01 18:35:17.586 15656-15656/? I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
01-01 18:35:17.586 15656-15656/? W/dalvikvm: VFY: unable to resolve interface method 19593: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
01-01 18:35:17.586 15656-15656/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-01 18:35:17.605 1583-1583/com.android.launcher D/OpenGLRenderer: Flushing caches (mode 1)
01-01 18:35:17.644 15656-15656/? I/dalvikvm: Could not find method android.view.ViewGroup.onWindowSystemUiVisibilityChanged, referenced from method android.support.v7.widget.ActionBarOverlayLayout.onWindowSystemUiVisibilityChanged
01-01 18:35:17.644 15656-15656/? W/dalvikvm: VFY: unable to resolve virtual method 19488: Landroid/view/ViewGroup;.onWindowSystemUiVisibilityChanged (I)V
01-01 18:35:17.644 15656-15656/? D/dalvikvm: VFY: replacing opcode 0x6f at 0x0008
01-01 18:35:17.707 15656-15656/? I/dalvikvm: Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
01-01 18:35:17.707 15656-15656/? W/dalvikvm: VFY: unable to resolve virtual method 19482: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
01-01 18:35:17.707 15656-15656/? D/dalvikvm: VFY: replacing opcode 0x6f at 0x0007
01-01 18:35:17.711 15656-15656/? I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
01-01 18:35:17.711 15656-15656/? W/dalvikvm: VFY: unable to resolve virtual method 440: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-01 18:35:17.711 15656-15656/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-01 18:35:17.715 15656-15656/? I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
01-01 18:35:17.715 15656-15656/? W/dalvikvm: VFY: unable to resolve virtual method 462: Landroid/content/res/TypedArray;.getType (I)I
01-01 18:35:17.715 15656-15656/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-01 18:35:17.750 1583-1583/com.android.launcher D/OpenGLRenderer: Flushing caches (mode 0)
01-01 18:35:17.785 15656-15656/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
01-01 18:35:17.785 15656-15656/? W/dalvikvm: VFY: unable to resolve virtual method 403: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
01-01 18:35:17.785 15656-15656/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-01 18:35:17.785 15656-15656/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
01-01 18:35:17.785 15656-15656/? W/dalvikvm: VFY: unable to resolve virtual method 405: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
01-01 18:35:17.785 15656-15656/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-01 18:35:17.808 15656-15657/? D/dalvikvm: GC_CONCURRENT freed 238K, 5% free 7910K/8263K, paused 3ms+3ms
01-01 18:35:17.824 15656-15656/? I/dalvikvm: Could not find method android.view.ViewGroup$MarginLayoutParams.resolveLayoutDirection, referenced from method android.support.constraint.ConstraintLayout$LayoutParams.resolveLayoutDirection
01-01 18:35:17.824 15656-15656/? W/dalvikvm: VFY: unable to resolve virtual method 19424: Landroid/view/ViewGroup$MarginLayoutParams;.resolveLayoutDirection (I)V
01-01 18:35:17.828 15656-15656/? D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002
01-01 18:35:17.836 1233-1233/? I/CameraService: Opening camera 0
01-01 18:35:17.836 1233-1233/? I/CameraHardwareSec: int android::HAL_camera_device_open(const hw_module_t*, const char*, hw_device_t**): open camera 0
01-01 18:35:17.836 1233-1233/? I/SecCamera: Name of input channel[0] is ov3640
01-01 18:35:17.855 1233-1233/? I/SecCamera: Name of input channel[0] is ov3640
01-01 18:35:17.855 1233-1233/? I/SecCamera: initCamera : initialized
01-01 18:35:17.855 1233-1233/? I/SecCamera: Name of input channel[0] is ov3640
01-01 18:35:17.855 1233-1233/? D/CameraHardwareSec: getPreviewMaxSize return 640,480
01-01 18:35:17.855 1233-1233/? D/CameraHardwareSec: getSnapshotMaxSize return 640,480
01-01 18:35:17.855 1233-1233/? I/CameraHardwareSec: int android::HAL_camera_device_open(const hw_module_t*, const char*, hw_device_t**): opened camera 0 (0x767998)
01-01 18:35:17.859 1233-15672/? I/CameraHardwareSec: int android::CameraHardwareSec::previewThreadWrapper(): starting
01-01 18:35:17.859 1233-15672/? I/CameraHardwareSec: int android::CameraHardwareSec::previewThreadWrapper(): calling mSecCamera->stopPreview() and waiting
01-01 18:35:17.859 1233-15672/? W/SecCamera: int android::SecCamera::stopPreview(): doing nothing because m_flag_camera_start is zero
01-01 18:35:17.863 1233-1233/? I/AwesomePlayer: setDataSource_l('/system/media/audio/ui/camera_click.ogg')
01-01 18:35:17.875 1233-1233/? I/AwesomePlayer: setDataSource_l('/system/media/audio/ui/VideoRecord.ogg')
01-01 18:35:17.894 15656-15656/? D/ERROR: get camera
01-01 18:35:17.894 15656-15656/? D/ERROR: ABLE TO PREVIEW camera
01-01 18:35:17.941 15656-15656/? D/libEGL: loaded /system/lib/egl/libGLES_android.so
01-01 18:35:17.945 15656-15656/? D/libEGL: loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
01-01 18:35:17.953 15656-15656/? D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
01-01 18:35:17.957 15656-15656/? D/libEGL: loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
01-01 18:35:18.039 15656-15656/? D/OpenGLRenderer: Enabling debug mode 0
01-01 18:35:18.140 1415-1445/system_process I/ActivityManager: Displayed com.video.newfirstworkingapp/.MainActivity: +704ms
单击“连接”按钮后的Logcat
1-01 18:35:30.965 1487-1489/com.android.systemui D/dalvikvm: GC_CONCURRENT freed 202K, 7% free 8406K/9031K, paused 2ms+2ms
01-01 18:35:30.988 1487-1487/com.android.systemui D/dalvikvm: GC_FOR_ALLOC freed 207K, 10% free 8198K/9031K, paused 23ms
01-01 18:35:31.074 1487-1487/com.android.systemui D/dalvikvm: GC_FOR_ALLOC freed 311K, 10% free 8198K/9031K, paused 19ms
01-01 18:35:31.566 2417-2419/com.android.vending D/dalvikvm: GC_CONCURRENT freed 370K, 8% free 8093K/8775K, paused 2ms+2ms
01-01 18:35:31.652 2417-2417/com.android.vending D/Finsky: [1] 5.onFinished: Installation state replication succeeded.
01-01 18:35:38.265 1415-1573/system_process I/ActivityManager: START {cmp=com.video.newfirstworkingapp/.CameraView} from pid 15656
01-01 18:35:38.273 1233-1407/? D/AudioHardware: AudioHardware pcm playback is exiting standby.
01-01 18:35:38.273 1233-1407/? D/AudioHardware: openPcmOut_l() mPcmOpenCnt: 0
01-01 18:35:38.304 15656-15656/com.video.newfirstworkingapp D/ERROR: Able to go next Class
01-01 18:35:38.316 15656-15656/com.video.newfirstworkingapp D/dalvikvm: newInstance failed: no <init>()
01-01 18:35:38.316 15656-15656/com.video.newfirstworkingapp D/AndroidRuntime: Shutting down VM
01-01 18:35:38.316 15656-15656/com.video.newfirstworkingapp W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40a451f8)
01-01 18:35:38.320 15656-15656/com.video.newfirstworkingapp E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.video.newfirstworkingapp/com.video.newfirstworkingapp.CameraView}: java.lang.InstantiationException: can't instantiate class com.video.newfirstworkingapp.CameraView; no empty constructor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class com.video.newfirstworkingapp.CameraView; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
01-01 18:35:38.340 1415-1426/system_process W/ActivityManager: Force finishing activity com.video.newfirstworkingapp/.CameraView
01-01 18:35:38.340 1415-1426/system_process W/ActivityManager: Force finishing activity com.video.newfirstworkingapp/.MainActivity
01-01 18:35:38.386 1415-1417/system_process D/dalvikvm: GC_CONCURRENT freed 538K, 14% free 10459K/12103K, paused 3ms+4ms
01-01 18:35:38.840 1415-1429/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{414ef840 com.video.newfirstworkingapp/.CameraView}
01-01 18:35:41.285 1233-1407/? D/AudioHardware: AudioHardware pcm playback is going to standby.
01-01 18:35:41.285 1233-1407/? D/AudioHardware: closePcmOut_l() mPcmOpenCnt: 1
01-01 18:35:49.031 1415-1429/system_process W/ActivityManager: Activity destroy timeout for ActivityRecord{413ef6b8 com.video.newfirstworkingapp/.MainActivity}
01-01 18:35:49.031 1415-1429/system_process W/ActivityManager: Activity destroy timeout for ActivityRecord{414ef840 com.video.newfirstworkingapp/.CameraView}
答案 0 :(得分:0)
您正在尝试启动活动,但CameraView
不是活动,此处:
Intent changePageIntent = new Intent(MainActivity.this,CameraView.class);
startActivity(changePageIntent);
如果您希望活动持有SurfaceView
,则应创建一个新的扩展活动类,并在那里实施SurfaceView
。