solve the error:: revoked permission android.permission.CALL_PHONE - java

How to solve this error:
revoked permission android.permission.CALL_PHONE
This is my Java code:
public class DetailContactActivity extends AppCompatActivity implements
OnClickListener {
private TextView phone, email;
private int id;
private ImageView call, btnEmail;
private ContactDB db;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_contact);
db = ContactDB.getInstance(this);
phone = (TextView) findViewById(R.id.txt_phone_number);
email = (TextView) findViewById(R.id.txt_email);
call = (ImageView) findViewById(R.id.btn_call);
btnEmail = (ImageView) findViewById(R.id.btn_email);
Bundle b = getIntent().getExtras();
if (b != null)
{
id = b.getInt("id");
phone.setText(b.getString("phone"));
getSupportActionBar().setTitle(b.getString("nama"));
if (!b.getString("email").equals("null"))
{
email.setText(b.getString("email"));
} else
{
email.setText("");
}
}
call.setOnClickListener(this);
btnEmail.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.detail_contact, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.action_edit:
Bundle b = new Bundle();
b.putInt("id", id);
b.putString("name", getSupportActionBar().getTitle().toString());
b.putString("email", email.getText().toString());
b.putString("phone", phone.getText().toString());
Intent i = new Intent(this, EditActivity.class);
i.putExtras(b);
startActivity(i);
finish();
return true;
case R.id.action_delete:
showSettingsAlert();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public void onClick(View v)
{
if (v == btnEmail)
{
if (!email.getText().toString().equals(""))
{
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto", email.getText().toString(),
null));
startActivity(Intent
.createChooser(emailIntent, "Send email..."));
}
} else if (v == call)
{
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phone.getText().toString()));
startActivity(callIntent);
//Uri call = Uri.parse("tel:" + phone.getText().toString());
//Intent surf = new Intent(Intent.ACTION_CALL, call);
//startActivity(surf);
}
}
private void showSettingsAlert()
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Delete");
alert.setMessage("Contact akan dihapus");
alert.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which)
{
db.deleteContact(id);
startActivity(new Intent(DetailContactActivity.this,
MainActivity.class));
finish();
}
});
alert.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which)
{
dialog.cancel();
}
});
alert.show();
}
#Override
public void onBackPressed()
{
super.onBackPressed();
startActivity(new Intent(DetailContactActivity.this, MainActivity.class));
finish();
}
Error:
01-02 02:05:41.493: D/AndroidRuntime(2927): Shutting down VM
01-02 02:05:41.493: D/AndroidRuntime(2927): --------- beginning of crash
01-02 02:05:41.616: E/AndroidRuntime(2927): FATAL EXCEPTION: main
01-02 02:05:41.616: E/AndroidRuntime(2927): Process: com.example.phonedb, PID: 2927
01-02 02:05:41.616: E/AndroidRuntime(2927): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{f5320c4 2927:com.example.phonedb/u0a69} (pid=2927, uid=10069) with revoked permission android.permission.CALL_PHONE
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.os.Parcel.readException(Parcel.java:1599)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.os.Parcel.readException(Parcel.java:1552)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2658)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.app.Activity.startActivityForResult(Activity.java:3917)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.app.Activity.startActivityForResult(Activity.java:3877)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:748)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.app.Activity.startActivity(Activity.java:4200)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.app.Activity.startActivity(Activity.java:4168)
01-02 02:05:41.616: E/AndroidRuntime(2927): at com.example.phonedb.DetailContactActivity.onClick(DetailContactActivity.java:127)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.view.View.performClick(View.java:5198)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.view.View$PerformClick.run(View.java:21147)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.os.Handler.handleCallback(Handler.java:739)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.os.Handler.dispatchMessage(Handler.java:95)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.os.Looper.loop(Looper.java:148)
01-02 02:05:41.616: E/AndroidRuntime(2927): at android.app.ActivityThread.main(ActivityThread.java:5417)
01-02 02:05:41.616: E/AndroidRuntime(2927): at java.lang.reflect.Method.invoke(Native Method)
01-02 02:05:41.616: E/AndroidRuntime(2927): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
01-02 02:05:41.616: E/AndroidRuntime(2927): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
here is the mainfest file,hope help::
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.phonedb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="23" />
<uses-permission-sdk-m android:name="android.permission.READ_CONTACTS" />
<uses-permission-sdk-m android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.phonedb.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=".AddContactActivity"
android:label="#string/title_activity_add_contact" >
</activity>
<activity
android:name="com.example.phonedb.DetailContactActivity"
android:label="#string/title_activity_detail_contact" >
</activity>
<activity
android:name=".EditActivity"
android:label="#string/title_activity_edit" >
</activity>
</application>

