我是 Android 编程新手,我想编写一个简单的应用程序进行练习。我已经在网上搜索了几个小时,但没有找到任何问题的答案。
我想在正在运行的相机应用程序上方放置一个 2. 层。
如果我拍照,它不应该显示图片中的 2. 层,就像从来没有 2. 层一样。
那是当前的代码,只有工作相机。图片显示了它的外观: http ://www.bild.me/bild.php?file=91520242013-08-03_19-25-33.png
public class MainActivity extends Activity {
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startCamera();
}
public void startCamera() {
iv = (ImageView)findViewById(R.id.imageView);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 0) {
Bitmap theImage = (Bitmap) data.getExtras().get("date");
iv.setImageBitmap(theImage);
startCamera();
}
}
}
编辑
答案中的 Logcat 异常:
08-04 12:33:44.403: E/AndroidRuntime(840): FATAL EXCEPTION: main
08-04 12:33:44.403: E/AndroidRuntime(840): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.camerafront/com.example.camerafront.AndroidCamera}: android.view.InflateException: Binary XML file line #1: Error inflating class menu
08-04 12:33:44.403: E/AndroidRuntime(840): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.os.Looper.loop(Looper.java:137)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-04 12:33:44.403: E/AndroidRuntime(840): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 12:33:44.403: E/AndroidRuntime(840): at java.lang.reflect.Method.invoke(Method.java:525)
08-04 12:33:44.403: E/AndroidRuntime(840): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-04 12:33:44.403: E/AndroidRuntime(840): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-04 12:33:44.403: E/AndroidRuntime(840): at dalvik.system.NativeStart.main(Native Method)
08-04 12:33:44.403: E/AndroidRuntime(840): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class menu
08-04 12:33:44.403: E/AndroidRuntime(840): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-04 12:33:44.403: E/AndroidRuntime(840): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.app.Activity.setContentView(Activity.java:1895)
08-04 12:33:44.403: E/AndroidRuntime(840): at com.example.camerafront.AndroidCamera.onCreate(AndroidCamera.java:30)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.app.Activity.performCreate(Activity.java:5133)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-04 12:33:44.403: E/AndroidRuntime(840): ... 11 more
08-04 12:33:44.403: E/AndroidRuntime(840): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.menu" on path: DexPathList[[zip file "/data/app/com.example.camerafront-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.camerafront-2, /system/lib]]
08-04 12:33:44.403: E/AndroidRuntime(840): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
08-04 12:33:44.403: E/AndroidRuntime(840): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-04 12:33:44.403: E/AndroidRuntime(840): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
08-04 12:33:44.403: E/AndroidRuntime(840): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
08-04 12:33:44.403: E/AndroidRuntime(840): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
08-04 12:33:44.403: E/AndroidRuntime(840): ... 20 more