0

我有一个布局,在那里,我有 View(类似这样的东西)一个):

<app.piotrek.learning.EObrazView
        android:id="@+id/myView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

在这个视图中,用户可以绘制一些东西 :) 屏幕底部有六个按钮。我想做的是,如果用户单击按钮,视图中的功能就会运行。我已经这样做了:

public class EObraz extends Activity {
[...]
EObrazView view1;
ImageButton minus;
ImageButton plus;
ImageButton kolo;
ImageButton strzalka;
ImageButton color;
ImageButton obrot;
Button menu;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edytujobraz);
    context = getApplicationContext();

    view1 = (EObrazView) findViewById(R.id.myView);
    minus = (ImageButton) findViewById(R.id.imageButton1);
    plus = (ImageButton) findViewById(R.id.imageButton2);
    kolo = (ImageButton) findViewById(R.id.imageButton3);
    strzalka = (ImageButton) findViewById(R.id.imageButton4);
    color = (ImageButton) findViewById(R.id.imageButton5);
    obrot = (ImageButton) findViewById(R.id.imageButton6);
    menu = (Button) findViewById(R.id.button1);

    bundle = getIntent().getExtras();
    sciezka_z_obrazem = bundle.getString("obrazeksciezka");
    Uri myUri = Uri.parse(sciezka_z_obrazem);

    try {
        wo = MediaStore.Images.Media.getBitmap(
                getContentResolver(), myUri);
    } catch (Exception e) {

    }

    //wo = scaleImages(wo, mWidth, ((float) wo.getHeight() / (float) wo.getWidth()) * (float) (mWidth), 0);
    if(wo != null){
    view1.newImage(wo); //THERE IS AN ERROR: NULLPOINTEREXCEPTION
    }

在这一行(行号 #69):

view1.newImage(wo); //THERE IS AN ERROR: NULLPOINTEREXCEPTION

是不是错误:

12-02 15:05:24.858: E/AndroidRuntime(10315): FATAL EXCEPTION: main
12-02 15:05:24.858: E/AndroidRuntime(10315): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.piotrek.learning/app.piotrek.learning.EObraz}: java.lang.NullPointerException
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.app.ActivityThread.access$600(ActivityThread.java:142)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.os.Looper.loop(Looper.java:137)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.app.ActivityThread.main(ActivityThread.java:4931)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at java.lang.reflect.Method.invokeNative(Native Method)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at java.lang.reflect.Method.invoke(Method.java:511)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at dalvik.system.NativeStart.main(Native Method)
12-02 15:05:24.858: E/AndroidRuntime(10315): Caused by: java.lang.NullPointerException
12-02 15:05:24.858: E/AndroidRuntime(10315):    at app.piotrek.learning.EObraz.onCreate(EObraz.java:69)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.app.Activity.performCreate(Activity.java:5008)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-02 15:05:24.858: E/AndroidRuntime(10315):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
12-02 15:05:24.858: E/AndroidRuntime(10315):    ... 11 more

怎么了?

4

0 回答 0