Switch to DIAL_PHONE, as that does not need a permission.
Just replace this line
Intent callIntent = new Intent(Intent.ACTION_CALL);
to
Intent callIntent = new Intent(Intent.ACTION_DIAL);

Android 6 (SDK 23) allows users to revoke permissions from an app. I guess, thats what happened here. Your app must be able to cope with this situation.
Have a look at the documentation for the details.
In particular:
If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.
Requsting permissions at runtime is described in detail here.

Add this permission in the manifest file:
<uses-permission android:name="android.permission.CALL_PHONE"/>
or else try this too.
<uses-permission android:name="android.permission.CALL_PRIVILEGED"/>
CALL_PRIVILEGED Allows an application to call any phone number,
including emergency numbers, without going through the Dialer user
interface for the user to confirm the call being placed.
Not for use by third-party applications.

i'm late. You must request permission dynamically.
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
more details at https://developer.android.com/training/permissions/requesting.html

Please change call_phone to dial phone. As you need to dial
the number.
Intent callIntent=new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:1234567890"));
startActivity(callIntent);

Related

cannot be cast to android.app.activity

When I run my application I get these errors, I'mm trying to make an app with RSS
Photo2.java
package com.otticafotobenzi.ofbshop;
import com.otticafotobenzi.R;
public class Photo2 extends ActionBarActivity implements View.OnClickListener {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private ViewFlipper mViewFlipper;
private Context mContext;
Button buttonCan;
Button buttonFuj;
Button buttonNik;
Button buttonOly;
Button buttonPana;
Button buttonPen;
Button buttonSon;
#SuppressWarnings("deprecation")
private final GestureDetector detector = new GestureDetector(
new SwipeGestureDetector());
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo2);
buttonCan = (Button) findViewById(R.id.buttonCan);
buttonFuj = (Button) findViewById(R.id.buttonFuj);
buttonNik = (Button) findViewById(R.id.buttonNik);
buttonOly = (Button) findViewById(R.id.buttonOly);
buttonPana = (Button) findViewById(R.id.buttonPana);
buttonPen = (Button) findViewById(R.id.buttonPen);
buttonSon = (Button) findViewById(R.id.buttonSon);
buttonCan.setOnClickListener(this);
buttonFuj.setOnClickListener(this);
buttonNik.setOnClickListener(this);
buttonOly.setOnClickListener(this);
buttonPana.setOnClickListener(this);
buttonPen.setOnClickListener(this);
buttonSon.setOnClickListener(this);
mContext = this;
mViewFlipper = (ViewFlipper) this.findViewById(R.id.view_flipper);
mViewFlipper.setOnTouchListener(new View.OnTouchListener() {
#SuppressLint("ClickableViewAccessibility")
#Override
public boolean onTouch(final View view, final MotionEvent event) {
detector.onTouchEvent(event);
return true;
}
});
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.buttonCan:
Intent loader_rssnik = new Intent(this, RssService.class); //problem here
startActivity(loader_rssnik);
break;
case R.id.buttonFuj:
Intent loader_rsscan = new Intent(this, RssService.class);
startActivity(loader_rsscan);
break;
case R.id.buttonNik:
Intent loader_rssfuji = new Intent(this, RssServiceNik.class);
startActivity(loader_rssfuji);
break;
case R.id.buttonOly:
Intent loader_rssoly = new Intent(this, RssService.class);
startActivity(loader_rssoly);
break;
case R.id.buttonPana:
Intent loader_rsspen = new Intent(this, RssService.class);
startActivity(loader_rsspen);
break;
case R.id.buttonPen:
Intent loader_rsspan = new Intent(this, RssService.class);
startActivity(loader_rsspan);
break;
case R.id.buttonSon:
Intent loader_rssson = new Intent(this, RssService.class);
startActivity(loader_rssson);
break;
}
}
class SwipeGestureDetector extends SimpleOnGestureListener {
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(
mContext, R.anim.left_in));
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(
mContext, R.anim.left_out));
mViewFlipper.showNext();
return true;
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(
mContext, R.anim.right_in));
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(
mContext, R.anim.right_out));
mViewFlipper.showPrevious();
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.photography, 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);
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.otticafotobenzi"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<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="android.permission.ACCESS_WIFI_STATE" />
<application android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".ofbshop.Loader"
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=".ofbshop.Home"
android:label="#string/title_activity_home">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ofbshop.Photography"
android:label="#string/title_activity_photography">
</activity>
<activity android:name=".ofbshop.Photo2"
android:label="#string/title_activity_photography">
</activity>
<activity android:name=".ofbshop.Optics"
android:label="#string/title_activity_optics">
</activity>
<activity android:name=".rss.Constants" />
<activity android:name=".rss.MainActivity" />
<activity android:name=".rss.RssAdapter" />
<activity android:name=".rss.RssFragment" />
<activity android:name=".rss.RssItem" />
<activity android:name=".rss.RssParser" />
<activity android:name=".rss.RssService" />
<activity android:name=".rss.RssServiceNik" />
</application>
RssService.java
package com.otticafotobenzi.rss;
public class RssService extends IntentService {
private static final String RSS_LINK = "http://feeds.feedburner.com/PhotoRumors?format=xml";
public static final String ITEMS = "items";
public static final String RECEIVER = "receiver";
public RssService() {
super("RssService");
}
#Override
protected void onHandleIntent(Intent intent) {
Log.d(Constants.TAG, "Service started");
List<RssItem> rssItems = null;
try {
RssParser parser = new RssParser();
rssItems = parser.parse(getInputStream(RSS_LINK));
} catch (XmlPullParserException e) {
Log.w(e.getMessage(), e);
} catch (IOException e) {
Log.w(e.getMessage(), e);
}
Bundle bundle = new Bundle();
bundle.putSerializable(ITEMS, (Serializable) rssItems);
ResultReceiver receiver = intent.getParcelableExtra(RECEIVER);
receiver.send(0, bundle);
}
public InputStream getInputStream(String link) {
try {
URL url = new URL(link);
return url.openConnection().getInputStream();
} catch (IOException e) {
Log.w(Constants.TAG, "Exception while retrieving the input stream",
e);
return null;
}
}
}
and this is the error in logcat with genymotion emulator android 4.4
02-12 17:04:50.552: E/AndroidRuntime(2044): FATAL EXCEPTION: main
02-12 17:04:50.552: E/AndroidRuntime(2044): Process: com.otticafotobenzi, PID: 2044
02-12 17:04:50.552: E/AndroidRuntime(2044): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.otticafotobenzi/com.otticafotobenzi.rss.RssService}: java.lang.ClassCastException: com.otticafotobenzi.rss.RssService cannot be cast to android.app.Activity
02-12 17:04:50.552: E/AndroidRuntime(2044): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
02-12 17:04:50.552: E/AndroidRuntime(2044): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
02-12 17:04:50.552: E/AndroidRuntime(2044): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-12 17:04:50.552: E/AndroidRuntime(2044): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-12 17:04:50.552: E/AndroidRuntime(2044): at android.os.Handler.dispatchMessage(Handler.java:102)
02-12 17:04:50.552: E/AndroidRuntime(2044): at android.os.Looper.loop(Looper.java:136)
02-12 17:04:50.552: E/AndroidRuntime(2044): at android.app.ActivityThread.main(ActivityThread.java:5001)
02-12 17:04:50.552: E/AndroidRuntime(2044): at java.lang.reflect.Method.invokeNative(Native Method)
02-12 17:04:50.552: E/AndroidRuntime(2044): at java.lang.reflect.Method.invoke(Method.java:515)
02-12 17:04:50.552: E/AndroidRuntime(2044): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
02-12 17:04:50.552: E/AndroidRuntime(2044): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
02-12 17:04:50.552: E/AndroidRuntime(2044): at dalvik.system.NativeStart.main(Native Method)
02-12 17:04:50.552: E/AndroidRuntime(2044): Caused by: java.lang.ClassCastException: com.otticafotobenzi.rss.RssService cannot be cast to android.app.Activity
02-12 17:04:50.552: E/AndroidRuntime(2044): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
02-12 17:04:50.552: E/AndroidRuntime(2044): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
02-12 17:04:50.552: E/AndroidRuntime(2044): ... 11 more
Change
<activity android:name=".rss.RssService" />
to
<service android:name=".rss.RssService" />
And if you want to start service use method
startService(Intent);
by
startActivity(Intent);
You need to call a different method for services:
Intent loader_rssnik = new Intent(this, RssService.class);
startService(loader_rssfuji);

