请帮忙!当我试图写onCreate方法时。
此行有多个标记
类型MainActivityParent中的onCreate方法只能设置一个public / 受保护/私人
方法断点:MainActivityParent [entry] - onCreate(Bundle)
覆盖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 :(得分:9)
您的会员声明中有一个空的private
。删除它。
private LinkedList<LatLng> locations = new LinkedList<LatLng>();
private