Android Google Maps Fragment crashes - android

I have embedded Google Maps V2 in my App, as the Google Tutorial says.
I get the following errors, when switching to the map fragment.
03-08 12:52:01.600: E/AndroidRuntime(30314): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2105)
03-08 12:52:01.600: E/AndroidRuntime(30314): FATAL EXCEPTION: main
03-08 12:52:01.600: E/AndroidRuntime(30314): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{de.arvidg.exampleactionbartabs/de.arvidg.exampleactionbartabs.StartActivity}:
java.lang.ClassNotFoundException: de.arvidg.exampleactionbartabs.StartActivity
Heres the source code
package de.arvidg.exampleactionbartabs;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.maps.MapActivity;
import data.Device;
import data.Mission;
import de.arvidg.exampleactionbartabs.R;
import logic.FetchData;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
public class MapFrag extends MapFragment {
protected FetchData thread;
protected Device device;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View lView = inflater.inflate(R.layout.map, container,
false);
return lView;
}
public void setDumb() {
}
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
}
<?xml version="1.0" encoding="utf-8"?>
<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"/>
My Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.arvidg.exampleactionbartabs"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<permission
android:name="de.arvidg.exampleactionbartabs.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="de.arvidg.exampleactionbartabs.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" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".StartActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapFrag"
android:label="Map"
android:theme="#android:style/Theme.Holo" >
<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="removed" />
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>

change
android:name="com.google.android.gms.maps.MapFragment"/>
to
android:name="com.google.android.gms.maps.SupportMapFragment"/> in activity_main.xml
and change
public class MainActivity extends Activity
to
public class MainActivity extends FragmentActivity in MainActivity.java
these two fixes worked for me.

Related

"Error: cannot find symbol class app"

I have external package class (my custom library), which I want to include in the project. It uses Activity, but shows error as you see.
If I place this command in main project class, it works well... What to do?
Here is the code:
package com.__MyDefaultLibrary;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.*;
import java.io.File;
import java.util.Calendar;
//
import android.app.Activity;
import com.oceanesa.samplevideorecorder.R;
public class __MyDefaultFunctions{
public android.app.Activity actv1 = android.app.Activity;
public void Initt(){
PreferenceManager.setDefaultValues(actv1.getBaseContext(), R.xml.mypreferences, false);
}
// ========== MY CUSTOM LIBRARY =============//
//button find
public Button fvb(int id) {
return (Button) actv1.findViewById(id);
}
//message show
public void msg(String text) {
Toast.makeText(actv1.getApplicationContext(), text, Toast.LENGTH_LONG).show();
}
public View.OnClickListener optionsListener2 = new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(actv1.getBaseContext(), com.__MyDefaultLibrary.__MyDefaultPreferencesInit1.class);
actv1.startActivity(i);
}
};
}
And AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.oceanesa.samplevideorecorder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:theme="#style/AppTheme"
>
<activity
android:name="com.oceanesa.samplevideorecorder.VideoCaptureExample"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.__MyDefaultLibrary.__MyDefaultPreferencesInit1"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Update Answer just passing context to class
public class MyClass {
private static Context mContext;
private static Activity mActivity;
public MyClass(Context c) {
mContext= c;
}
public MyClass(Activity act) {
mActivity= act;
}
public static void showToastMethod() {
// then passing context or activity to
Toast.makeText(mContext, "mymessage ", Toast.LENGTH_SHORT).show();
// or Toast.makeText(mActivity, "mymessage ", Toast.LENGTH_SHORT).show();
}
}
Finally I got it working with the help of topic: How to display a Toast message in from a class that doesn't extend Activity
Problem was in my code. There was no need to call andorid.app at all. I didnt pass Activity to my external file, from where I couldnt call anything..
I had to pass activity like this (from main project file):
public MyExternalClass myEx = new MyExternalClass(Activity);
and needed some modifications...

android crashes after using setMyLocationEnabled on mapcallback on actual device