Unable to find explicit activity class {}; have you declared this activity in your AndroidManifest.xml

I'm trying unzip some files in background, so I use IntentService like in google's tutorial. My service class declared in AndroidManifest like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.osmdroid">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:configChanges="orientation|screenSize|keyboardHidden"
android:hardwareAccelerated="true"
android:icon="#drawable/ecn_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MapActivity"
android:icon="#drawable/ecn_icon"
android:label="test" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="#string/title_activity_settings">
</activity>
<service
android:name=".UnZipService"
android:exported="false"/>
</application>
In activity, I have
IntentFilter intentFilter = new IntentFilter(DownloadManager
.ACTION_DOWNLOAD_COMPLETE);
receiverDownloadComplete = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
long reference = intent.getLongExtra(DownloadManager
.EXTRA_DOWNLOAD_ID, -1);
if (myDownloadReference == reference) {
...
switch (status) {
case DownloadManager.STATUS_SUCCESSFUL:
Intent mServiceIntent = new Intent(context, UnZipService.class);
mServiceIntent.setData(Uri.parse(savedFilePath));
startActivity(mServiceIntent);
break;
...
}
cursor.close();
}
}
};
registerReceiver(receiverDownloadComplete, intentFilter);
And service here:
public class UnZipService extends IntentService {
public UnZipService() {
super("UnZipService");
}
#Override
protected void onHandleIntent(Intent workIntent) {
String dataString = workIntent.getDataString();
Log.v("IntentURI", dataString);
Toast.makeText(this, "Installing....", Toast.LENGTH_SHORT).show();
}
It should show toast just for test, but I always get an error:
01-29 19:08:25.740 15521-15521/org.osmdroid E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=org.osmdroid (has extras) } in org.osmdroid.SettingsActivity$1#21292650
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:768)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5147)
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: android.content.ActivityNotFoundException: Unable to find explicit activity class {org.osmdroid/org.osmdroid.UnZipService}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
at android.app.Activity.startActivityForResult(Activity.java:3404)
at android.app.Activity.startActivityForResult(Activity.java:3365)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
at android.app.Activity.startActivity(Activity.java:3600)
at android.app.Activity.startActivity(Activity.java:3568)
at org.osmdroid.SettingsActivity$1.onReceive(SettingsActivity.java:148)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:758)
at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:150)
            at android.app.ActivityThread.main(ActivityThread.java:5147)
            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)
