I'm getting this fatal exception: main error. It is only when I click on the 'Pick A Place' button on my app.
The logcat report when clicking on the 'Pick A Place' button is below:
04-13 13:52:19.418 10737-10737/cct.mad.lab E/AndroidRuntime: FATAL EXCEPTION: main
Process: cct.mad.lab, PID: 10737
java.lang.NoSuchMethodError: cct.mad.lab.SettingsActivity.checkSelfPermission
at cct.mad.lab.SettingsActivity.calculateCurrentCoordinates(SettingsActivity.java:679)
at cct.mad.lab.SettingsActivity.onPrepareDialog(SettingsActivity.java:581)
at android.app.Activity.onPrepareDialog(Activity.java:3061)
at android.app.Activity.showDialog(Activity.java:3124)
at android.app.Activity.showDialog(Activity.java:3075)
at cct.mad.lab.SettingsActivity$8.onClick(SettingsActivity.java:374)
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:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
The logcat points to a 'NoSuchMethodError' when checking for 'self permission' to do with the method 'calculateCurrentCooridnates'. This method is below:
#TargetApi(Build.VERSION_CODES.M)
private void calculateCurrentCoordinates() {
float lat = 0, lon = 0;
try {
LocationManager locMgr = (LocationManager) getSystemService(LOCATION_SERVICE);
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// Activity#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for Activity#requestPermissions for more details.
return;
}
Location recentLoc = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
lat = (float) recentLoc.getLatitude();
lon = (float) recentLoc.getLongitude();
} catch (Exception e) {
Log.e(DEBUG_TAG, "Location failed", e);
}
mFavPlaceCoords = new GPSCoords(lat, lon);
}
The ToDo was automatically generated when Android Studio automatically added the '#TargetAPI' bit. With this in mind I added the following to the manifest and as I got no more errors I thought this would be enough:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
However, the app just crashes.
Any help greatly appreciated.
Thanks
Extending AppCompatActivity will solve the issue.
Do like this
public class SettingsActivity extends AppCompatActivity {
Related
I'm making a small app, I use sinch for video calling and it works fine on android 8.1 and lower. But on android 9, my app crash when I make a video call. and this is the error:
2019-02-11 11:36:56.895 1638-2821/? E/AndroidRuntime: FATAL EXCEPTION: VideoCapturerThread
Process: com.example.myapp.app, PID: 1638
java.lang.SecurityException: validateClientPermissionsLocked:1054: Caller "com.example.myapp.app" (PID 10319, UID 1638) cannot open camera "1" without camera permission
at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:747)
at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:405)
at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:567)
at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:495)
at org.webrtc.Camera2Session.openCamera(Unknown Source:44)
at org.webrtc.Camera2Session.start(Unknown Source:60)
at org.webrtc.Camera2Session.<init>(Unknown Source:73)
at org.webrtc.Camera2Session.create(Unknown Source:17)
at org.webrtc.Camera2Capturer.createCameraSession(Unknown Source:17)
at org.webrtc.CameraCapturer$5.run(Unknown Source:52)
at android.os.Handler.handleCallback(Handler.java:891)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:207)
at android.os.HandlerThread.run(HandlerThread.java:65)`
Try this method for video capture with camera may be it helps you:-
public void dispatchTakeVideoIntent() {
PermissionUtil.with(this).setCallback(new PermissionUtil.PermissionGrantedListener() {
#Override
public void onPermissionResult(boolean isGranted, int requestCode) {
if (isGranted) {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, AppConstants.REQUEST_CODE.REQUEST_VIDEO_CAPTURE);
}
}
}
}).validate(Manifest.permission.CAMERA);
}
for the permission Util check this link https://www.truiton.com/2016/04/obtaining-runtime-permissions-android-marshmallow-6-0/
In android versions earlier than Lollipop, I keep getting the VerifyError while trying to instantiate a fragment, leading to an app crash. Can someone explain to me the cause of this error?
12-19 17:46:52.510 28238-28238/com.greeblu.tootl2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.greeblu.tootl2, PID: 28238
java.lang.VerifyError: com/greeblu/tootl2/fragment/ProfileGridFragment
at com.greeblu.tootl2.activity.ProfileActivity.launchGridFragment(ProfileActivity.java:289)
at com.greeblu.tootl2.fragment.ProfileOverlayFragment$3.onClick(ProfileOverlayFragment.java:123)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18439)
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:5034)
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:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)
This is how I'm calling the fragment for older android versions:
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.profileContainer, new ProfileGridFragment(),fragmentTag); //Replaces the Fragment C previously in the right_container with a new Fragment B
ft.commit();
Edit:
The code for the onClick call is as follows. It is called from another fragment in the same activity
picContainer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
((ProfileActivity) getActivity()).launchGridFragment(overlayDp, "all");
}
});
I've encountered this exact error because I had a try-catch block with exception class that is unavailable on old android versions. The block wasn't even in the constructor, it was in one of the onClick methods so the code wasn't even executed, but nevertheless app was always crashing with VerifyError as soon as I was trying to create the fragment.
Solver it by changing clause block with instanceof check:
Crashing:
try {
...
} catch (FileUriExposedException e) {
...
}
Works ok:
try {
...
} catch (Exception e) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && e instanceof FileUriExposedException) {
...
}
}
Are you using the support Fragment class from android.support.v4.app.Fragment? If so you need to be calling
getSupportFragmentManager()
instead of
getFragmentManager()
Note that the Fragment class from android.app.Fragment is now deprecated.
I'm trying to start a third party app(here is Launcher) by using this code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String currentHomePackage = resolveInfo.activityInfo.packageName;
openApp(getApplicationContext(),currentHomePackage);
openApp:
public static boolean openApp(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
return true;
} catch (Exception e) {
return false;
}
}
but I get a NullPointerException! This code gets my launcher package name correctly, but I can't open it! Help me please and don't get me negative points!
logcat:
07-30 18:59:47.206 16079-16079/ir.whiteapp.keepme E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at ir.whiteapp.keepme.AlertBox.openApp(AlertBox.java:80)
at ir.whiteapp.keepme.AlertBox$1.onClick(AlertBox.java:52)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
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)
There is no requirement that getLaunchIntentForPackage() return anything. Quoting the documentation:
Returns: A fully-qualified Intent that can be used to launch the main activity in the package. Returns null if the package does not contain such an activity, or if packageName is not recognized.
In particular, a home screen implementation does not need a launch Intent (ACTION_MAIN/CATEGORY_LAUNCHER), as normally it is not launched by other home screen implementations.
I followed a tutorial online about how to create a simple app that can switch on and off your phone's cam-light.
<manifest....>
<uses-permission android:name = "android.permission.CAMERA"/>
<uses-feature android:name = "android.hardware.camera"/>
</manifest>
This is in android manifest.
The problem: it crashes when I press the ON button (made by me, in application)
Stack Trace:
07-17 22:27:13.990: E/AndroidRuntime(1775): FATAL EXCEPTION: main
07-17 22:27:13.990: E/AndroidRuntime(1775): java.lang.NullPointerException
07-17 22:27:13.990: E/AndroidRuntime(1775): at com.example.salpa.MainActivity$1.onClick(MainActivity.java:33)
07-17 22:27:13.990: E/AndroidRuntime(1775): at android.view.View.performClick(View.java:4204)
07-17 22:27:13.990: E/AndroidRuntime(1775): at android.view.View$PerformClick.run(View.java:17355)
07-17 22:27:13.990: E/AndroidRuntime(1775): at android.os.Handler.handleCallback(Handler.java:725)
Another strange thing: when I install the app, there are no details about what permissions is requiring.
"The application can acces the following on your phone:" and there's nothing. (despite the permissions in tutorial where it shows that the application needs permision to Camera.)
Can someone please help me, thanks.
setContentView(R.layout.activity_main);
Button aprinde =(Button)findViewById(R.id.aprinde);
//Button sting = (Button)findViewById(R.id.sting);
cameraObj = Camera.open();
aprinde.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view){
Camera.Parameters cameraParams = cameraObj.getParameters();
cameraParams.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cameraObj.setParameters(cameraParams);
cameraObj.startPreview();
}
} );
Your app is crashing because you are running it on an emulator, which doesn't have a back-facing camera.
The documentation for Camera#open():
Creates a new Camera object to access the first back-facing camera on the
device. If the device does not have a back-facing camera, this returns
null.
You can fix the crash by checking for null.
public void onClick(View v) {
if (cameraObj == null) {
return;
}
Camera.Parameters cameraParams = cameraObj.getParameters();
cameraParams.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cameraObj.setParameters(cameraParams);
cameraObj.startPreview();
}
You should also look out for setParameters as this could crash too if the device doesn't have a flash.
public void onClick(View v) {
if (cameraObj == null) {
return;
}
Camera.Parameters cameraParams = cameraObj.getParameters();
if (cameraParams.getFlashMode() == null) {
return;
}
cameraParams.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cameraObj.setParameters(cameraParams);
cameraObj.startPreview();
}
I'm trying to implement twitter login in my android app.
I've followed the instructions ( https://dev.twitter.com/twitter-kit/android/twitter-login ).
Everything is working fine if I have the twitter app installed but if I don't when I tap on the login button I get the exception below.
It shoulw open a webview asking to login instead.
Any hint?
06-02 11:22:23.531 24124-24124/it.quepasa W/dalvikvm: VFY: unable to resolve virtual method 39779: Lretrofit/client/OkClient;.openConnection (Lretrofit/client/Request;)Ljava/net/HttpURLConnection;
06-02 11:22:23.611 24124-24124/it.quepasa E/Twitter﹕ Failed to get request token
com.twitter.sdk.android.core.TwitterApiException: method POST must have a request body.
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:400)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:838)
06-02 11:22:23.686 24124-24124/it.quepasa E/Twitter﹕ Authorization completed with an error
com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:78)
at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:198)
at com.twitter.sdk.android.core.Callback.failure(Callback.java:28)
at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5370)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Here there is my code:
AndroidManifest.xml:
<meta-data
android:name="io.fabric.ApiKey"
android:value="XXXXXXXX" />
MainActivity.java:
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig), new Crashlytics()); //I've tried without crashlytics, same problem. Crashlytics works..
LoginActivity.java:
loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_buttons);
loginButton.setCallback(new Callback<TwitterSession>() {
#Override
public void success(Result<TwitterSession> result) {
Log.d(TAG, "Success");
}
#Override
public void failure(TwitterException exception) {
Log.d(TAG, "Failure");
}
});
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
loginButton.onActivityResult(requestCode, resultCode, data);
}
I've found a solution:
it is a breaking change in okhttp 2.4, reverting to 2.3 solved my problem.
See:
https://github.com/square/okhttp/issues/751
https://github.com/square/retrofit/issues/854