I'm getting a nullPointerException when I try to access my ActionBar
getActionBar().setDisplayHomeAsUpEnabled(true);
my recipientsActivity is this
package com.ahmetyuva.ribbit;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import com.parse.ParseRelation;
import com.parse.ParseUser;
import java.util.List;
public class RecipientsActivity extends ListActivity{
public static final String TAG = RecipientsActivity.class.getSimpleName();
protected List<ParseUser> mFriends;
protected ParseRelation<ParseUser> mFriendsRelation;
protected ParseUser mCurrentUser;
protected MenuItem mSendMenuItem;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipients);
getActionBar().setDisplayHomeAsUpEnabled(true);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
#Override
public void onResume() {
super.onResume();
mCurrentUser = ParseUser.getCurrentUser();
mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
ParseQuery<ParseUser> query = mFriendsRelation.getQuery();
query.addAscendingOrder(ParseConstants.KEY_USERNAME);
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> friends, ParseException e) {
if(e == null) {
mFriends = friends;
String[] usernames = new String[mFriends.size()];
int i = 0;
for (ParseUser user : mFriends) {
usernames[i] = user.getUsername();
i++;
} ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getListView().getContext(),
android.R.layout.simple_list_item_checked,
usernames);
setListAdapter(adapter);
}
else{
Log.e(TAG, e.getMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(RecipientsActivity.this);
builder.setMessage(e.getMessage())
.setTitle(R.string.error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_recipients, menu);
mSendMenuItem = menu.getItem(0);
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.
switch (item.getItemId()){
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.action_send:
return true;
}
/* int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
*/
return super.onOptionsItemSelected(item);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
if (l.getCheckedItemCount() > 0) {
mSendMenuItem.setVisible(true);
} else {
mSendMenuItem.setVisible(false);
}
}
}
my error log is here
04-13 11:19:05.148 1956-1956/? E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ahmetyuva.ribbit/com.ahmetyuva.ribbit.RecipientsActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) 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:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.ahmetyuva.ribbit.RecipientsActivity.onCreate(RecipientsActivity.java:40) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) 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:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method)
menu_recipients xml is here
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.ahmetyuva.ribbit.RecipientsActivity">
<item android:id="#+id/action_send"
android:title="Send"
android:orderInCategory="100"
app:showAsAction="always"
android:visible="true"
android:icon="#drawable/ic_action_send_now"
/>
</menu>
activity_recipients xml is here
<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="com.ahmetyuva.ribbit.RecipientsActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#android:id/list"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"/>
<TextView
android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/empty_recipients_list_message"
/>
</RelativeLayout>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ahmetyuva.ribbit" >
<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-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission
android:name="com.ahmetyuva.ribbit.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.ahmetyuva.ribbit.permission.C2D_MESSAGE" />
<application
android:name=".RibbitApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".SignUpActivity"
android:label="#string/title_activity_sign_up"
android:parentActivityName=".LoginActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".EditFriendsActivity"
android:label="#string/title_activity_edit_friends"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.ahmetyuva.ribbit.MainActivity" />
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. -->
<category android:name="com.ahmetyuva.ribbit" />
</intent-filter>
</receiver>
<activity
android:name=".RecipientsActivity"
android:label="#string/title_activity_recipients"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.ahmetyuva.ribbit.MainActivity" />
</activity>
</application>
</manifest>
Try to use
getSupportedActionBar() instead of getActionBar()
First of all, always do this to avoid this kind of error :
ActionBar ab = getSupportActionBar();
if (ab == null) {
Log.d("test", "ab null");
}
else {
Log.d("test", "ab not null");
ab.setDisplayHomeAsUpEnabled(true);
}
Then, what is in the logcat with the tag "test" ?
Make sure that you actually have an ActionBar, if for example, your theme is:
Theme.Light.NoActionBar, you won't have an action bar.
So, make sure your theme has and Actionbar
EDIT:
Try with the following theme:
<style name="AppTheme" parent="Theme.AppCompat">
If that doesn't work, You should consider changing to fragments, as suggested in this SO Answer
For both activities,
in your onCreate the next line after setContentView( ... )
add the following :
getActionBar().setDisplayHomeAsUpEnabled(true);
in the manifest for both activities add
android:theme="#android:style/Theme.Holo.Light"
in the tag directly after
android:screenOrientation="portrait"
Related
App launches normally. When I try to minimize it and reopen through the recent apps history, again it works fine. But when I minimize and try to re open it with the app icon, it crashes.
MainActivity.java
public class MainActivity extends AppCompatActivity implements ResetPasswordDialog.Listener {
public static final String TAG = MainActivity.class.getSimpleName();
private LoginFragment mLoginFragment;
private ResetPasswordDialog mResetPasswordDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
loadFragment();
}
}
private void loadFragment(){
if (mLoginFragment == null) {
mLoginFragment = new LoginFragment();
}
getFragmentManager().beginTransaction().replace(R.id.fragmentFrame,mLoginFragment,LoginFragment.TAG).commit();
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String data = intent.getData().getLastPathSegment();
Log.d(TAG, "onNewIntent: "+data);
mResetPasswordDialog = (ResetPasswordDialog) getFragmentManager().findFragmentByTag(ResetPasswordDialog.TAG);
if (mResetPasswordDialog != null)
mResetPasswordDialog.setToken(data);
}
#Override
public void onPasswordReset(String message) {
showSnackBarMessage(message);
}
private void showSnackBarMessage(String message) {
Snackbar.make(findViewById(R.id.activity_main),message, Snackbar.LENGTH_SHORT).show();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<!--singleTask => flag of launchMode -->
<application
android:name="io.github.froger.xinger.InstaMaterialApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="io.github.froger.xinger.ui.activity.MainActivity"
android:launchMode="singleTop"
android:theme="#style/AppTheme.LoginRegister"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="learn2crack"
android:scheme="http" />
</intent-filter>
</activity>
<activity
android:name="io.github.froger.xinger.ui.activity.DashboardActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="io.github.froger.xinger.ui.activity.CommentsActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.TransparentActivity" />
<activity
android:name="io.github.froger.xinger.ui.activity.UserProfileActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.TransparentActivity"
android:launchMode="singleInstance" />
<activity
android:name="io.github.froger.xinger.ui.activity.TakePhotoActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.TransparentActivity" />
<activity
android:name="io.github.froger.xinger.ui.activity.PublishActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"
android:windowSoftInputMode="stateHidden">
</activity>
</application>
Error
04-01 00:51:26.015 25525-25525/io.github.froger.instamaterial D/AndroidRuntime: Shutting down VM
04-01 00:51:26.016 25525-25525/io.github.froger.instamaterial E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.github.froger.instamaterial, PID: 25525
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
at io.github.froger.xinger.ui.activity.MainActivity.onNewIntent(MainActivity.java:44)
at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1245)
at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1257)
at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2804)
at android.app.ActivityThread.performNewIntents(ActivityThread.java:2816)
at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2825)
at android.app.ActivityThread.-wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1552)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
The stack trace clearly indicates that the call to intent.getData() at line 44 of your MainActivity is returning a null. You should check for the null, and not try to interrogate the Intent if it is null.
You could store string data in a static variable, and then check to see if it's null. If it's null use the static data. I know static variables are frowned upon and you should address the root problem, but this will fix your immediate problem.
static String yourStaticString;
...
String data;
if (intent.getData()==NULL)
{
data = yourStaticString;
}
else
{
if (intent.getData().getLastPathSegment()!=NULL)
{
data = intent.getData().getLastPathSegment();
yourStaticString = data;
} else return;
}
The android app I had created is not crashing in the emulator nor the phone I am using but shows some exceptions like java.lang.NoSuchMethodError: in the logcat, but when I transfer the apk file to other devices then 80% of the users reported the app got crashed while just opening the app or opening an activity with on the app.
This is driving me crazy I tested this on different emulators and none of them got crashed.I just couldn't understand what the problem is please help.
MY AndroidMaifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androgeekzz.pokemongo_bestguidetipsandtricks">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Basics" />
<activity android:name=".Tips" />
<activity android:name=".Tricks" />
<activity android:name=".Bas_What" />
<activity android:name=".Bas_Downld" />
<activity android:name=".Bas_Pikatchu" />
<activity android:name=".Bas_PokeCapture" />
<activity android:name=".Bas_LVI5" />
<activity android:name=".Bas_GainXP_LVL_Up" />
<activity android:name=".Bas_All_Iteams" />
<activity android:name=".Bas_All_Places" />
<activity android:name=".Advanced" />
<activity android:name=".Adv_gainXP" />
<activity android:name=".Adv_1candies" />
<activity android:name=".Adv_2Evolution" />
<activity android:name=".Adv_3PowerUp" />
<activity android:name=".Adv_4FightAGym" />
<activity android:name=".Adv_5DefendGym" />
<activity android:name=".Adv_6LvlGym" />
<activity android:name=".Adv_7Type" />
<activity android:name=".Adv_8Egg" />
<activity android:name=".Tips_0Good" />
<activity android:name=".Tips_1Eevee" />
<activity android:name=".Tips_2EarnXP" />
<activity android:name=".Tips_3Find" />
<activity android:name=".Tips_4Nest" />
<activity android:name=".Adv_Nests" />
<activity android:name=".Resources"></activity>
</application>
Main Activity:
package com.androgeekzz.pokemongo_bestguidetipsandtricks;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends AppCompatActivity {
SharedPreferences prefs;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prefs = getSharedPreferences("myPrefs", MODE_PRIVATE);
int times = prefs.getInt("ok_clicked", 0);
if (times == 0) {
new AlertDialog.Builder(MainActivity.this).setTitle("Hi there user").setMessage("This app version right now is just 1.0 the later versions will be released soon with even more content,Images and in app video tutorials etc..and this app is completely ADD free so please do consider rating it. ").setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
prefs = getSharedPreferences("myPrefs", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("ok_clicked", 1);
editor.apply();
}
}).show();
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
public void basicsOnclick(View view) {
Intent i = new Intent(this, Basics.class);
startActivity(i);
}
public void advanceOnclick(View view) {
Intent i = new Intent(this, Advanced.class);
startActivity(i);
}
public void tipsOnclick(View view) {
Intent i = new Intent(this, Tips.class);
startActivity(i);
}
public void tricksOnclick(View view) {
Intent i = new Intent(this, Tricks.class);
startActivity(i);
}
public void resourceLinksOnclick(View view) {
Intent i = new Intent(this, Resources.class);
startActivity(i);
}
public void aboutOnclick(View view) {
new AlertDialog.Builder(MainActivity.this).setTitle("About").setMessage("App Name :Pokemon GO-Guide\nVersion :1.0 \nCreator :Prudhvi").setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).show();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
LogCat (It had not crashed for this log cat)-
at com.android.systemui.statusbar.SignalClusterView.apply(SignalClusterView.java:468)
at com.android.systemui.statusbar.policy.NetworkControllerImpl.refreshViews(NetworkControllerImpl.java:1986)
at com.android.systemui.statusbar.policy.NetworkControllerImpl.refreshViews(NetworkControllerImpl.java:1679)
at com.android.systemui.statusbar.policy.NetworkControllerImpl.onReceive(NetworkControllerImpl.java:643)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:895)
at android.os.Handler.handleCallback(Handler.java:810)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5529)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:114)
08-07 23:23:38.730 824-824/?
E/Xposed: java.lang.NoSuchMethodError: com.mediatek.systemui.ext.DefaultStatusBarPlugin#getDataNetworkTypeIconGemini(com.mediatek.systemui.ext.NetworkType,int)#exact
at de.robv.android.xposed.XposedHelpers.findMethodExact(XposedHelpers.java:170)
at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:131)
at com.ceco.lollipop.gravitybox.ModStatusBar$24.afterHookedMethod(ModStatusBar.java:1072)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:689)
at com.mediatek.systemui.ext.PluginFactory.getStatusBarPlugin(<Xposed>)
at com.android.systemui.statusbar.SignalClusterView.apply(SignalClusterView.java:401)
at com.android.systemui.statusbar.policy.NetworkControllerImpl.refreshViews(NetworkControllerImpl.java:1986)
at com.android.systemui.statusbar.policy.NetworkControllerImpl.refreshViews(NetworkControllerImpl.java:1679)
at com.android.systemui.statusbar.policy.NetworkControllerImpl.onReceive(NetworkControllerImpl.java:643)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:895)
at android.os.Handler.handleCallback(Handler.java:810)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5529)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:114)
08-07 23:23:38.731 824-824/?
E/Xposed: java.lang.NoSuchMethodError: com.mediatek.systemui.ext.DefaultStatusBarPlugin#getDataNetworkTypeIconGemini(com.mediatek.systemui.ext.NetworkType,int)#exact
at de.robv.android.xposed.XposedHelpers.findMethodExact(XposedHelpers.java:170)
at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:131)
at com.ceco.lollipop.gravitybox.ModStatusBar$24.afterHookedMethod(ModStatusBar.java:1072)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:689)
at com.mediatek.systemui.ext.PluginFactory.getStatusBarPlugin(<Xposed>)
at com.android.systemui.statusbar.SignalClusterView.getNullIconIdGemini(SignalClusterView.java:557)
at com.android.systemui.statusbar.SignalClusterView.apply(SignalClusterView.java:468)
at com.android.systemui.statusbar.policy.NetworkControllerImpl.refreshViews(NetworkControllerImpl.java:1986)
at com.android.systemui.statusbar.policy.NetworkControllerImpl.refreshViews(NetworkControllerImpl.java:1679)
at com.android.systemui.statusbar.policy.NetworkControllerImpl.onReceive(NetworkControllerImpl.java:643)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:895)
at android.os.Handler.handleCallback(Handler.java:810)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5529)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:114)
i have a application that allows me to alter/add/delete from mysql database. The application opens up fine when i run it but when i try clicking on the 'ViewAllEmployee' button i keep getting a error saying it cannot find explicit activity class. I have looked online and tried all solutions that have worked for people with this problem before. I have added it into my AndroidManifest too but it still doesn't want to work. Can anyone help? Literally been trying to fix this for hours!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="#string/app_name" >
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"
/>
</activity>
</application>
</manifest>
MainActivity.java -- Error showing when onClick for 'ViewAllEmployee' is clicked:
package com.example.assignment.androidassignment;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.HashMap;
public class MainActivity extends Activity implements View.OnClickListener{
//Defining views
private EditText editTextLatitude;
private EditText editTextLongitude;
private EditText editTextTimeInserted;
private Button buttonAdd;
private Button buttonView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Initializing views
editTextLatitude = (EditText) findViewById(R.id.editTextLat);
editTextLongitude = (EditText) findViewById(R.id.editTextLon);
editTextTimeInserted = (EditText) findViewById(R.id.editTextTimeInserted);
buttonAdd = (Button) findViewById(R.id.buttonAdd);
buttonView = (Button) findViewById(R.id.buttonView);
//Setting listeners to button
buttonAdd.setOnClickListener(this);
buttonView.setOnClickListener(this);
}
//Adding an employee
private void addEmployee(){
final String lat = editTextLatitude.getText().toString().trim();
final String lon = editTextLongitude.getText().toString().trim();
final String timeInserted = editTextTimeInserted.getText().toString().trim();
class AddEmployee extends AsyncTask<Void,Void,String>{
ProgressDialog loading;
#Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(MainActivity.this,"Adding...","Wait...",false,false);
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(MainActivity.this,s,Toast.LENGTH_LONG).show();
}
#Override
protected String doInBackground(Void... v) {
HashMap<String,String> params = new HashMap<>();
params.put(Config.KEY_LAT,lat);
params.put(Config.KEY_LON,lon);
params.put(Config.KEY_TIMEINSERTED,timeInserted);
RequestHandler rh = new RequestHandler();
String res = rh.sendPostRequest(Config.URL_ADD, params);
return res;
}
}
AddEmployee ae = new AddEmployee();
ae.execute();
}
#Override
public void onClick(View v) {
if(v == buttonAdd){
addEmployee();
}
if(v == buttonView){
startActivity(new Intent(this,com.example.assignment.androidassignment.ViewAllEmployee.class));
}
}
}
LogCat errors:
12-09 03:34:46.634 2489-2489/? E/AndroidRuntime: FATAL EXCEPTION: main
=Process: com.example.assignment.androidassignment, PID: 2489
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.assignment.androidassignment/com.example.assignment.androidassignment.ViewAllEmployee}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at android.app.Activity.startActivity(Activity.java:3627)
at android.app.Activity.startActivity(Activity.java:3595)
at com.example.assignment.androidassignment.MainActivity.onClick(MainActivity.java:91)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
You are nesting <activity> tags in your Manifest. Take them apart:
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"/>
from
if(v == buttonView){
startActivity(new Intent(this,com.example.assignment.androidassignment.ViewAllEmployee.class));
}
to
if(v == buttonView){
startActivity(new Intent(MainActivity.this,ViewAllEmployee.class));
}
from
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="#string/app_name" >
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"
/>
</activity>
</application>
</manifest>
to
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="#string/app_name" >
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"
/>
</application>
</manifest>
please change the above and this is happening because of nesting of activity inside manifest
I have an app that worked up to just recently.
The error in the Google play store is as follows:
java.lang.RuntimeException: Unable to instantiate application org.marsfirst.mars_app: java.lang.ClassNotFoundException: Didn't find class "org.marsfirst.mars_app" on path: DexPathList[[zip file "/data/app/org.marsfirst.mars_app-2.apk"],nativeLibraryDirectories=[/data/app-lib/org.marsfirst.mars_app-2, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703)
at android.app.ActivityThread.access$1600(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.marsfirst.mars_app" on path: DexPathList[[zip file "/data/app/org.marsfirst.mars_app-2.apk"],nativeLibraryDirectories=[/data/app-lib/org.marsfirst.mars_app-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:981)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
MainActivity:
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;//this gives me a warning that states its unused but it has been used in the past
import android.support.v4.app.Fragment;//this gives me a warning that states its unused but it has been used in the past
import android.app.Activity;//this gives me a warning that states its unused but it has been used in the past
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.LogInCallback;
public class MainActivity extends ActionBarActivity {
private String un, pw;
public TextView username;
public EditText pass;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (TextView) findViewById(R.id.editloginusername);
pass = (EditText) findViewById(R.id.editpass);
Button login = (Button) findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
un = username.getText().toString();
pw = pass.getText().toString();
ParseUser.logInInBackground(un, pw, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
new CallMainPage().execute();
} else {
// username.setText("");
pass.setText("");
makeToast("User name or password not recognized.");
}
}
});
}
});
Button signup = (Button) findViewById(R.id.signup);
signup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new CallSignup().execute();
}
});
}
#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);
}
public class CallSignup extends AsyncTask<Void, Void, String> {
protected String doInBackground(Void... urls) {
Intent intent = new Intent(MainActivity.this, Signup.class);
MainActivity.this.startActivity(intent);
return "";
}
}
public class CallMainPage extends AsyncTask<Void, Void, String> {
protected String doInBackground(Void... urls) {
Intent intent = new Intent(MainActivity.this, MainPage.class);
MainActivity.this.startActivity(intent);
return "";
}
}
public void makeToast(String text) {
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(getApplicationContext(), text, duration);
toast.show();
}
}
My manifest:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="org.marsfirst.mars_app"
android:protectionLevel="signature" />
<uses-permission android:name="org.marsfirst.mars_app" />
<application
android:name="org.marsfirst.mars_app"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="org.marsfirst.mars_app.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>
<activity
android:name=".Signup"
android:label="#string/signup"
android:parentActivityName=".MainActivity" >
<intent-filter />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".MainPage"
android:label="Main Page" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".Webpage"
android:label="Website"
android:parentActivityName=".MainPage" >
<intent-filter />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainPage" />
</activity>
<activity
android:name=".TeamNews"
android:label="Team News"
android:parentActivityName="org.marsfirst.mars_app.MainPage" >
<intent-filter />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.marsfirst.mars_app.MainPage" />
</activity>
<activity
android:name=".OprPage"
android:label="OPR Page"
android:parentActivityName="org.marsfirst.mars_app.MainPage" >
<intent-filter />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.marsfirst.mars_app.MainPage" />
</activity>
<activity
android:name="org.marsfirst.mars_app.MechPage"
android:label="Mechanical Page"
android:parentActivityName="org.marsfirst.mars_app.MainPage" >
<intent-filter />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainPage" />
</activity>
<activity
android:name=".DriveNews"
android:label="Drive News"
android:parentActivityName=".MainPage" >
<intent-filter />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainPage" />
</activity>
<activity
android:name=".ProgramingPage"
android:label="Programming Page"
android:parentActivityName=".MainPage" >
<intent-filter />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainPage" />
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="org.marsfirst.mars_app" />
</intent-filter>
</receiver>
</application>
</manifest>
File Explorer
http://imgur.com/UCwiJqP
I am unsure if it is a Code error or not, due to my research I believe it is a buildpath error however everything I have tried seems to fail please help
I will post any Additional screen shots or code that is needed. In attempt to fix the problem one "fix" I found was to change every thing to android:name=".DriveNews" instead of android:name=org.marsfirst.mars_app.DriveNews which was what it was originally
Thank you for any help you may be able to give.
Disclaimer: I am a noob in android development.
I think you would like to verify the following permission tags:
<permission
android:name="org.marsfirst.mars_app"
android:protectionLevel="signature" />
<uses-permission android:name="org.marsfirst.mars_app" />
The classloader is not able to find a class org.marsfirst.mars_app. From your code it seems like mars_app is a package. Same for android:name in application name.
Change
android:name="org.marsfirst.mars_app"
to
android:name="org.marsfirst.mars_app.YourApplicationClass"
where YourApplicationClass is the class that is extending Application class. If you don't have any such class just remove the name attribute.
According to official documentation of the application tag the name attribute should be
The fully qualified name of an Application subclass implemented for the application. When the application process is started, this class is instantiated before any of the application's components.
The subclass is optional; most applications won't need one. In the absence of a subclass, Android uses an instance of the base Application class.
can show you file explore?
e.g.
Right click the project -> Build Path -> Configure Build Path -> Order and Export and check the libraries that you use in your project.
Do you use proguard in your application?
if yes: check this from developer.google site. It may help you
The default proguard.cfg file tries to cover general cases, but you might encounter exceptions such as ClassNotFoundException, which happens when ProGuard strips away an entire class that your application calls.
You can fix errors when ProGuard strips away your code by adding a -keep line in the proguard.cfg file. For example:
-keep public class < MyClass >
Strangely map=frag.getMap(); does not throw nullpointerexception , but still the map is always null!
The same situation with or without running the handler.
I see the map (world map) but cannot do anything with the map object.
PRINT SCREE with project properties : http://i.stack.imgur.com/BGB65.jpg
Please have a look at the code and please advice where I am wrong.
package com.bestsiteeditor.bestwirelessdeals;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
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.app.FragmentTransaction;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
public class Settings extends FragmentActivity{
LinearLayout submenu;
GoogleMap map;
LinearLayout mainLayout;
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
submenu =(LinearLayout) findViewById(R.id.submenu);
SubMenu sm = new SubMenu(this,submenu);
sm.getButtons();
mainLayout =(LinearLayout) findViewById(R.id.temp);
final Handler handler = new Handler();
handler.postDelayed(new Runnable(){
#Override
public void run() {
MapFragment frag = MapFragment.newInstance();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(mainLayout.getId(), frag);
fragmentTransaction.commit();
map=frag.getMap();
System.out.println("THEMAAP "+map);
if(map != null) {
System.out.println("THEMAAP NOT NULL "+map);
}else{handler.postDelayed(this, 500);}
}
}, 500);
}
#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;
}
public boolean onOptionsItemSelected(MenuItem item) {
return ActionBar.HandleMenu(this, item.getItemId());
}
}
and the is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bestsiteeditor.bestwirelessdeals"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<permission
android:name="com.suntrainer.suntrainer.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.suntrainer.suntrainer.permission.MAPS_RECEIVE" />
<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="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" >
</uses-permission>
<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/MyAppActionBarTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDJuwvAd8Zzqasdasdadasdasd" />
<activity
android:name="com.bestsiteeditor.bestwirelessdeals.MainActivity"
android:label="#string/app_name"
android:screenOrientation="sensorPortrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.bestsiteeditor.bestwirelessdeals.Locations"
android:label="#string/app_name"
android:screenOrientation="sensorPortrait" >
<intent-filter>
<action android:name="android.intent.action.LOCATIONS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.bestsiteeditor.bestwirelessdeals.Settings"
android:label="#string/app_name"
android:screenOrientation="sensorPortrait" >
<intent-filter>
<action android:name="android.intent.action.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.bestsiteeditor.bestwirelessdeals.WatchList"
android:label="#string/app_name"
android:screenOrientation="sensorPortrait" >
<intent-filter>
<action android:name="android.intent.action.WATCHLIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.bestsiteeditor.bestwirelessdeals.Profile"
android:label="#string/app_name"
android:screenOrientation="sensorPortrait" >
<intent-filter>
<action android:name="android.intent.action.PROFILE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
You have
android:minSdkVersion="12"
So you need to change
public class Settings extends FragmentActivity{
to
public class Settings extends Activity{
Also it is better you check the availability of google play services before initializing
google map object.
From the docs
public final GoogleMap getMap ()
Gets the underlying GoogleMap that is tied to the view wrapped by this
fragment.
Returns the GoogleMap. Null if the view of the fragment is not yet
ready. This can happen if the fragment lifecyle have not gone through
onCreateView(LayoutInflater, ViewGroup, Bundle) yet. This can also
happen if Google Play services is not available. If Google Play
services becomes available afterwards and the fragment have gone
through onCreateView(LayoutInflater, ViewGroup, Bundle), calling this
method again will initialize and return the GoogleMap.
Edit:
Missing a meta tag in the applciation tag of manifest fie.
Pls make sure you followed all the steps #
https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Simply waiting 500 ms after the fragment transaction solved the issue.
Instead of Thread ,handler could be also implemented also.
fragmentTransaction.commit();
Thread thread= new Thread(){
#Override
public void run(){ try { synchronized(this){wait(500);}}catch(InterruptedException ex){ }
map=frag.getMap();
System.out.println("MAP OK"+frag.getMap());
}
};
thread.start();