Both (class and activity) in same folder (org.osmdroid). Seems like paths is ok, but the problem appears and I have no more ideas...
You are starting a service as an activity
Change
Intent mServiceIntent = new Intent(context, UnZipService.class);
mServiceIntent.setData(Uri.parse(savedFilePath));
startActivity(mServiceIntent);
to
Intent mServiceIntent = new Intent(context, UnZipService.class);
mServiceIntent.setData(Uri.parse(savedFilePath));
startService(mServiceIntent); // Only this line is changed
Please declared this activity in your AndroidManifest.xml

google play services Unable to instantiate activity ComponentInfo java.lang.ClassNotFoundException

Before i've imported google play services and basegamesutils everything was ok. now app crashes and in logcat i can see :
12-05 07:42:49.445: E/AndroidRuntime(6223): FATAL EXCEPTION: main
12-05 07:42:49.445: E/AndroidRuntime(6223): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.kubasienki.freefall/com.kubasienki.freefall.MainActivity}: java.lang.ClassNotFoundException: com.kubasienki.freefall.MainActivity
12-05 07:42:49.445: E/AndroidRuntime(6223): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
12-05 07:42:49.445: E/AndroidRuntime(6223): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
12-05 07:42:49.445: E/AndroidRuntime(6223): at android.app.ActivityThread.access$600(ActivityThread.java:140)
12-05 07:42:49.445: E/AndroidRuntime(6223): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
12-05 07:42:49.445: E/AndroidRuntime(6223): at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 07:42:49.445: E/AndroidRuntime(6223): at android.os.Looper.loop(Looper.java:137)
12-05 07:42:49.445: E/AndroidRuntime(6223): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-05 07:42:49.445: E/AndroidRuntime(6223): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 07:42:49.445: E/AndroidRuntime(6223): at java.lang.reflect.Method.invoke(Method.java:511)
12-05 07:42:49.445: E/AndroidRuntime(6223): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-05 07:42:49.445: E/AndroidRuntime(6223): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-05 07:42:49.445: E/AndroidRuntime(6223): at dalvik.system.NativeStart.main(Native Method)
12-05 07:42:49.445: E/AndroidRuntime(6223): Caused by: java.lang.ClassNotFoundException: com.kubasienki.freefall.MainActivity
12-05 07:42:49.445: E/AndroidRuntime(6223): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-05 07:42:49.445: E/AndroidRuntime(6223): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-05 07:42:49.445: E/AndroidRuntime(6223): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-05 07:42:49.445: E/AndroidRuntime(6223): at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
12-05 07:42:49.445: E/AndroidRuntime(6223): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
12-05 07:42:49.445: E/AndroidRuntime(6223): ... 11 more
my MainActivity.java:
package com.kubasienki.freefall;
import com.google.example.games.basegameutils.BaseGameActivity;
import com.kubasienki.freefall.R;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class MainActivity extends BaseGameActivity
implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// final Button button = (Button) findViewById(R.id.start);
// button.setOnClickListener(new View.OnClickListener() {
//#Override
//public void onClick(View v) {
// Intent intent = new Intent(MainActivity.this, Fall.class);
// startActivity(intent);
// }
// });
//final Button button1 = (Button) findViewById(R.id.howto);
// button1.setOnClickListener(new View.OnClickListener() {
// #Override
// public void onClick(View v) {
// Intent intent1 = new Intent(MainActivity.this, HowTo.class);
//
// startActivity(intent1);
// }
// });
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
findViewById(R.id.howto).setOnClickListener(this);
findViewById(R.id.start).setOnClickListener(this);
}
#Override
public void onSignInFailed() {
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
#Override
public void onSignInSucceeded() {
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);
}
#Override
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button) {
// start the asynchronous sign in flow
beginUserInitiatedSignIn();
}
else if (view.getId() == R.id.sign_out_button) {
// sign out.
signOut();
// show sign-in button, hide the sign-out button
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
else if(view.getId() == R.id.howto){
Intent intent1 = new Intent(MainActivity.this, HowTo.class);
startActivity(intent1);
}
else if(view.getId() == R.id.start){
Intent intent = new Intent(MainActivity.this, Fall.class);
startActivity(intent);}
}
//#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;
//}
}
and manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kubasienki.freefall"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.kubasienki.freefall.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="com.kubasienki.freefall.Fall"
android:label="#string/app_name"
android:parentActivityName="com.kubasienki.freefall.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.kubasienki.freefall.MainActivity" />
</activity>
<activity
android:name="com.kubasienki.freefall.HowTo"
android:label="#string/app_name"
android:parentActivityName="com.kubasienki.freefall.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.kubasienki.freefall.MainActivity" />
</activity>
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
</application>
</manifest>
What i have checked:
imported google-play-services_lib and BaseGameUtils
checked build path
What helped for me:
1. in tutorial is to register app_id in ids.xml and then they use app_id form file strings.xml.
2. I have added:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
to Manifest.xml
Try this:
Go to Project/Properties/Java Build Path/Order and Export -- Make sure there's a check in front of Android Dependencies and the support library, if you use it.Mark all checkboxes.Click on Apply and clean the project.
Hope this helps.
make sure that Android Private Libraries is checked in Order and Export.
if it isn't checked,check it and restart eclipse.
This happens because MainActivity derives from BaseGameActivity, and the class loader can't find BaseGameActivity because it wasn't included in the APK. To solve this build issue, make sure that the BaseGameUtils library is being correctly built and included in the APK. In Eclipse, you will want to right click on the BaseGameUtils project and go to Project Properties and make sure it's marked as a library (there's a checkbox for that). Then, go to your project's properties and make sure that the BaseGameUtils project is listed as a dependency of it. If not, add it.

