Android - java.lang.VerifyError on SDK 2.2 - java

I recently launched my application to the Market and I've been in contact with a user who is reporting that when he launches my app, it display the Force Close/Report dialog. I asked the user to report the error so I could see the stack trace of what's happening and I'm getting the java.lang.VerifyError.
From what I've read, this has either something to do with an external library or an incompatibility in some method in java.lang with the targeted Android SDK version.
The user is on Android 2.2.1, but the app currently works on many other 2.2 devices, so I'm trying to figure out where to start digging.
Question:
Does anybody have suggestions as to what would be the best thing to start looking into to find the issue? I can provide code or more information if needed, so please let me know.
Here's the Stack Trace:
java.lang.VerifyError: com.app.myapp.MainActivity
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1034)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2749)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2866)
at android.app.ActivityThread.access$2300(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2181)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Thanks in advance!
EDIT
Added per request of Konstantin
MainActivity.java
package com.app.myapp;
//Imports removed
public class MainActivity extends BaseActivity implements Runnable {
private LayoutInflater mInflater;
private SharedPreferences prefs;
private SharedPreferences.Editor prefsEditor;
....
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadActivity(savedInstanceState);
}
private void loadActivity(Bundle savedInstanceState) {
setContentView(R.layout.mainlayout);
ActionBar actionBar = (ActionBar)findViewById(R.id.actionbar);
actionBar.setTitle("My App");
actionBar.setHomeAction(new IntentAction(this, null, R.drawable.ic_actionbar_home));
actionBar.addAction(new SearchAction(this, R.drawable.ic_actionbar_search));
weatherThread = new Thread(this);
try {
....Unrelated Code....
//****HERE WAS THE PROBLEM****//
Gson gson = new Gson();
....More Unrelated Code....
} catch (JsonSyntaxException ex) { }
initMembers();
initControls();
if (savedInstanceState != null) {
mSelectedLayout = savedInstanceState.getInt("CURRENT_TAB");
setCurrentTab();
}
else
loadMainLayout();
}
....Other unrelated code....
}

There are a few devices which are using GSON internally, but made the library public, causing a namespace conflict when the application attempts to reference its packaged version of gson. A possible workaround is changing the namespace of the gson jar you have included using jarjar.
Heres a thread on the issue - The thread contains a description of at least one workaround supplied by another developer who encountered the same issue.

there could be mismatch with the libs like Gson you have compiled and libs which are used in run time.
Ref - Causes of getting a java.lang.VerifyError

It looks like ActionBar was released since API level 11 only, while android 2.2 is somewhat older (API level 8). So try it without the action bar. I do not know if the view was backported to 2.2 platform, but even if it was, your user can still have old 2.2 version..

Check that you are compiling against the correct Android SDK version. What is minSDK in your AndroidManifest.xml?

Related

How to authenticate Android app to connect with Spotify?

