2013-12-09 60 views
1

請幫忙!當我試圖寫onCreate方法。錯誤onCreate方法(FragmentActivity)

在該行

  • 多個標記式MainActivityParent方法的onCreate只能設置保護公共/ 之一/私人

    • 方法斷點:MainActivityParent [進入] - 的onCreate(捆綁)

    • 覆蓋android.support.v4.app.FragmentActivity.onCreate

這裏:

package com.example.seledkarelease1; 

import java.io.BufferedReader; 
import java.io.FileInputStream; 
import java.io.InputStreamReader; 
import java.util.LinkedList; 
import java.util.concurrent.ExecutionException; 

import org.apache.http.util.LangUtils; 

import android.annotation.SuppressLint; 
import android.annotation.TargetApi; 
import android.app.DialogFragment; 
import android.graphics.Color; 
import android.os.Build; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.view.GravityCompat; 
import android.support.v4.widget.DrawerLayout; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.Toast; 

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks; 
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Polyline; 
import com.google.android.gms.maps.model.PolylineOptions; 

public class MainActivityParent extends FragmentActivity implements 
     ConnectionCallbacks, OnConnectionFailedListener, 
     OnMyLocationButtonClickListener, 
     NoticeDialogFragment.NoticeDialogListener { 

    private ChildrenLocations ch; 
    private Polyline mMutablePolyline; 
    private boolean isGetting = false; 
    private ListView mDrawerList; 
    private DrawerLayout mDrawerLayout; 
    private String[] menuItems; 
    private GoogleMap mMap; 
    private LinkedList<LatLng> locations = new LinkedList<LatLng>(); 
    private 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main_parent); 

     menuItems = getResources().getStringArray(R.array.menu_items); 
     mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
     mDrawerList = (ListView) findViewById(R.id.left_drawer); 
     // set a custom shadow that overlays the main content when the drawer 
     // opens 
     mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, 
       GravityCompat.START); 
     // set up the drawer's list view with items and click listener 
     mDrawerList.setAdapter(new ArrayAdapter<String>(this, 
       R.layout.drawer_list_item, menuItems)); 
     mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); 

     // mMessageView = (TextView) findViewById(R.id.message_text); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     MenuInflater inflater = getMenuInflater(); 
     inflater.inflate(R.menu.main, menu); 
     return super.onCreateOptionsMenu(menu); 
    } 

    /* Called whenever we call invalidateOptionsMenu() */ 
    @Override 
    public boolean onPrepareOptionsMenu(Menu menu) { 
     // If the nav drawer is open, hide action items related to the content 
     // view 
     boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); 
     menu.findItem(R.id.action_settings).setVisible(!drawerOpen); 
     return super.onPrepareOptionsMenu(menu); 
    } 



    private void setUpMapIfNeeded() { 
     if (mMap == null) { 
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment) getSupportFragmentManager() 
        .findFragmentById(R.id.map)).getMap(); 
      // Check if we were successful in obtaining the map. 
      if (mMap != null) { 
       mMap.setMyLocationEnabled(true); 
       mMap.setOnMyLocationButtonClickListener(this); 
       setUpMap(); 
      } 
     } 
    } 


    private void setUpMap() { 
     if (locations.size() > 1) { 
      LatLng[] locs = new LatLng[locations.size()]; 
      locations.toArray(locs); 
      PolylineOptions opt = new PolylineOptions().add(locs/*locs[locs.length - 2], locs[locs.length - 2]*/); 
      mMap.addPolyline(opt.color(Color.RED).width(10)); 
      mMap.moveCamera(CameraUpdateFactory 
        .newLatLng(locs[locs.length - 1])); 
     } 
    } 

    public void showLocation(View view) { 
     ConnectionDetector cd = new ConnectionDetector(getApplicationContext()); 
     if (cd.isConnectingToInternet()) { 

      Toast.makeText(getApplicationContext(), "Data has been updated!", Toast.LENGTH_SHORT) 
        .show(); 
     }else{ 
      Toast.makeText(getApplicationContext(), "Please connect to the internet!", Toast.LENGTH_SHORT) 
      .show(); 
     } 
    } 



    public void loadPath(View view) { 
     TextView tv = (TextView) findViewById(R.id.fileNameField); 
     try { 
      FileInputStream fin = openFileInput(tv.getText().toString()); 
      InputStreamReader isr = new InputStreamReader(fin); 
      BufferedReader buffreader = new BufferedReader(isr); 
      locations = new LinkedList<LatLng>(); 
      String res = ""; 
      String readString = buffreader.readLine(); 
      while (readString != null) { 
       res += readString; 
       readString = buffreader.readLine(); 
      } 
      isr.close(); 
      Toast.makeText(this, res, Toast.LENGTH_SHORT).show(); 
      setUpMap(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 



    /* The click listner for ListView in the navigation drawer */ 
    private class DrawerItemClickListener implements 
      ListView.OnItemClickListener { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, 
       long id) { 
      selectItem(position); 
     } 
    } 

    private void selectItem(int position) { 
     if(position==0||position==1) 
     showNoticeDialog();  
    } 

    @TargetApi(Build.VERSION_CODES.HONEYCOMB) 
    @SuppressLint("NewApi") 
    public void showNoticeDialog() { 
     DialogFragment dialog = new NoticeDialogFragment(); 
     dialog.show(MainActivityParent.this.getFragmentManager(), 
       "NoticeDialogFragment"); 
    } 

    public void onUserSetValue(String name, String pass) 
      throws InterruptedException, ExecutionException { 
     isGetting=true; 
     String res = new Client().execute("8888", name + " " + pass).get(); 
     if (res.equals("-1")) 
      Toast.makeText(getApplicationContext(), "User was not found", 
        Toast.LENGTH_SHORT).show(); 
     if (res.equals("1")) 
      Toast.makeText(getApplicationContext(), 
        "User was succefully connected", Toast.LENGTH_SHORT).show(); 
     if (res.equals("0")) 
      Toast.makeText(getApplicationContext(), "Incorrect password", 
        Toast.LENGTH_SHORT).show(); 
     isGetting=false; 

    } 

    /** 
    * Callback called when disconnected from GCore. Implementation of 
    * {@link ConnectionCallbacks}. 
    */ 
    @Override 
    public void onDisconnected() { 

    } 

    /** 
    * Implementation of {@link OnConnectionFailedListener}. 
    */ 
    @Override 
    public void onConnectionFailed(ConnectionResult result) { 

    } 

    @Override 
    public boolean onMyLocationButtonClick() { 
     Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT) 
       .show(); 
     return false; 
    } 

    @Override 
    public void onDialogPositiveClick(DialogFragment dialog) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onDialogNegativeClick(DialogFragment dialog) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onConnected(Bundle arg0) { 
     // TODO Auto-generated method stub 

    } 



} 

,但在另一個類相同的方法不會有這些錯誤。

+0

更多的代碼,這是什麼活動的名稱和擴展你做什麼。 (也從'protected'改爲'public' – Blundell

+0

我已經嘗試過了,但也有同樣的錯誤 – user3051506

+0

嘗試清理你的項目,有時會遇到奇怪的錯誤有幫助 – cYrixmorten

回答

9

您的成員聲明中有空的浮動private。刪除。

private LinkedList<LatLng> locations = new LinkedList<LatLng>();

private

相關問題