Android App crashing in Emulator [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm a novice android app developer. I wrote an application which fetches Bible Readings from online. I wrote the separate Java class for fetching the reading and I tested it and it's working fine. But when I tried to use that in my Android App, my app crashed and stops working. I've understood from the logs that it's throwing a null pointer exception, but I don't how to fix that. I've also checked the internet and I can't find an exact solution for this. I'm attaching the logs and file related to my application below. Could anyone go through my code and throw some light on fixing the error. I appreciate your time on my behalf and many thanks in advance.
10-25 09:49:23.243: E/AndroidRuntime(620): FATAL EXCEPTION: main
10-25 09:49:23.243: E/AndroidRuntime(620): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mgocsm/com.mgocsm.EveningKymthaPrayers}: java.lang.NullPointerException: println needs a message
10-25 09:49:23.243: E/AndroidRuntime(620): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.os.Looper.loop(Looper.java:137)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-25 09:49:23.243: E/AndroidRuntime(620): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 09:49:23.243: E/AndroidRuntime(620): at java.lang.reflect.Method.invoke(Method.java:511)
10-25 09:49:23.243: E/AndroidRuntime(620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-25 09:49:23.243: E/AndroidRuntime(620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-25 09:49:23.243: E/AndroidRuntime(620): at dalvik.system.NativeStart.main(Native Method)
10-25 09:49:23.243: E/AndroidRuntime(620): Caused by: java.lang.NullPointerException: println needs a message
10-25 09:49:23.243: E/AndroidRuntime(620): at android.util.Log.println_native(Native Method)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.util.Log.d(Log.java:138)
10-25 09:49:23.243: E/AndroidRuntime(620): at com.mgocsm.BibleReader.getVerses(BibleReader.java:44)
10-25 09:49:23.243: E/AndroidRuntime(620): at com.mgocsm.EveningKymthaPrayers.onCreate(EveningKymthaPrayers.java:25)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.app.Activity.performCreate(Activity.java:5008)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-25 09:49:23.243: E/AndroidRuntime(620): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-25 09:49:23.243: E/AndroidRuntime(620): ... 11 more
EveningKymthaPrayers.java (Activitiy from where I call the Java class to fetch readings)
=========================
.
public class EveningKymthaPrayers extends Activity {
AssetManager am;
FileReader f;
TextView kymtha_prayer;
BibleReader bible;
//ReadingList rl = new ReadingList();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.evening_kymtha);
am = getAssets();
f = new FileReader(am,"kymtha.txt");
kymtha_prayer = (TextView) findViewById(R.id.show_kymtha);
kymtha_prayer.setMovementMethod(new ScrollingMovementMethod());
bible = new BibleReader("John 3:16-17");
kymtha_prayer.setText(bible.getVerses());
//kymtha_prayer.setText(f.readFile());
//kymtha_prayer.setText(setText);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
BibleReader.java (Java class for fetching Bible verses)
public class BibleReader {
public static final String URL="http://labs.bible.org/api/?passage=";
String verse;
String logName = "BibleReader";
String line;
StringBuilder recText;
private static final int BUFFER_SIZE = 1024 * 10;
private final byte[] dataBuffer = new byte[BUFFER_SIZE];
public BibleReader(String verse) {
// TODO Auto-generated constructor stub
this.verse = verse;
this.verse = this.verse.toString().replaceAll(" ", "%20");
}
public String getVerses()
{
String body = null;
try{
URL url = new URL(URL+this.verse);
URLConnection con = url.openConnection();
InputStream in = con.getInputStream();
String encoding = con.getContentEncoding();
encoding = encoding == null ? "UTF-8" : encoding;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len = 0;
while ((len = in.read(dataBuffer)) != -1) {
baos.write(dataBuffer, 0, len);
}
body = new String(baos.toByteArray(), encoding);
Log.d(logName, "Fetched Verse"+body);
}
catch(Exception e){
Log.d(logName, e.getMessage());
}
return body.toString();
}
}
AndroidMainfest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mgocsm"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<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>
<activity android:name=".DailyPrayers" android:label="#string/app_name"></activity>
<activity android:name=".EveningPrayers" android:label="#string/app_name"></activity>
<activity android:name=".EveningKymthaPrayers" android:label="#string/app_name"></activity>
</application>
</manifest>
MainActivity.java
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onClick(View v){
switch(v.getId()){
case R.id.daily_prayers:
startActivity(new Intent(getApplicationContext(),DailyPrayers.class));
break;
}
}
}
DailyPrayers.java
public class DailyPrayers extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.daily_prayers);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onClick(View v){
switch(v.getId()){
case R.id.home:
startActivity(new Intent(getApplicationContext(),MainActivity.class));
break;
case R.id.evening_prayers:
startActivity(new Intent(getApplicationContext(),EveningPrayers.class));
break;
}
}
}
EveningPrayers.java
public class EveningPrayers extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.evening_prayers);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onClick(View v){
switch(v.getId()){
case R.id.kymtha_evening:
startActivity(new Intent(getApplicationContext(),EveningKymthaPrayers.class));
break;
case R.id.sleeba_evening:
break;
}
}
}
The body that you are trying to print is getting null as a value.Check first you receive any value in body or not.
What i have noticed in your code:
bible.getVerses() is returning null
It seems INTERNET permission is not included in AndroidManifest.xml file
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Don't make a web call on Main thread. Instead you can use AsyncTask or AsyncTaskLoader
Instead of using:
this.verse = this.verse.toString().replaceAll(" ", "%20");
You must use:
String webURL = URLEncoder.encode("your web url", "utf-8");
What are you logging at this place: com.mgocsm.BibleReader.getVerses(BibleReader.java:44)
?
You are probably passing a Null.
Add this permission in your Manifest
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
body = new String(baos.toByteArray(), encoding);
Log.d(logName, "Fetched Verse"+body);
your Body is getting null value that is why ur log is giving nullpointer exception