I want to create my own (non-commercial) DDR app on my phone for fun that uses music from Spotify.
So far I've tried to follow the quickstart tutorial: https://developer.spotify.com/documentation/android/quick-start/
I have created a template app, with just a hello world screen in android studio.
I have the spotify app installed, and I'm logged in with a premium account.
I went to the spotify developer dashboard and registered my app. My app is called MyDDR for now.
I have the redirect URI set to 192.168.1.23:5000/callback, a flask server running on my PC. I tested it, and my phone can connect to it. I don't know if this is relevant since there is no traffic triggered by my code for now.
Then I added my fingerprint and package name to the app I registered in the spotify developer dashboard. Here are my results from that:
I created a signed bundle, with a keystore created following this tutorial.
I only did the 'register app fingerprints' part, since the page seemed to be just an old version of the quickstart guide I was already following.
Running the gradle task signingReport revealed the same SHA1 key that was in my keystore by checking it manually.
> Task :app:signingReport
Variant: release
Config: none
----------
Variant: debug
Config: debug
Store: C:\Users\[name]\.android\debug.keystore
Alias: AndroidDebugKey
MD5: [removed]
SHA1: [mysha1key]
SHA-256: [removed]
Valid until: Wednesday, 8 September 2049
----------
[3 other variants, debugUnitTest, debugAndroidTest, releaseUnitTest]
I'm not familiar with signing apps, so I'm not sure it did it right.
As far as I understand it I only need to concern myself with debug right? I don't have plans releasing this to the play store.
Here is my android studio setup:
As you can see my package name is com.example.myddr
And finally I added my package name and fingerprint in the spotify developer dashboard:
I had downloaded the Spotify Android SDK, by downloading the spotify-app-remote-release-0.6.3.aar file and adding it as a new module. I added the module/project to my build.gradle (Module: app) dependencies, together with gson, like the tutorial instructed.
dependencies {
implementation project(':spotify-app-remote')
implementation "com.google.code.gson:gson:2.8.5"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Now I was ready for the step 'Authorizing the user using the built-in auth flow'
This is the code so far
package com.example.myddr;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.spotify.android.appremote.api.ConnectionParams;
import com.spotify.android.appremote.api.Connector;
import com.spotify.android.appremote.api.SpotifyAppRemote;
import com.spotify.protocol.client.Subscription;
import com.spotify.protocol.types.PlayerState;
import com.spotify.protocol.types.Track;
public class MainActivity extends AppCompatActivity {
private static final String CLIENT_ID = "2d6a5307b3024e7b9b32d52146150986";
private static final String REDIRECT_URI = "http://192.168.1.23:5000/callback";
private SpotifyAppRemote mSpotifyAppRemote;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onStart() {
super.onStart();
ConnectionParams connectionParams =
new ConnectionParams.Builder(CLIENT_ID)
.setRedirectUri(REDIRECT_URI)
.showAuthView(true)
.build();
SpotifyAppRemote.connect(this, connectionParams,
new Connector.ConnectionListener() {
public void onConnected(SpotifyAppRemote spotifyAppRemote) {
mSpotifyAppRemote = spotifyAppRemote;
Log.d("MainActivity", "Connected! Yay!");
// Now you can start interacting with App Remote
connected();
}
public void onFailure(Throwable throwable) {
Log.e("MainActivity", throwable.getMessage(), throwable);
// Something went wrong when attempting to connect! Handle errors here
}
});
}
private void connected() {
}
}
However when running this I get a lot of warnings like this:
W/m.example.mydd: Unable to resolve Lcom/spotify/protocol/types/HelloDetails; annotation class 28
W/m.example.mydd: Unable to resolve Lcom/spotify/protocol/types/HelloDetails; annotation class 31
W/m.example.mydd: Unable to resolve Lcom/spotify/protocol/types/Info; annotation class 28
W/m.example.mydd: Unable to resolve Lcom/spotify/protocol/types/Info; annotation class 31
And finally an error:
E/MainActivity: {"message":"com.spotify.mobile.android.spotlets.appprotocol.model.AppProtocol$Message"}
com.spotify.android.appremote.api.error.AuthenticationFailedException: {"message":"com.spotify.mobile.android.spotlets.appprotocol.model.AppProtocol$Message"}
at com.spotify.android.appremote.api.LocalConnector.asAppRemoteException(LocalConnector.java:131)
at com.spotify.android.appremote.api.LocalConnector.access$000(LocalConnector.java:35)
at com.spotify.android.appremote.api.LocalConnector$1.onConnectionFailed(LocalConnector.java:111)
at com.spotify.android.appremote.internal.SdkRemoteClientConnector$ConnectionTask.onPostExecute(SdkRemoteClientConnector.java:142)
at com.spotify.android.appremote.internal.SdkRemoteClientConnector$ConnectionTask.onPostExecute(SdkRemoteClientConnector.java:75)
at android.os.AsyncTask.finish(AsyncTask.java:695)
at android.os.AsyncTask.access$600(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: com.spotify.protocol.client.error.RemoteClientException: {"message":"com.spotify.mobile.android.spotlets.appprotocol.model.AppProtocol$Message"}
at com.spotify.protocol.client.RemoteWampClient.getRemoteClientException(RemoteWampClient.java:139)
at com.spotify.protocol.client.RemoteWampClient.access$200(RemoteWampClient.java:16)
at com.spotify.protocol.client.RemoteWampClient$1.onAbort(RemoteWampClient.java:44)
at com.spotify.protocol.client.WampRouterImpl.routeAbort(WampRouterImpl.java:100)
at com.spotify.protocol.client.WampRouterImpl.route(WampRouterImpl.java:26)
at com.spotify.protocol.client.AppProtocolCommunicator.onData(AppProtocolCommunicator.java:78)
at com.spotify.android.appremote.internal.RemoteServiceIo.handleMessage(RemoteServiceIo.java:113)
at com.spotify.android.appremote.internal.RemoteServiceIo.access$000(RemoteServiceIo.java:47)
at com.spotify.android.appremote.internal.RemoteServiceIo$IncomingHandler.handleMessage(RemoteServiceIo.java:91)
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6898) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
This error means that I couldn't connect to Spotify due to an AuthenticationFailedException. Googling the error delivered no satisfying solutions. I only found people who had forgotten to register their fingerprint, but as far as I know I've done that. But I'm also suspicious that I did not do it correctly, because it seems fairly complicated.

react-native-facebook-login: attempt to login results in Instrumentation.java error

I am using react-native-facebook-login for users authorization in my react-native app. It used to work just fine, but now it is not working when used with new versions of Android (in particular, with Android Pie). Old versions still work.
When I press Login button, some kind of loading happens, and then Facebook layout with following error shows up: "Login Error: There is an error in logging you into this application. Please try again later".
I've checked the logcat, and found this error showed up after the button was pressed.
2019-07-25 19:38:53.855 17122-17122/? E/Instrumentation: Uninitialized ActivityThread, likely app-created Instrumentation, disabling AppComponentFactory
java.lang.Throwable
at android.app.Instrumentation.getFactory(Instrumentation.java:1233)
at android.app.Instrumentation.newActivity(Instrumentation.java:1224)
at X.04T.newActivity(:4122)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3313)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3587)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2185)
at android.os.Handler.dispatchMessage(Handler.java:112)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7593)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
This stacktrace has led me to Instrumentation.java, so this is the code where error occurs:
private AppComponentFactory getFactory(String pkg) {
if (pkg == null) {
Log.e(TAG, "No pkg specified, disabling AppComponentFactory");
return AppComponentFactory.DEFAULT;
}
if (mThread == null) {
Log.e(TAG, "Uninitialized ActivityThread, likely app-created Instrumentation,"
+ " disabling AppComponentFactory", new Throwable());
return AppComponentFactory.DEFAULT;
}
LoadedApk apk = mThread.peekPackageInfo(pkg, true);
// This is in the case of starting up "android".
if (apk == null) apk = mThread.getSystemContext().mPackageInfo;
return apk.getAppFactory();
}
I am not that good in Java to be able to understand how to fix it, or what is even going on here. I've found some articles where this stuff is mentioned, but all of them are in chinese and not really helping. So, if anyone knows how this could be handled, I'd really appreciate any help.

