在android studio中运行我的程序时遇到错误。这是以下消息错误:
public class ParentModel
{
public string EnvironmentName { get; set; }
}
MainActivity.java的第103行如下:
[HttpPost]
public ActionResult ParentClass(string submit, ParentModel model)
{
//omit
var envName = model.EnvironmentName;
//I am not seeing a value for model.EnvironmentName at this point
}
这是AndroidManifest.xml中的权限代码:
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: Process: com.example.natasya.myapplication, PID: 3478
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.natasya.myapplication/com.example.natasya.myapplication.MainActivity}: java.lang.IllegalArgumentException: invalid provider: null
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: Caused by: java.lang.IllegalArgumentException: invalid provider: null
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.location.LocationManager.checkProvider(LocationManager.java:1704)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1194)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at com.example.natasya.myapplication.MainActivity.getlongilatifile(MainActivity.java:103)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at com.example.natasya.myapplication.MainActivity.onCreate(MainActivity.java:76)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6237)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-22 19:13:54.831 3478-3478/com.example.natasya.myapplication E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我很困惑为什么会这样?请帮帮我。
这是MainActivity:
Location location = locationManager.getLastKnownLocation(bestProvider);
}
谢谢, 阿贡
答案 0 :(得分:2)
传递给getLastKnownLocation
的提供程序应该是以下字符串常量之一:
GPS_PROVIDER
,有价值" gps";
NETWORK_PROVIDER
,有价值"网络";
PASSIVE_PROVIDER
,有价值"被动";
以下是source code of getLastKnownLocation
:
public Location getLastKnownLocation(String provider) {
checkProvider(provider);
String packageName = mContext.getPackageName();
LocationRequest request = LocationRequest.createFromDeprecatedProvider(
provider, 0, 0, true);
try {
return mService.getLastLocation(request, packageName);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException", e);
return null;
}
}
和方法checkProvider
:
private static void checkProvider(String provider) {
if (provider == null) {
throw new IllegalArgumentException("invalid provider: " + provider);
}
}
由此我们可以得出结论,你的参数bestProvider
为空,而不是有效的提供者字符串。