2013-05-01 105 views
0

自從我升級到谷歌應用程序引擎1.7.7我無法在我的Android應用程序上設置我的實體數據。我收到一個空指針異常錯誤。在以前的GAE版本中,我沒有遇到這個問題。這裏是我的代碼谷歌App Engine 1.7.7問題

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的問題? 我需要,因爲這是在大學的最後一年的項目儘快此排序,我只有一兩天即可完成:(

感謝

+0

你沒有包含所有的文件,那麼哪一行是第60行? – 2013-05-01 12:10:32

+0

感謝您的回覆。第60行是tracks.setTrackName(String.valueOf(etTrackName.getText())); Emortal 2013-05-01 12:31:42

回答

2

你聲明tracks;

Tracks tracks; 

...並使用它......

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

...但從來沒有在課堂上與new Tracks()初始化它。我會宣佈它,我方法爲saveTrackToCloud;

Tracks tracks = new Tracks(); 

...並刪除實例變量,因爲它不再需要。最好讓你的變量保持在本地,這樣你可以清楚地看到它們是否被初始化。

+0

我不能相信我沒有注意到這一點。我現在正在用額頭拍我的手!非常感謝你 – Emortal 2013-05-01 12:44:47