i'm trying to use google map v2 on my android application. everything works on emulator but if i use setMyLocationEnabled(true) on my map it will crash on actual device.
the device is lg x-cam using android v6.
here is my manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.latest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="24" />
<permission
android:name="com.example.latest.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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-permission android:name="com.example.latest.permission.MAPS_RECEIVE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light"
>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="my valid api key is here"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".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>
</manifest>
my MainActivity :
package com.example.latest;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
SupportMapFragment mapFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap map) {
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.setMyLocationEnabled(true);
map.getUiSettings().setZoomControlsEnabled(true);
map.getUiSettings().setCompassEnabled(true);
map.getUiSettings().setZoomGesturesEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(true);
map.getUiSettings().setMapToolbarEnabled(true);
}
}
my 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
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
how can i fix this ?

My app is Always crashing: Unable to instantiate activity

Help! when i run my app it will crash and give me that
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.spinhaxo.consoleapp/com.spinhaxo.consoleapp.Console}:
java.lang.ClassNotFoundException: Didn't find class
"com.spinhaxo.consoleapp.Console" on path: /data/app/com.spinhaxo.consoleapp-1.apk
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.spinhaxo.consoleapp.Console" on path: /data/app/com.spinhaxo.consoleapp-1.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
I dont know what to do :( on an Virtual device on my Pc its working fine, but on my mobile phone and Tablet its Crashing...
My Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spinhaxo.consoleapp"
android:versionCode="5"
android:versionName="2.1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".Console"
>
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.startapp.android.publish.list3d.List3DActivity"
android:theme="#android:style/Theme" />
<activity android:name="com.startapp.android.publish.AppWallActivity"
android:theme="#android:style/Theme.Translucent"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:icon="#drawable/frages"
android:label="BatteryInfo"
android:name=".BatteryInfo"
android:theme="#android:style/Theme.Dialog">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The onCreate of my MainActivity(Consolejar):
package com.spinhaxo.console;
import android.app.*;
import android.view.*;
import android.widget.TextView;
import android.content.DialogInterface;
import android.widget.Toast;
import android.view.Menu;
import android.net.wifi.*;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Environment;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.view.View;
import android.widget.EditText;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import com.spinhaxo.consoleapp.R;
import com.startapp.android.publish.StartAppAd;
import com.startapp.android.publish.StartAppAd.AdMode;
import com.startapp.android.publish.StartAppSDK;
import com.startapp.android.publish.splash.SplashConfig;
import com.startapp.*;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.util.Log;
import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.Fields;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.MapBuilder;
import com.google.analytics.tracking.android.Tracker;
public class Console extends Activity
{
private static Context context;
EditText console;
String folderPath;
File folder;
TextView output, stat_set, stat_devset, Zwischenablage_set;
private WifiManager wifiManager;
TextView invText, invtext2, invtext3, invtext4;
public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
private ProgressDialog mProgressDialog;
String FILENAME = "Output.console";
String FILENAMEset = "Set_Autosave.set";
String FILENAMEdevset = "Set_DeveloperView.set";
String FileDownload = "Minecraft Pe.apk";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
StartAppSDK.init(this, "108083436", "208381016", false);
setContentView(R.layout.main);
StartAppAd.showSplash(this, savedInstanceState,
new SplashConfig()
.setTheme(SplashConfig.Theme.OCEAN)
.setCustomScreen(R.layout.splash)
);
Zwischenablage_set = (TextView) findViewById(R.id.zwischenablage);
stat_set = (TextView) findViewById(R.id.stat_set);
stat_devset = (TextView) findViewById(R.id.stat_devset);
console = (EditText) findViewById(R.id.Console);
output = (TextView) findViewById(R.id.output);
invText = (TextView) findViewById(R.id.InvisibleText);
invtext2 = (TextView) findViewById(R.id.InvisibleText2);
invtext3 = (TextView) findViewById(R.id.InvisibleText3);
GoogleAnalytics.getInstance(this).getTracker("UA-53616112-1");
Tracker tracker = GoogleAnalytics.getInstance(this).getTracker("UA-53616112-1");
HashMap<String, String> hitParameters = new HashMap<String, String>();
hitParameters.put(Fields.HIT_TYPE, "appview");
hitParameters.put(Fields.SCREEN_NAME, "Home Screen");
tracker.send(hitParameters);
loaddevset(invtext3);
checkdevset();
createDir();
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
this.registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
String read_data = null;
try {
File myFile = new File("/sdcard/Console/"+FILENAME);
FileInputStream fis = new FileInputStream(myFile);
byte[] dataArray = new byte[fis.available()];
while (fis.read(dataArray) != -1) {
read_data = new String(dataArray);
}
fis.close();
output.setText(read_data);
} catch (FileNotFoundException e) {
Toastmessage("Filenotfound");
e.printStackTrace();
} catch (IOException e) {
Toastmessage("IOException");
e.printStackTrace();
}
String vorheriges = output.getText().toString();
output.setText(vorheriges +"\n[System] Starting Console...\n[System] fetching data... \n[System] Console ready to work!");
loadset(invtext2);
I hope someone can help...
You are using different packages in your manifest and your Activity. Also you have multiple activities that are set as launchers, so remove
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
from the one that's not your main activity.
Here's an example manifest that should work:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spinhaxo.console"
android:versionCode="5"
android:versionName="2.1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".Console">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.startapp.android.publish.list3d.List3DActivity"
android:theme="#android:style/Theme" />
<activity android:name="com.startapp.android.publish.AppWallActivity"
android:theme="#android:style/Theme.Translucent"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:icon="#drawable/frages"
android:label="BatteryInfo"
android:name=".BatteryInfo"
android:theme="#android:style/Theme.Dialog">
</activity>
</application>

How to display map using fragment

MainActivity.java
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.app.Activity;
public class MainActivity extends Activity
{
static final LatLng latlng = new LatLng(13 , 80);
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
Marker mar = googleMap.addMarker(new MarkerOptions().
position(latlng).title("Google Map"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<permission
android:name="com.example.mapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapp.permission.MAPS_RECEIVE" />
<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_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-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<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="AIzaSyDXYlSDkAo4z45GwjRkE2qiNMQoFeQCDUY" />
</application>
</manifest>
Am new to android .i dont know how to display map using fragment.this is my code.i dont get map.my program is unfortunately stopped.and i got error in logcat:No Activity Found to handle.can anyone help me please
You need to activate Google Map API V2 from your google developer console, from there you need to generate map api key, then you need to give that key to map.
Additionally, you need to declare some classes in Android Manifect file, after that you can see map. Its a process and you must need to follow it.
Just visit some good sites like :https://developers.google.com/maps/documentation/android/start
Try this......
<fragment
android:id="#+id/map"
android:class="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Instead of..
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Here is the complete code to show google maps v2..
activity_main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.movingmarkergooglemaps.MainActivity"
tools:ignore="MergeRootFrame" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
MainActivity.java
package com.example.movingmarkergooglemaps;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity{
GoogleMap Mmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
gps=new GPSTracker(MainActivity.this);
Mmap=((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.movingmarkergooglemaps.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.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="**Replace with your key**" />
</application>
Dont forget add google-play-services_lib

Android SecurityException ACCESS_WIFI_STATE

I am building an Android app that uses wifi.
I have properly declared these uses permissions in the manifest, however for some reason the app is throwing a SecurityException that causes the app to force-close.
I traced the cause of the security exception in LogCat to the system saying it doesn't have the access_wifi_state permission. This is strange and confusing to me because I have already declared it in the manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.wifi"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="ACCESS_WIFI_STATE" />
<uses-permission android:name="CHANGE_WIFI_STATE" />
<uses-feature android:name="android.hardware.wifi" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="android.wifi.AndroidWiFiActivity"
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>
</manifest>
And here is the code that causes the exception:
package android.wifi;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.wifi.R;
public class AndroidWiFiActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.textbox);
tv.setText("ABC 123");
WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if(wifiMgr.isWifiEnabled())
{
tv.append("Wifi is enabled");
}
else
{
tv.append("Wifi is disabled");
}
}
}
Any help is greatly appreciated. Thanks.
The permission is:
android.permission.ACCESS_WIFI_STATE

Categories

Resources