Android media.AudioTrack.finalize Throwing IllegalStateException: Binder has been finalized

I am using a custom camera to record Videos on android.
The device experiencing the issue is a Nexus 5 with Android 6.0.1 on it.
When the camera finishes recording for only for the 2nd time, i get the following exception in the under-the-hood android media AudioTrack class. This is something that is called implicitly by android, by the FinalizerDaemon, and not as a result of any code I execute directly. So the FinalizerDaemon calls finalize on AudioTrack, and gets an IllegalStateException.
12-02 09:20:23.155 23705-23714/social.ivideo.greetings E/System: Uncaught exception thrown by finalizer
12-02 09:20:23.160 23705-23714/social.ivideo.greetings E/System: java.lang.IllegalStateException: Binder has been finalized!
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:615)
at com.android.internal.app.IAppOpsService$Stub$Proxy.stopWatchingMode(IAppOpsService.java:435)
at android.media.PlayerBase.baseRelease(PlayerBase.java:136)
at android.media.AudioTrack.finalize(AudioTrack.java:979)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:222)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:209)
at java.lang.Thread.run(Thread.java:761)
Perhaps I need to do some sort of clean up when the camera finishes recording? Here's the current code I'm using when the recording stops:
#Override
public void stopRecording(boolean wasCancelled, float duration) {
if (mMediaRecorder != null) {
mMediaRecorder.stop();
mMediaRecorder.reset();
if (flashState) {
toggleFlash();
}
if (!wasCancelled) {
callbacks.onFinishedRecording(null, mediaPath, duration, wasCancelled);
}
}
}
mMediaRecorder is an instance of MediaRecorder class.
Any suggestions?
So I think this might be an Android bug. Looks suspiciously like this issue, which is marked as fixed in a "future version": https://issuetracker.google.com/issues/37138597
Same Issue Reported in Android 7.1.2
fixed in Android 8.0 https://android.googlesource.com/platform/frameworks/base/+log/aee6ee94675d56e71a42d52b16b8d8e5fa6ea3ff/media/java/android/media/PlayerBase.java