error with the map Activity

I develop a simple mapActivity that aska the user to check if he has enabled the gps system or not by using the dialog alert and the intent for the location service. And if the gps is enables it goes direct to the mapView but this do not happen with me. It makes me force close when I press to go to the mapView.
This is the dialog code:
public void onClick(View arg0) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Click yes TO ENABLE GPS")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, close
// current activity
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 1);
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, just close
// the dialog box and do nothing
//dialog.cancel();
Intent intent = new Intent(MainActivity.this, AndroidGoogleMapsActivity.class);
context.startActivity(intent);
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
}
And this is the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mkyong.android"
android:versionCode="1"
android:versionName="1.0" ><uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<uses-library
android:name="com.google.android.maps"
android:required="true" />
<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=".AndroidGoogleMapsActivity" >
</activity>
</application>
</manifest>
this is the code of the AndroidGoogleMapsActivity class
public class AndroidGoogleMapsActivity extends MapActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Displaying Zooming controls
MapView mapView = (MapView) findViewById(R.id.mapView);
Log.d("error", "the negative button befor the line 27 ");
mapView.setBuiltInZoomControls(true);
Log.d("error", "the negative button after the line 27 befor the map view settings ");
mapView.setSatellite(true); // Satellite View
Log.d("error", "the negative button after the line 27 after satellite view ");
mapView.setStreetView(false); // Street View
Log.d("error", "the negative button after the line 27 after street view ");
mapView.setTraffic(true); // Traffic view
Log.d("error", "the negative button after the line 27 after the map view settings ");
MapController mc = mapView.getController();
Log.d("error", "the negative button after the line 27 after the mapController ");
double lat = Double.parseDouble("33.823862");// kehale
double lon = Double.parseDouble("35.590248");// kehale
GeoPoint geoPoint = new GeoPoint((int)(lat * 1E6), (int)(lon * 1E6));
mc.animateTo(geoPoint);
mc.setZoom(15);
mapView.invalidate();
Log.d("error", "the negative button befor the GeoPoint");
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
And this is the error that I get:
09-20 05:16:22.512: D/AndroidRuntime(309): Shutting down VM
09-20 05:16:22.512: W/dalvikvm(309): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-20 05:16:22.543: E/AndroidRuntime(309): FATAL EXCEPTION: main
09-20 05:16:22.543: E/AndroidRuntime(309): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mkyong.android/com.mkyong.android.AndroidGoogleMapsActivity}: java.lang.NullPointerException
09-20 05:16:22.543: E/AndroidRuntime(309): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-20 05:16:22.543: E/AndroidRuntime(309): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-20 05:16:22.543: E/AndroidRuntime(309): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-20 05:16:22.543: E/AndroidRuntime(309): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-20 05:16:22.543: E/AndroidRuntime(309): at android.os.Handler.dispatchMessage(Handler.java:99)
09-20 05:16:22.543: E/AndroidRuntime(309): at android.os.Looper.loop(Looper.java:123)
09-20 05:16:22.543: E/AndroidRuntime(309): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-20 05:16:22.543: E/AndroidRuntime(309): at java.lang.reflect.Method.invokeNative(Native Method)
09-20 05:16:22.543: E/AndroidRuntime(309): at java.lang.reflect.Method.invoke(Method.java:521)
09-20 05:16:22.543: E/AndroidRuntime(309): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-20 05:16:22.543: E/AndroidRuntime(309): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-20 05:16:22.543: E/AndroidRuntime(309): at dalvik.system.NativeStart.main(Native Method)
09-20 05:16:22.543: E/AndroidRuntime(309): Caused by: java.lang.NullPointerException
09-20 05:16:22.543: E/AndroidRuntime(309): at com.mkyong.android.AndroidGoogleMapsActivity.onCreate(AndroidGoogleMapsActivity.java:27)
09-20 05:16:22.543: E/AndroidRuntime(309): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-20 05:16:22.543: E/AndroidRuntime(309): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-20 05:16:22.543: E/AndroidRuntime(309): ... 11 more
09-20 05:16:25.141: I/Process(309): Sending signal. PID: 309 SIG: 9
Seems like you got a problem in your layout-file that causes this NullPointerException.
// This command tries to get the mapView but fails to find it, so it returns null, instead of the mapView
MapView mapView = (MapView) findViewById(R.id.mapView);
// This tries to call a method on null, which will cause a NullPointerException.
mapView.setBuiltInZoomControls(true);
To solve this check that in your layout/map_activity.xml the map is actually named mapView like this:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />

Categories