2012-03-16 7 views
-1
  package com.locatn; 

      import java.io.File; 
      import java.io.IOException; 
      import java.io.OutputStream; 
      import java.io.OutputStreamWriter; 
      import java.io.Writer; 

      import android.app.Activity; 
      import android.content.Context; 

      import android.location.LocationManager; 
      import android.os.Bundle; 
      import android.os.Environment; 

       import android.widget.Toast; 

       public class Location extends Activity { 
        private LocationManager locationManagerNetwork; 


        @Override 
        public void onCreate(Bundle savedInstanceState) { 
         super.onCreate(savedInstanceState); 
         setContentView(R.layout.main); 


        locationManagerNetwork = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
        android.location.Location location2 = locationManagerNetwork 
            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
       if (location2 != null) { `enter code here`  
          String message = String 
            .format("Yout location : \n Longitude: %1$s \n Latitude: %2$s", 
              location2.getLongitude(), location2.getLatitude()); 
          Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG) 
            .show(); 

//このコードの保存部分に多くのエラーが発生しています。
このコードを修正する手助けをしてください。 撮影した位置情報をtxtファイルとして保存し、SDカードに保存します。 私の友人を助けてください..... //撮影したネットワークの場所を保存するにはどうすればよいですか?

// following are the errors // 

       // Illegal modifier for the local class WriteTextFileExample; only abstract or final is permitted // 
        *public class WriteTextFileExample{ 
// The method main cannot be declared static; static methods can only be declared in a static or top level type // 
          public static void main(String[] args)throws IOException{ 
          Writer output = null; 

          File sdcard = Environment.getExternalStorageDirectory(); 
          File file = new File("/sdcard/andsecure/mysdfile.txt"); 
// Multiple markers at this line // 
    // - BufferedWriter cannot be resolved to a type // 
    // - BufferedWriter cannot be resolved to a type // 
    // - Cannot refer to a non-final variable location2 inside an inner class defined in a different // 
    // method - FileWriter cannot be resolved to a type // 
          output = new BufferedWriter(new FileWriter(location2)); 
// text cannot be resolved to a variable // 
          output.write(text); 
          output.close();*** 

          } 
         } 


          } 
         } 


        } 
+2

を、エラーがありますか? –

答えて

1

あなたはFileからLocationオブジェクトを作成しようとしています。最初に文字列に変換する必要があるため、これは機能しません。このLocationを後で読みたい場合は、LocationオブジェクトのJSON表現を保存することを検討してください。

それは直列化が非常に容易になりますように私は、Gsonを示唆している:...

Gson gson = new Gson(); 
JsonObject json = gson.toJson(location2); 
String text = json.toString(); 
関連する問題