Android app crashes with java.lang.NoClassDefFoundError

I have an application that creates an Intent when selecting item menu, but the first time the user clicks this button, the app crashes with the following stack trace.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.systemsat.monitriip, PID: 17818
java.lang.NoClassDefFoundError: br.com.systemsat.monitriip.activity.ConfigurationActivity
at br.com.systemsat.monitriip.activity.MainActivity.onOptionsItemSelected(MainActivity.java:212)
at android.app.Activity.onMenuItemSelected(Activity.java:2912)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:421)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:188)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.onMenuItemSelected(AppCompatDelegateImplV7.java:663)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:810)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:957)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:947)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618)
at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:155)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Below is my Activity declaration inside AndroidManifest.xml:
<activity
android:name=".activity.ConfigurationActivity"
android:parentActivityName=".activity.MainActivity">
</activity>
Also, below is the line that is accused to be the cause of the problem by the call stack:
Intent hashCodeIntent = new Intent(getApplicationContext(), ConfigurationActivity.class);
Some answers found in StackOverflow pointed me that clean and rebuild would do the trick but I've tried without any luck. I have also tried adding MultiDex to gradle file as well as to my custom Application class, but that also resulted in a no go.
Could someone else have any insights as to what I might have done wrong? What is really intriguing is that this error only happens on the first time the user clicks the "Configuration" screen button. After the app crashes, the user can reopen it and click the button normally.
Thank you in advance.
UPDATE
I have forgot to mention that Android Monitor also logs the following info right before the crash:
Rejecting re-init on previously-failed class java.lang.Class<br.com.systemsat.monitriip.activity.ConfigurationActivity>
UPDATE 2
Here is my onOptionsItemSelected method:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_action_config:
Intent hashCodeIntent = new Intent(this, ConfigurationActivity.class);
hashCodeIntent.putExtra("isConfigurationCall", true);
startActivity(hashCodeIntent);
break;
}
return true;
}
UPDATE 3
I have just generated an apk for testing purposes and the error did not show. Maybe it has something to do with debuging? Or even something to do with gradle version? I currently use the last version of gradle.
Try to change getAplicationContext() for getActivity()
Sometimes getAplicationContext returns null.

I don't have force to close the application in android

