0

自从我升级到 google app engine 1.7.7 后,我无法在我的 android 应用程序上设置我的实体数据。我收到一个空指针异常错误。在以前版本的 GAE 上我没有这个问题。这是我的代码

public class SaveTrackActivity extends Activity {

    static String TAG = "SaveTrackActivity";

    Tracksendpoint endpoint;
    private TrackRateApp trackapp;
    private EditText etTrackName;
    private EditText etTrackDes;
    private ImageView ivTrackPic;
    Bitmap trackImage;
    Tracks tracks;
    int numBackEndTasks;

    String encodedImage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_save_track);
        initialize();
        Intent saveTrackIntent = getIntent();
        trackImage = (Bitmap)saveTrackIntent.getParcelableExtra("BitMapImage");
        ivTrackPic.setImageBitmap(trackImage);

    }

    private void initialize() {
        trackapp = (TrackRateApp)getApplication();
        endpoint = trackapp.getEndpoint();
        etTrackName = (EditText) findViewById(R.id.etTrackName);
        etTrackDes = (EditText) findViewById(R.id.edTrackDescr);
        ivTrackPic = (ImageView) findViewById(R.id.trackImage);
    }

    public void saveTrackToCloud(View v){
        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        trackImage.compress(Bitmap.CompressFormat.PNG, 100 , baos);    
        byte[] b = baos.toByteArray(); 
        encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
        Log.d(TAG, "GeopointArray size is: " + trackapp.getGeoPtArray().size());

        tracks.setTrackName(String.valueOf(etTrackName.getText()));
        tracks.setTrackDescription(String.valueOf(etTrackDes.getText()));
        tracks.setTrackImage(encodedImage);
        tracks.setRoute(trackapp.getGeoPtArray());
        addTracks(tracks);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.save_track, menu);
        return true;
    }

    public void addTracks(Tracks tracks) {
        new AsyncAddTrack(this).execute(tracks);
    }
}

当我尝试设置数据时出现问题tracks.setTrackName(String.valueOf(etTrackName.getText())); tracks.setTrackDescription(String.valueOf(etTrackDes.getText())); tracks.setTrackImage(encodedImage); tracks.setRoute(trackapp.getGeoPtArray());

我收到这个错误

05-01 12:41:19.522: E/AndroidRuntime(6858): FATAL EXCEPTION: main
05-01 12:41:19.522: E/AndroidRuntime(6858): java.lang.IllegalStateException: Could not execute method of the activity
05-01 12:41:19.522: E/AndroidRuntime(6858):     at android.view.View$1.onClick(View.java:3691)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at android.view.View.performClick(View.java:4211)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at android.view.View$PerformClick.run(View.java:17267)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at android.os.Handler.handleCallback(Handler.java:615)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at android.os.Looper.loop(Looper.java:137)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at android.app.ActivityThread.main(ActivityThread.java:4898)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at java.lang.reflect.Method.invokeNative(Native Method)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at java.lang.reflect.Method.invoke(Method.java:511)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at dalvik.system.NativeStart.main(Native Method)
05-01 12:41:19.522: E/AndroidRuntime(6858): Caused by: java.lang.reflect.InvocationTargetException
05-01 12:41:19.522: E/AndroidRuntime(6858):     at java.lang.reflect.Method.invokeNative(Native Method)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at java.lang.reflect.Method.invoke(Method.java:511)
05-01 12:41:19.522: E/AndroidRuntime(6858):     at android.view.View$1.onClick(View.java:3686)
05-01 12:41:19.522: E/AndroidRuntime(6858):     ... 11 more
05-01 12:41:19.522: E/AndroidRuntime(6858): Caused by: java.lang.NullPointerException
05-01 12:41:19.522: E/AndroidRuntime(6858):     at com.jman.trackrate.SaveTrackActivity.saveTrackToCloud(SaveTrackActivity.java:60)
05-01 12:41:19.522: E/AndroidRuntime(6858):     ... 14 more

任何人都可以帮忙还是这是一个已知的 GAE 问题?我需要尽快完成这个排序,因为这是我在大学的最后一年项目,我只剩下几天可以完成了:(

谢谢

4

1 回答 1

2

你在声明tracks

Tracks tracks;

...并使用它...

tracks.setTrackName(String.valueOf(etTrackName.getText()));

...但永远不要new Tracks()在课堂上初始化它。我会在saveTrackToCloud方法中将其声明为;

Tracks tracks = new Tracks();

...并删除实例变量,因为不再需要它。最好将变量保留在本地,以便您可以清楚地看到它们是否已初始化。

于 2013-05-01T12:37:52.627 回答