When trying to integrate googleMaps into my MainActivity following instructions here, the word GpsLocation
(orange box 6 on linked page) goes red and says- Invalid method declaration; return type required
.
在尝试按照此处的说明将googleMaps集成到我的MainActivity时,单词GpsLocation(链接页面上的橙色框6)变为红色并显示 - 无效的方法声明;需要返回类型。
I know this means it has to be inside of a button or a void or something, but here I have no idea what it needs to be in. So please, take a look at my MainActivity, and tell me where I am going wrong.
我知道这意味着它必须在按钮或虚空或其他内部,但在这里我不知道它需要什么。所以,请看看我的MainActivity,告诉我哪里出错了。
Here's my MainActivity:
这是我的MainActivity:
package com.lalalaala.mapstest;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
public class MainActivity extends AppCompatActivity {
private GoogleMap googleMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
}
else {
// Changing map type
//TODO
}
}
}
public GpsLocation (Context mContext, TextView gpsStatusTextView) {
this.mContext = mContext;
this.gpsStatusTextView = gpsStatusTextView;
getLocation();
}
}
Thank you
1 个解决方案
#1
1
A method needs to have a return type in your case GpsLocation
and a name. Currently you only have a return type.
一个方法需要在您的案例GpsLocation和名称中具有返回类型。目前您只有一个返回类型。
public GpsLocation methodName (Context mContext, TextView gpsStatusTextView) {
}
not
public GpsLocation (Context mContext, TextView gpsStatusTextView) {
}
#1
1
A method needs to have a return type in your case GpsLocation
and a name. Currently you only have a return type.
一个方法需要在您的案例GpsLocation和名称中具有返回类型。目前您只有一个返回类型。
public GpsLocation methodName (Context mContext, TextView gpsStatusTextView) {
}
not
public GpsLocation (Context mContext, TextView gpsStatusTextView) {
}