i am developing an android application using a new device (Samsung galaxy core) the problem is when I try to run the application and I have an error in my code like infinity loop or something like that when the application run in my device a black screen appears and i can't do nothing only restart the device and start over again I don't see the dialog ( force to close application ... ) which I used to have in my old device any help please !
thanks for you answers and sorry if i wasn't so clear actually the problem is not in my code it's in the device (i think) for example in this code i haven't declare a new activity in Androidmanifest.xml
package com.exadle.df;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.button);
final Intent intent = new Intent(MainActivity.this, newj.class);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
MainActivity.this.startActivity(intent);
}
});
}
}
so when the app crash a black screen appears and i can't do nothing ! even as you said "Hold the Home Button for couple of seconds, when the list of running applications shows up, flip your app out." the only thing i can do is Hold power Button to restart the phone
here is the logcat if it can help
05-25 15:04:32.281 21017-21017/com.exadle.df D/dalvikvm﹕ Late-enabling CheckJNI
05-25 15:04:32.401 21017-21017/com.exadle.df D/ActivityThread﹕ setTargetHeapUtilization:0.25
05-25 15:04:32.401 21017-21017/com.exadle.df D/ActivityThread﹕ setTargetHeapIdealFree:8388608
05-25 15:04:32.401 21017-21017/com.exadle.df D/ActivityThread﹕ setTargetHeapConcurrentStart:2097152
05-25 15:04:32.871 21017-21017/com.exadle.df D/libEGL﹕ loaded /system/lib/egl/libEGL_adreno200.so
05-25 15:04:32.881 21017-21017/com.exadle.df D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_adreno200.so
05-25 15:04:32.891 21017-21017/com.exadle.df D/libEGL﹕ loaded /system/lib/egl/libGLESv2_adreno200.so
05-25 15:04:32.891 21017-21017/com.exadle.df I/Adreno200-EGL﹕ <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.02.21.107_msm8625_JB_REL_2.0.3_CL3357771_release_AU (CL3357771)
Build Date: 02/25/13 Mon
Local Branch:
Remote Branch: quic/jb_rel_2.0.3
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.02.21.107 + NOTHING
05-25 15:04:32.941 21017-21017/com.exadle.df D/OpenGLRenderer﹕ Enabling debug mode 0
05-25 15:04:37.531 21017-21017/com.exadle.df D/AndroidRuntime﹕ Shutting down VM
05-25 15:04:37.531 21017-21017/com.exadle.df W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41b78438)
05-25 15:04:37.541 21017-21017/com.exadle.df E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.exadle.df/com.exadle.df.newj}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
at android.app.Activity.startActivityForResult(Activity.java:3429)
at android.app.Activity.startActivityForResult(Activity.java:3390)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
at android.app.Activity.startActivity(Activity.java:3600)
at android.app.Activity.startActivity(Activity.java:3568)
at com.exadle.df.MainActivity$1.onClick(MainActivity.java:25)
at android.view.View.performClick(View.java:4191)
at android.view.View$PerformClick.run(View.java:17229)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
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:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
i am using Android Studio and i can't use stop execution !
Without the code for your app, I can't tell why it is hanging.
If you think it is stuck in an infinite loop, you can use tools to determine roughly where the loop is. A good pace to start is with the profiling tools in the Android Development Kit, which will tell you the method where the loop is occurring.
If you show us some of the code or logcat, we may be able to help more. But, I can offer my bit of advice.
When I come across something in my apps that is not working right, or it crashes when it comes to that bit of code, I comment out a few blocks of code at a time, and find the point at which the app runs correctly. So If I had an app that crashed when a specific method was called, I would systematically comment out parts of that method until it stopped crashing. If it only stopped when the entire method was commented out, then I would need to go into the code and try to spot the problem. However, if you comment out half of the method and the remaining code runs, then you know that the problem is in something you commented out. Then you can narrow that down to the exact problem.
Just make sure you comment out blocks of code that make sense. Don't just comment out a bracket, and then have your program give you errors. Comment out the code intelligently.
Since your entire app isn't working, make sure that your preliminary activity is set correctly in your Manifest. If it is your splash, make sure that it is called when the app starts. There is a setting/line of code in the manifest somewhere, but I forget where it is. If all of that is correct, then start commenting out the code in that activity systematically. Start with the last method called, then the second to last, and so on. When it starts running, look at the code you have commented out and try to find the problem.
This is all we can do without any code or logcat. If the problem turns out not to be in the code, but in the phone, then this would be better suited on the Android Enthusiasts forum. You could ask for a migration if this is the case. Hope this helps!
UPDATE
I am still not 100% sure what the problem is, but I can suggest some changes in your code that may or may not work.
Make sure your newj activity is in your Manifest.XML. There should be a line of code that says:
<activity android:theme="#style/AppBaseTheme" android:screenOrientation="portrait" android:name="newj"></activity>
If that doesn't help at all, you can try these also.
Instead of having your intent outside the click listener, put in inside. I find that having not in the same OnClickListener or if statement or method can cause a problem to two. So your code would be:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Intent intent = new Intent(MainActivity.this, newj.class);
startActivity(intent); //and get rid of MainActivity.this.
}
});
If that doesn't work, then this method is more in-depth, but I think it is safer.
First, you want to go into the XML for your button, and add these two lines.
android:Clickable="true"
android:onClick="methodToBeCalled"
These two lines take the place of the OnClickListener, and make the button clickable and tell the program which method to call when the button is clicked. So you need to make a new method, outside of onCreate, that looks like this.
public static void methodToBeCalled(View view){
final Intent intent = new Intent(MainActivity.this, newj.class);
startActivity(intent);
}
So basically what happens is that the code in the XML makes the button clickable, and says to call the method, "methodToBeCalled" when it is clicked. Then it looks for that method in your mainActivity class (because that XML file is linked to this activity) and it runs that activity, starting the Intent intent which starts the Activity newj. Confusing, right? Not really. The XML tells the program to run the method "methodToBeCalled", which starts newj.
Try these methods in order. If method 1 doesn't work, move onto 2. Then 3. If none of these work, update your question with the new logcat, your entire MainActivity code, your entire activity_main XML code, and your entire AndroidManifest.XML code. We can move on from there.
If this does turn out to be a problem with your phone and not the code, flag for migration to Android Enthusiasts Stack Exchange. You will get better help there if this does turn out to be a problem with the phone itself, and not the code.
Hope this helps!

Categories

Resources