- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在处理 Android 开发人员网站的示例部分中提供的 Android 项目(特别是 MediaRecorder sample 。
我下载了该文件并将其导入到 Eclipse 中。
导入过程似乎正常进行,我在 Eclipse 模拟器上启动了该应用程序。
我收到此消息“不幸的是,MediaRecorder 已停止”。
这些是目录中的错误:
01-01 07:22:33.336: I/Process(1423): Sending signal. PID: 1423 SIG: 9
01-02 04:34:23.366: D/AndroidRuntime(1558): Shutting down VM
01-02 04:34:23.376: W/dalvikvm(1558): threadid=1: thread exiting with uncaught exception (group=0xb1aadb90)
01-02 04:34:23.506: E/AndroidRuntime(1558): FATAL EXCEPTION: main
01-02 04:34:23.506: E/AndroidRuntime(1558): Process: com.example.android.mediarecorder, PID: 1558
01-02 04:34:23.506: E/AndroidRuntime(1558): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.mediarecorder/com.example.android.mediarecorder.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.android.mediarecorder.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.mediarecorder-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.mediarecorder-1, /system/lib]]
01-02 04:34:23.506: E/AndroidRuntime(1558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2102)
01-02 04:34:23.506: E/AndroidRuntime(1558): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
01-02 04:34:23.506: E/AndroidRuntime(1558): at android.app.ActivityThread.access$700(ActivityThread.java:135)
01-02 04:34:23.506: E/AndroidRuntime(1558): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
01-02 04:34:23.506: E/AndroidRuntime(1558): at android.os.Handler.dispatchMessage(Handler.java:102)
01-02 04:34:23.506: E/AndroidRuntime(1558): at android.os.Looper.loop(Looper.java:137)
01-02 04:34:23.506: E/AndroidRuntime(1558): at android.app.ActivityThread.main(ActivityThread.java:4998)
01-02 04:34:23.506: E/AndroidRuntime(1558): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 04:34:23.506: E/AndroidRuntime(1558): at java.lang.reflect.Method.invoke(Method.java:515)
01-02 04:34:23.506: E/AndroidRuntime(1558): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
01-02 04:34:23.506: E/AndroidRuntime(1558): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
01-02 04:34:23.506: E/AndroidRuntime(1558): at dalvik.system.NativeStart.main(Native Method)
01-02 04:34:23.506: E/AndroidRuntime(1558): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.mediarecorder.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.mediarecorder-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.mediarecorder-1, /system/lib]]
01-02 04:34:23.506: E/AndroidRuntime(1558): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-02 04:34:23.506: E/AndroidRuntime(1558): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
01-02 04:34:23.506: E/AndroidRuntime(1558): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
01-02 04:34:23.506: E/AndroidRuntime(1558): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
01-02 04:34:23.506: E/AndroidRuntime(1558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
01-02 04:34:23.506: E/AndroidRuntime(1558): ... 11 more
01-02 04:34:32.246: I/Process(1558): Sending signal. PID: 1558 SIG: 9
我的 list 是:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.mediarecorder"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<!-- This app records A/V content from camera and stores it to disk -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- Since this sample records video from camera preview, locking the orientation to
landscape. Landscape mode offers us more preview space with standard video aspect
ratios (width > height) -->
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我在之前的文章中读到,问题可能取决于 Java 构建路径的正确配置,但由于我是 android 和编程的新手,我无法弄清楚如何修改 java 构建以使应用程序正常工作。
我还附上了 Java 构建路径的图像
java build path order and export
谁能给我一些提示吗?提前致谢
我在下面添加 MainActivity 代码
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.mediarecorder;
import android.annotation.TargetApi;
import android.app.Activity;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.TextureView;
import android.view.View;
import android.widget.Button;
import com.example.android.common.media.CameraHelper;
import java.io.IOException;
import java.util.List;
/**
* This activity uses the camera/camcorder as the A/V source for the {@link android.media.MediaRecorder} API.
* A {@link android.view.TextureView} is used as the camera preview which limits the code to API 14+. This
* can be easily replaced with a {@link android.view.SurfaceView} to run on older devices.
*/
public class MainActivity extends Activity {
private Camera mCamera;
private TextureView mPreview;
private MediaRecorder mMediaRecorder;
private boolean isRecording = false;
private static final String TAG = "Recorder";
private Button captureButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_main);
mPreview = (TextureView) findViewById(R.id.surface_view);
captureButton = (Button) findViewById(R.id.button_capture);
}
/**
* The capture button controls all user interaction. When recording, the button click
* stops recording, releases {@link android.media.MediaRecorder} and {@link android.hardware.Camera}. When not recording,
* it prepares the {@link android.media.MediaRecorder} and starts recording.
*
* @param view the view generating the event.
*/
public void onCaptureClick(View view) {
if (isRecording) {
// BEGIN_INCLUDE(stop_release_media_recorder)
// stop recording and release camera
mMediaRecorder.stop(); // stop the recording
releaseMediaRecorder(); // release the MediaRecorder object
mCamera.lock(); // take camera access back from MediaRecorder
// inform the user that recording has stopped
setCaptureButtonText("Capture");
isRecording = false;
releaseCamera();
// END_INCLUDE(stop_release_media_recorder)
} else {
// BEGIN_INCLUDE(prepare_start_media_recorder)
new MediaPrepareTask().execute(null, null, null);
// END_INCLUDE(prepare_start_media_recorder)
}
}
private void setCaptureButtonText(String title) {
captureButton.setText(title);
}
@Override
protected void onPause() {
super.onPause();
// if we are using MediaRecorder, release it first
releaseMediaRecorder();
// release the camera immediately on pause event
releaseCamera();
}
private void releaseMediaRecorder(){
if (mMediaRecorder != null) {
// clear recorder configuration
mMediaRecorder.reset();
// release the recorder object
mMediaRecorder.release();
mMediaRecorder = null;
// Lock camera for later use i.e taking it back from MediaRecorder.
// MediaRecorder doesn't need it anymore and we will release it if the activity pauses.
mCamera.lock();
}
}
private void releaseCamera(){
if (mCamera != null){
// release the camera for other applications
mCamera.release();
mCamera = null;
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean prepareVideoRecorder(){
// BEGIN_INCLUDE (configure_preview)
mCamera = CameraHelper.getDefaultCameraInstance();
// We need to make sure that our preview and recording video size are supported by the
// camera. Query camera to find all the sizes and choose the optimal size given the
// dimensions of our preview surface.
Camera.Parameters parameters = mCamera.getParameters();
List<Camera.Size> mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
Camera.Size optimalSize = CameraHelper.getOptimalPreviewSize(mSupportedPreviewSizes, mPreview.getWidth(), mPreview.getHeight());
// Use the same size for recording profile.
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
profile.videoFrameWidth = optimalSize.width;
profile.videoFrameHeight = optimalSize.height;
// likewise for the camera object itself.
parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
mCamera.setParameters(parameters);
try {
// Requires API level 11+, For backward compatibility use {@link setPreviewDisplay}
// with {@link SurfaceView}
mCamera.setPreviewTexture(mPreview.getSurfaceTexture());
} catch (IOException e) {
Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage());
return false;
}
// END_INCLUDE (configure_preview)
// BEGIN_INCLUDE (configure_media_recorder)
mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT );
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
mMediaRecorder.setProfile(profile);
// Step 4: Set output file
mMediaRecorder.setOutputFile(CameraHelper.getOutputMediaFile(
CameraHelper.MEDIA_TYPE_VIDEO).toString());
// END_INCLUDE (configure_media_recorder)
// Step 5: Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
return true;
}
/**
* Asynchronous task for preparing the {@link android.media.MediaRecorder} since it's a long blocking
* operation.
*/
class MediaPrepareTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... voids) {
// initialize video camera
if (prepareVideoRecorder()) {
// Camera is available and unlocked, MediaRecorder is prepared,
// now you can start recording
mMediaRecorder.start();
isRecording = true;
} else {
// prepare didn't work, release the camera
releaseMediaRecorder();
return false;
}
return true;
}
@Override
protected void onPostExecute(Boolean result) {
if (!result) {
MainActivity.this.finish();
}
// inform the user that recording has started
setCaptureButtonText("Stop");
}
}
}
最佳答案
尝试一下,将您的 Activity
名称更改为完整的类名称:
<activity
android:name="com.example.android.mediaRecorder.MainActivity"
关于java.lang.RuntimeException : Unable to instantiate activity ComponentInfo java build path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20885968/
我刚遇到 MSVC(版本 12 更新 5)的问题: 如果模板函数具有通过 SFINAE 禁用的重载,则显式实例化模板函数会失败。但是,调用该函数(从而隐式实例化它)是有效的。 示例代码: #inclu
我正在阅读一本关于 DI 的书,该书总是谈论 DI 框架“实例化对象图”。为什么这样说而不是“实例化对象”? 最佳答案 对象图由保存彼此引用的对象组成。在这种情况下,图的另一个名称是网络。 如果 IO
一个类Customers实例化许多其他类(例如CustomersFromMysql、CustomersFromPostgeSQL),所有查询数据库都返回客户名称。现在,这些客户名称返回为例如 name
当我尝试调用 listenEventReducer 时,出现了这个奇怪的错误。该方法知道类型,但仍然不确定我哪里出错了。 import 'package:test/test.dart'; enum O
我正在尝试使用 org.hibernate.Interceptor.instantiate() 来拦截实例化(显然)并使用默认构造函数之外的构造函数手动实例化特定对象。如果要阅读此方法的 JavaDo
public class TestingClass { public static void main(String[] args) { int numberRooms = 6
为什么 C++ 以这样的方式创建,如果您有一个类 A 并声明一个类型 A 的数组,那么整个数组将填充使用该类的默认构造函数实例化的对象? 最佳答案 因为当您创建一个给定大小的数组时,数组的每个元素都必
考虑下面的例子 template struct S { A a; void foo() {} }; template void bar() { S *p = 0; } templat
Note that code is instantiated only for member functions that are called. For class templates, membe
当我尝试运行这段代码时: import java.io.*; import java.util.*; public class TwoColor { public static void ma
每当我尝试在 Unity 3D 中实例化粒子系统时,命令都会定位粒子但不会播放/运行动画。 这是我的代码 GameObject impactGO = Instantiate(impactEffect,
我使用以下代码在 verilog 中实例化二维内存 reg [15:0] data_pattern_even [3:0] = {16'hFFFF,16'hFFFF,16'hFFFF,16'hFFFF
假设我获得了我作为 String 创建的类的名称。 .如何使用该字符串中包含的名称实例化类?我知道它将派生自某个父类,但实际类会有所不同。 最佳答案 var instance : MyClass =
python 的 attrs 包提供了一种在实例化时验证传递的变量的简单方法 (example taken from attrs page): >>> @attr.s ... class C(obje
我收到 java 空指针异常。我无法解决它。我已在 testbase 类中初始化驱动程序,并希望在我的 Testing_TVO 类中使用相同的驱动程序 这是我的测试基类 public class te
我对 Java 编程还比较陌生,可能错过了一些明显的东西,所以请耐心等待。 我正在创建一个程序,该程序使用 Swing API 和 JDesktopPane 来创建 GUI。主屏幕上有一个按钮,上面写
python 的 attrs 包提供了一种在实例化时验证传递的变量的简单方法 (example taken from attrs page): >>> @attr.s ... class C(obje
C++ 模板中的“延迟实例化”是什么意思? 最佳答案 延迟实例化是指直到第一次使用对应的实体时才实例化模板。例如,您有一个模板化函数: template void YourFunction() {
当我阅读 spring 教程时,我发现了这样的内容: LocalChangeInterceptor localChangeInterceptor; localChangeInterceptor = n
我正在实现 unforgettable factory .一切正常,但有一件事:类(class)有时没有注册。 我认为关键部分是 Registrar::registered成员。如果使用它,“真正有趣
我是一名优秀的程序员,十分优秀!