I want to create a packet and send to over network(2nd layer of network) in android application I use android studio.I download jnetpcap-1.3.0 file , this file include some file such as jnetPcap.jar , I add this jar file to my android project,Is it right or not?
at this step I can call some classes in the jar file(jnetpcap.jar) but when I want run this android application I have an error and I don't know how I can solve this problem.
I asign some permission to android appliaton, such as permission is :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission zndroid:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
My code is:
int size=100;
Ethernet wEth;
byte[] sourceMac={};
byte[] destMac={};
Ip4 wIp4;
byte[] bytes={};
byte[] dIP={};
byte[] sIP={};
try {
Process p = Runtime.getRuntime().exec("su");
JPacket wPacket = new JMemoryPacket(size);
wPacket.order(ByteOrder.BIG_ENDIAN);
wPacket.setUShort(12, 0x0800);
wPacket.scan(JProtocol.ETHERNET_ID);
wEth = wPacket.getHeader(new Ethernet());
wEth.source(sourceMac);
wEth.destination(destMac);
wEth.checksum(wEth.calculateChecksum());
int headersize = 14;
wPacket.setUByte(14, 0x40 | 0x05);
wPacket.scan(JProtocol.ETHERNET_ID);
wIp4 = wPacket.getHeader(new Ip4());
wIp4.length(500 - wEth.size());
wIp4.source(dIP);
wIp4.destination(sIP);
wIp4.ttl(32);
wIp4.flags(0);
wIp4.offset(0);
wIp4.checksum(wIp4.calculateChecksum());
headersize += 20;
}catch (Exception ex)
{
ex.printStackTrace();
}
and I have this error that shows on logcat on androis studio :
1. 11-15 14:03:42.084 2996-2996/com.example.saeed.monoq E/Trace: error
opening trace file: No such file or directory (2) 11-15 14:03:42.814
2996-2996/com.example.saeed.monoq E/dalvikvm: Could not find class
'android.util.ArrayMap', referenced from method
com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
11-15 14:03:42.844 2996-2996/com.example.saeed.monoq E/dalvikvm:
Could not find class 'android.util.ArrayMap', referenced from method
com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache 11-15
14:03:44.884 2996-2996/com.example.saeed.monoq E/AndroidRuntime:
FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at
com.example.saeed.monoq.MainActivity.onCreate(MainActivity.java:69)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:107 at
how can I solve this problem?
Check your Gradle files to see if you have included all required dependencies. For packet manipulation, you may want to check on mvn repo details.
Related
I have seen several questions regarding SocketException when using Android, but none of them cover the BindException that I get even with the INTERNET permission specified in my manifest.
Here is part of my manifest:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_OWNER_DATA"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCOUNT_MANAGER"></uses-permission>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission>
Here is the relevant portion of my LogCat output:
04-22 14:49:06.117: DEBUG/MyLibrary(4844): Address to bind: 192.168.1.14 port: 843
04-22 14:49:06.197: WARN/System.err(4844): java.net.BindException: Permission denied (maybe missing INTERNET permission)
04-22 14:49:06.207: WARN/System.err(4844): at org.apache.harmony.luni.platform.OSNetworkSystem.socketBindImpl(Native Method)
04-22 14:49:06.207: WARN/System.err(4844): at org.apache.harmony.luni.platform.OSNetworkSystem.bind(OSNetworkSystem.java:107)
04-22 14:49:06.217: WARN/System.err(4844): at org.apache.harmony.luni.net.PlainSocketImpl.bind(PlainSocketImpl.java:184)
04-22 14:49:06.217: WARN/System.err(4844): at java.net.ServerSocket.bind(ServerSocket.java:414)
04-22 14:49:06.227: WARN/System.err(4844): at org.apache.harmony.nio.internal.ServerSocketChannelImpl$ServerSocketAdapter.bind(ServerSocketChannelImpl.java:213)
04-22 14:49:06.227: WARN/System.err(4844): at java.net.ServerSocket.bind(ServerSocket.java:367)
04-22 14:49:06.237: WARN/System.err(4844): at org.apache.harmony.nio.internal.ServerSocketChannelImpl$ServerSocketAdapter.bind(ServerSocketChannelImpl.java:283)
04-22 14:49:06.237: WARN/System.err(4844): at mylibrary.net.PolicyConnection$PolicyServerWorker.(PolicyConnection.java:201)
I Really hope this is a simple problem and not something complicated by the fact that the binding is occurring within a worker thread on a port less than 1024.
Update
Looks as if this is a privileged port issue, anyone know how to bind to ports lower than 1024 in Android?
SelectorProvider provider = SelectorProvider.provider();
try {
ServerSocketChannel channel = provider.openServerSocketChannel();
policySocket = channel.socket();
Log.d("MyLibrary", "Address to bind: " + device.getAddress().getAddress() + " port: 843");
InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(device.getAddress().getAddress()), 843);
policySocket.bind(addr);
policySocket.setReuseAddress(true);
policySocket.setReceiveBufferSize(256);
} catch (Exception e) {
e.printStackTrace();
}
anyone know how to bind to ports lower
than 1024 in Android?
Either root your phone, modify the firmware, or don't bind to ports lower than 1024. That's a Linux thing more than an Android thing.
Try add permission android.permission.INTERNET
it worked for me
java.lang.RuntimeException: setAudioSource failed.
11-07 20:30:16.294 12438-12438/com.main.sample W/System.err: at android.media.MediaRecorder.setAudioSource(Native Method)
11-07 20:30:16.294 12438-12438/com.main.sample W/System.err: at com.main.sample.Activity.EventsaddActivity.initializeMediaRecord
In the first step you need to add these permissions:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
set target sdk to 22 or use request permission and set target to 23 or above.
and check your path again
MediaRecorder.setAudioSource(new File("YOUR_PATH"));
I am trying to develop one app for Google map v2. i followed the all the instructions. i generate API_KEY and placed it into android manifest file also.
On the "Order and Export" tab I checked "Android Private Libraries" on my project. I also did this for the library project it references.
But i get the error when i run app in emulator as well as android device also. my log cat fallow the error like
10-09 03:02:37.905: E/PAUSE(2949): TIMERS!
10-09 03:02:37.921: W/dalvikvm(2949): VFY: unable to find class referenced in signature (Lcom/google/android/gms/maps/GoogleMap;)
10-09 03:02:37.921: I/dalvikvm(2949): Could not find method com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable, referenced from method com.zarrin.negar.LocationActivity.checkGooglePlayServicesForUpdate
10-09 03:02:37.921: W/dalvikvm(2949): VFY: unable to resolve static method 3699: Lcom/google/android/gms/common/GooglePlayServicesUtil;.isGooglePlayServicesAvailable (Landroid/content/Context;)I
10-09 03:02:37.925: D/dalvikvm(2949): VFY: replacing opcode 0x71 at 0x0005
10-09 03:02:37.925: E/dalvikvm(2949): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method com.zarrin.negar.LocationActivity.initialization
10-09 03:02:37.925: W/dalvikvm(2949): VFY: unable to resolve check-cast 615 (Lcom/google/android/gms/maps/SupportMapFragment;) in Lcom/zarrin/negar/LocationActivity;
10-09 03:02:37.933: D/dalvikvm(2949): VFY: replacing opcode 0x1f at 0x0021
10-09 03:02:37.937: E/dalvikvm(2949): Could not find class 'com.google.android.gms.maps.model.LatLng', referenced from method com.zarrin.negar.LocationActivity.setGps
10-09 03:02:37.941: W/dalvikvm(2949): VFY: unable to resolve new-instance 618 (Lcom/google/android/gms/maps/model/LatLng;) in Lcom/zarrin/negar/LocationActivity;
10-09 03:02:37.941: D/dalvikvm(2949): VFY: replacing opcode 0x22 at 0x0021
10-09 03:02:37.941: E/dalvikvm(2949): Could not find class 'com.google.android.gms.maps.model.LatLng', referenced from method com.zarrin.negar.LocationActivity.setLocation
10-09 03:02:37.945: W/dalvikvm(2949): VFY: unable to resolve new-instance 618 (Lcom/google/android/gms/maps/model/LatLng;) in Lcom/zarrin/negar/LocationActivity;
10-09 03:02:37.945: D/dalvikvm(2949): VFY: replacing opcode 0x22 at 0x001e
10-09 03:02:37.949: D/dalvikvm(2949): DexOpt: unable to opt direct call 0x0f0e at 0x27 in Lcom/zarrin/negar/LocationActivity;.setGps
10-09 03:02:37.949: D/dalvikvm(2949): DexOpt: unable to opt direct call 0x0f10 at 0x37 in Lcom/zarrin/negar/LocationActivity;.setGps
10-09 03:02:37.949: D/dalvikvm(2949): DexOpt: unable to opt direct call 0x0f0e at 0x40 in Lcom/zarrin/negar/LocationActivity;.setGps
10-09 03:02:37.949: I/dalvikvm(2949): Failed resolving Lcom/zarrin/negar/LocationActivity$1; interface 612 'Lcom/google/android/gms/maps/GoogleMap$OnMapClickListener;'
manifest:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.CLEAR_CACHE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission
android:name="com.zarrin.negar.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.zarrin.negar.permission.C2D_MESSAGE" />
<permission
android:name="com.zarrin.negar.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.zarrin.negar.permission.MAPS_RECEIVE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
and my activity :
<activity
android:name="com.zarrin.negar.LocationActivity"
android:screenOrientation="portrait"
android:launchMode="singleTop" >
</activity>
meta data :
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my_api_key" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
image of my project's properties :
image 1
image 2
This could be because of your project configuration, or your emulator configuration.
Project
Have you imported as a library Google Play services project from your
SDK?
Emulator
Has your emulator installed Google Play Services? Try running an
emulator with SDK (Google APIs)
Good luck buddy!
I tried to install project present in tutorial:
All It's ok but when run project, logcat say:
"Could not find class 'maps.ag.l', referenced from method maps.ah.an.a"
The map is empty and logcat say:
" Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
I have changed package name from "in.wptrafficanalyzer.locationgooglemapv2demo" to "it.appatwork" and i have got the apikey for android maps apiV2 with my sha1.
I have android 2.3.3
Please help me!
Mainactivity:
package it.appatwork.locationgooglemapv2demo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable (getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
System.out.println("ok");
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
AndoridManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.appatwork.locationgooglemapv2demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="it.appatwork.locationgooglemapv2demo.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBgkEwv0Z4O2t27avrve_33N33QY0wHNXg"/>
</application>
</manifest>
UPDATE:
this is the logcat output:
07-24 23:11:40.849: W/dalvikvm(6472): VFY: unable to resolve instance field 24
07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/p/w; (718)
07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/p/w;' failed
07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/aq/as; (5347)
07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/aq/as;' failed
07-24 23:11:41.149: W/dalvikvm(6472): Unable to resolve superclass of Lmaps/ag/l; (4576)
07-24 23:11:41.149: W/dalvikvm(6472): Link of class 'Lmaps/ag/l;' failed
07-24 23:11:41.149: E/dalvikvm(6472): Could not find class 'maps.ag.l', referenced from method maps.ah.an.a
07-24 23:11:41.149: W/dalvikvm(6472): VFY: unable to resolve new-instance 4420 (Lmaps/ag/l;) in Lmaps/ah/an;
07-24 23:11:41.359: I/ApplicationPackageManager(6472): cscCountry is not German : WIN
07-24 23:11:47.069: W/Google Maps Android API(6472): Please add <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> into AndroidManifest.xml to ensure correct behavior under poor connectivity conditions.
07-24 23:11:47.069: I/Google Maps Android API(6472): Failed to contact Google servers. Another attempt will be made when connectivity is established.
07-24 23:11:59.009: W/IInputConnectionWrapper(6472): getExtractedText on inactive InputConnection
07-24 23:11:59.009: W/IInputConnectionWrapper(6472): getExtractedText on inactive InputConnection
07-24 23:12:02.289: E/Google Maps Android API(6472): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
First of all the two problem you are describing are not related one to another, you main problem is here:
Failed to load map. Error contacting Google servers. This is probably
an authentication issue (but could be due to network errors).
This means that you have some kind of problem with you permissions in the manifest file, or with you configuration in the Google API's console.
Please go over all the steps of this two blog post, Google Maps API V2 key and Google Maps API V2, and commit all the steps, if you still have problems post here your code and updated logcat message.
UPDATE:
You package name:
package="it.appatwork.locationgooglemapv2demo"
does not match the package name you specified in the permissions:
permission
android:name="it.appatwork.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="it.appatwork.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"/>
I think it's case-sensitive so try to change it to:
permission
android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="it.appatwork.locationgooglemapv2demo.permission.MAPS_RECEIVE"/>
I'm creating sample application to use Google Maps Android API v2.
I tried on Samsung Galaxy Ace GT-S5830i, but instead of Map, I'm seeing
And logcat is
Signature not valid. Found:
MIIDDTCCAfWgAwIBAgIEEhX+gTANBgkqhkiG9w0BAQsFADA3MQswCQYDVQQGEwJVUzEQMA4GA1UE
ChMHQW5kcm9pZDEWMBQGA1UEAxMNQW5kcm9pZCBEZWJ1ZzAeFw0xMzAyMjUxMTEwNDRaFw00MzAy
MTgxMTEwNDRaMDcxCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdBbmRyb2lkMRYwFAYDVQQDEw1BbmRy
b2lkIERlYnVnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApqChoDnHsDfsxa7n2Kv9
2av0G0tm+kS1uP4T6fA8cO6jB3qB5EHFR6+5UO+k4laHW2WzOJbyhhtFE5eOTS4Zt5qo4FX/hsc/
Zi7dDX/Y13b+4qajhLoGYqVjM00eQc2qF58TTnbQ3lTERxaofYL2qI3j2KcVODFMksinL9lt3RTD
V3MXy7KDLcuSvoVZxXn1L0O9rkTbZicmleK4wLDzI+lTpuXngAuQ4MBH1wEWwqMhJg6/J06t5axU
ea2UVv7ZtYg8KPMEiQEApCbdAHtQsmqcsEQZtJAqFtj7KEQ7wTSgnpDRix4N5C9QlwUtKSlOCIlk
ueUPVBypKf/SWIgF6QIDAQABoyEwHzAdBgNVHQ4EFgQURyMuspjlLaDj8LhEb5UyYqQgWQYwDQYJ
KoZIhvcNAQELBQADggEBAA9IXLEAQTD+VEt9l8JQDEOFv8WqIdQisvmJCfJjN98faarvf6RRA+v3
HF2VFlZPaUu/HBeOH8MI7u+gNuRtZGYWn1eC/qfP0W31MQoNaN4ocsF+tL9INzpd89/u6Ya5Kove
r0E0tpJFBgdtDPYcPBjQ6tYAqmhnmPIJftGHLNQbil4ocK/PkqgxGlwQN7WrCNjDewb0twz7hZBx
Ig4OsnfdgPTYGlR+LyTzUd9/KyqaLHivRAI+y/xGDz6lOfGH7bDOPi/hDm0bkhC1y1J7L9+FiGWb
dmi+Co9Jlf1f3vyTtD7kr3h0K0C3MsNWtybVqmVvgImoLt/lPbjNJahVrds=
Google Play services signature invalid.
Can't open keycharmap file
Error loading keycharmap file
Using default keymap
My manifest code
<?xml version="1.0" encoding="utf-8"?>
<permission
android:name="com.example.testmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.testmap.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.testmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDTsWrO0j24sbp4E5qhoHhd6nyOQM5lErc" />
<activity
android:name="com.example.testmap.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
my xml file code
<?xml version="1.0" encoding="utf-8"?>
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
My activity code
package com.example.testmap;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.final_main);
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//map.getMinZoomLevel();
}
}
And clicking on ok button gives force close with Logcat
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
at android.app.Activity.startActivityForResult(Activity.java:2827)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
at android.app.Activity.startActivity(Activity.java:2933)
at com.google.android.gms.internal.e$2.onClick(Unknown Source)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Also when I UN-comment last line map.getMinZoomLevel(); , I get null pointer exception on the line.
Check if you have enabled offline work for gradle: Goto File > Settings > Gradle
Deselect Offline Work if its checked.
Then confirm if you have latest version of google services mentioned as dependencies in project level build.gradle:
classpath 'com.google.gms:google-services:2.1.0'
You can find latest version here: https://jcenter.bintray.com/com/android/tools/build/gradle/
Clean and build the project after gradle sync completes.
ouThese steps solved a similar issue I'd with Google Maps and also solved the first error you mentioned Signature Not Valid
If your device runs on Android M, you may want to verify your code for location access following this answer.
I was also getting same exception and I fixed it.
Note: I am working on google analytics and was getting this exception. But my app was not crashing I was getting this in Logs. you can also try this solution.
add this in project level gradle file.
classpath 'com.google.gms:google-services:2.1.0'
and this one for module level gradle file.
compile 'com.google.android.gms:play-services:8.4.0'
and move `below plugin at the end of file (at last line) of module level gradle file.
apply plugin: 'com.google.gms.google-services'