Android 设置相机帮助时出错
Getting Error In Android Setting Camera Help Neded
我正在学习 android 相机捕捉并将其设置为来自教程的墙纸但是出现错误我努力寻找但无法弄清楚我在另一个 class 中设置了这个 class by anotherlistitem 点击这里是我的代码。
public class Camera extends Activity implements View.OnClickListener {
ImageView iv;
ImageButton ib;
Button b;
Intent i;
final static int cameraData = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
initilize();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.BResults:
break;
case R.id.ibtakenimage:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap bmp = (Bitmap) extras.get("Data");
iv.setImageBitmap(bmp);
}
}
public void initilize() {
iv = (ImageView) findViewById(R.id.IVimageview);
ib = (ImageButton) findViewById(R.id.ibtakenimage);
b = (Button) findViewById(R.id.BResults);
b.setOnClickListener(this);
ib.setOnClickListener(this);
}
}
这是我的 logcat。
01-14 02:37:21.770: E/Trace(1247): error opening trace file: No such file or directory (2)
01-14 02:37:22.200: D/dalvikvm(1247): GC_FOR_ALLOC freed 79K, 9% free 2442K/2660K, paused 55ms, total 57ms
01-14 02:37:22.210: I/dalvikvm-heap(1247): Grow heap (frag case) to 3.103MB for 614416-byte allocation
01-14 02:37:22.250: D/dalvikvm(1247): GC_FOR_ALLOC freed 2K, 7% free 3040K/3264K, paused 35ms, total 35ms
01-14 02:37:22.280: D/dalvikvm(1247): GC_CONCURRENT freed <1K, 7% free 3190K/3416K, paused 4ms+3ms, total 38ms
01-14 02:37:22.520: D/gralloc_goldfish(1247): Emulator without GPU emulation detected.
01-14 02:37:28.100: I/Choreographer(1247): Skipped 195 frames! The application may be doing too much work on its main thread.
01-14 02:37:28.270: I/Choreographer(1247): Skipped 30 frames! The application may be doing too much work on its main thread.
01-14 02:37:43.140: I/Choreographer(1247): Skipped 52 frames! The application may be doing too much work on its main thread.
01-14 02:37:43.440: D/AndroidRuntime(1247): Shutting down VM
01-14 02:37:43.460: W/dalvikvm(1247): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
----->>>> 01-14 02:37:43.530: E/AndroidRuntime(1247): FATAL EXCEPTION: main
01-14 02:37:43.530: E/AndroidRuntime(1247): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidme/com.example.androidme.Camera}: java.lang.NullPointerException
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.access0(ActivityThread.java:141)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.os.Looper.loop(Looper.java:137)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-14 02:37:43.530: E/AndroidRuntime(1247): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 02:37:43.530: E/AndroidRuntime(1247): at java.lang.reflect.Method.invoke(Method.java:511)
01-14 02:37:43.530: E/AndroidRuntime(1247): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-14 02:37:43.530: E/AndroidRuntime(1247): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-14 02:37:43.530: E/AndroidRuntime(1247): at dalvik.system.NativeStart.main(Native Method)
01-14 02:37:43.530: E/AndroidRuntime(1247): Caused by: java.lang.NullPointerException
01-14 02:37:43.530: E/AndroidRuntime(1247): at com.example.androidme.Camera.initilize(Camera.java:58)
01-14 02:37:43.530: E/AndroidRuntime(1247): at com.example.androidme.Camera.onCreate(Camera.java:24)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.Activity.performCreate(Activity.java:5104)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-14 02:37:43.530: E/AndroidRuntime(1247): ... 11 more
----> 错误开始。
Caused by: java.lang.NullPointerException
at com.example.androidme.Camera.initilize(Camera.java:58)
告诉你错误。在您的相机 class 的第 58 行中,您正试图访问一个不存在的对象,即为 null。
必须是以下行之一:
b.setOnClickListener(this);
ib.setOnClickListener(this);
因此您所要做的就是检查您之前输入的 ID 是否与您在 .xml.
中指定的 ID 正确
我正在学习 android 相机捕捉并将其设置为来自教程的墙纸但是出现错误我努力寻找但无法弄清楚我在另一个 class 中设置了这个 class by anotherlistitem 点击这里是我的代码。
public class Camera extends Activity implements View.OnClickListener {
ImageView iv;
ImageButton ib;
Button b;
Intent i;
final static int cameraData = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
initilize();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.BResults:
break;
case R.id.ibtakenimage:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap bmp = (Bitmap) extras.get("Data");
iv.setImageBitmap(bmp);
}
}
public void initilize() {
iv = (ImageView) findViewById(R.id.IVimageview);
ib = (ImageButton) findViewById(R.id.ibtakenimage);
b = (Button) findViewById(R.id.BResults);
b.setOnClickListener(this);
ib.setOnClickListener(this);
}
}
这是我的 logcat。
01-14 02:37:21.770: E/Trace(1247): error opening trace file: No such file or directory (2)
01-14 02:37:22.200: D/dalvikvm(1247): GC_FOR_ALLOC freed 79K, 9% free 2442K/2660K, paused 55ms, total 57ms
01-14 02:37:22.210: I/dalvikvm-heap(1247): Grow heap (frag case) to 3.103MB for 614416-byte allocation
01-14 02:37:22.250: D/dalvikvm(1247): GC_FOR_ALLOC freed 2K, 7% free 3040K/3264K, paused 35ms, total 35ms
01-14 02:37:22.280: D/dalvikvm(1247): GC_CONCURRENT freed <1K, 7% free 3190K/3416K, paused 4ms+3ms, total 38ms
01-14 02:37:22.520: D/gralloc_goldfish(1247): Emulator without GPU emulation detected.
01-14 02:37:28.100: I/Choreographer(1247): Skipped 195 frames! The application may be doing too much work on its main thread.
01-14 02:37:28.270: I/Choreographer(1247): Skipped 30 frames! The application may be doing too much work on its main thread.
01-14 02:37:43.140: I/Choreographer(1247): Skipped 52 frames! The application may be doing too much work on its main thread.
01-14 02:37:43.440: D/AndroidRuntime(1247): Shutting down VM
01-14 02:37:43.460: W/dalvikvm(1247): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
----->>>> 01-14 02:37:43.530: E/AndroidRuntime(1247): FATAL EXCEPTION: main
01-14 02:37:43.530: E/AndroidRuntime(1247): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidme/com.example.androidme.Camera}: java.lang.NullPointerException
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.access0(ActivityThread.java:141)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.os.Looper.loop(Looper.java:137)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-14 02:37:43.530: E/AndroidRuntime(1247): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 02:37:43.530: E/AndroidRuntime(1247): at java.lang.reflect.Method.invoke(Method.java:511)
01-14 02:37:43.530: E/AndroidRuntime(1247): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-14 02:37:43.530: E/AndroidRuntime(1247): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-14 02:37:43.530: E/AndroidRuntime(1247): at dalvik.system.NativeStart.main(Native Method)
01-14 02:37:43.530: E/AndroidRuntime(1247): Caused by: java.lang.NullPointerException
01-14 02:37:43.530: E/AndroidRuntime(1247): at com.example.androidme.Camera.initilize(Camera.java:58)
01-14 02:37:43.530: E/AndroidRuntime(1247): at com.example.androidme.Camera.onCreate(Camera.java:24)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.Activity.performCreate(Activity.java:5104)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-14 02:37:43.530: E/AndroidRuntime(1247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-14 02:37:43.530: E/AndroidRuntime(1247): ... 11 more
----> 错误开始。
Caused by: java.lang.NullPointerException
at com.example.androidme.Camera.initilize(Camera.java:58)
告诉你错误。在您的相机 class 的第 58 行中,您正试图访问一个不存在的对象,即为 null。
必须是以下行之一:
b.setOnClickListener(this);
ib.setOnClickListener(this);
因此您所要做的就是检查您之前输入的 ID 是否与您在 .xml.
中指定的 ID 正确