Custom Application class onCreate() never called - android

I'm trying to initialize Parse on a custom Application class:
import android.app.Application;
import android.util.Log;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseInstallation;
import com.parse.SaveCallback;
public class SomeApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
initializeParse();
}
private void initializeParse() {
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("##########")
.clientKey("############")
.server("https://#####.com/parse/")
.build()
);
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
// Do something here
}
});
}
}
And I already declare this Application in AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.someproject">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".SomeApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AnotherActivity"/>
</application>
</manifest>
But my custom Application is never called. I tried to put logs and break points on onCreate method, clean project, rebuild project, close and re-open Android Studio, uninstall and reinstall the app and nothing ... so, I need help.
Thanks!

Disable Instant Run, Clean build, Rebuild the project and then run again.
I had the same issue. Disabling instant run worked for me. It is weird Application class not getting called. But it happened.

In my case I forgot about declaration in the manifest:
<application
android:name=".App"
...>

This worked for me - try using this property in your Manifest file:
<application
android:name=".SomeApplication"
android:usesCleartextTraffic="true"

Related

Parse Error: There was a problem parsing the package

I try to resolve this error from various methods in my Hello World App.These are;
-Go to Security-->Unknown sources.
-Go to About phone-->Build number.
-Update my manifest file whose picture is given below.
-Test app both on phone Y625 Huawei and on tablet T1-701u tab.
-Reboot android phone and android studio (version 3.4.1).
-Transfer apk file via data cable or airmove software.
But none of them works to solve the issue.
I develop my Hello World. Firstly i faced insufficient heap size error issue which has solved on the temporary basis. After build up my app, Parsing the package issue has emerged.
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hw04">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.example.hw04;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Parse Error
There was a problem parsing the package enter code here

Subclass activity from a jar getting ClassNotFoundException

I have two Android projects. One is a library and compiles a jar the other an executable which includes this jar on the build path.
I'm subclassing an activity in the jar in my project but when I start it I'm getting a ClassNotFoundException.
Here's the manifest with the activity in question being MainActivity:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.package.MyProject"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:label="#string/app_name"
android:name=".MyApplication"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<activity android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here is my MainActivity, where the QCARSamples package is found in my jar:
package com.my.package.MyProject;
import java.io.File;
import com.qualcomm.QCARSamples.ImageTargets.GraphicsEngineHook;
import com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity;
import com.my.package.MyProject.R;
public class MainActivity extends VuforiaTrackingActivity{
private File blenderFile;
#Override
protected synchronized void updateApplicationStatus(final int appStatus){
return;
}
#Override
protected GraphicsEngineHook getGraphicsEngineHook() {
return new MyGraphicsEngineHook();
}
#Override
protected int getSplashScreenImageResource() {
return R.drawable.splash_screen_image_targets;
}
}
I also tried including the activity I'm subclassing in my manifest like so, but I was still getting the same error:
<activity>
<android:name="com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity>
</activity>
Any ideas?
The problem is usually on the BuildPath.
Assuming you're using eclipse and ADT:
Right click on your project, select Build Path -> Configure Build Path -> Order and Export and make sure that your library is selected.
Remember to clean the project before trying again.
it could also be the class path as the guy suggested on the commented, on the manifest, instead of editing direct the XML, go to the Application tab, select the activity, click Browser, uncheck 'Display classes from sources of Project ...', and select the Activity from your library.

ACRA error reporting failed

I am using famous ACRA Error reporting tool to send crash logs to document which I have uploaded on my Google Doc.
I have followed all below steps mentioned in
https://github.com/ACRA/acra/wiki/BasicSetup
But still my application does not send error reports to document which I have uploaded.
I could see following error logs generated by ACRA.
01-01 02:11:19.995: E/ACRA(6054): ACRA caught a RuntimeException
exception for com.example.arcasample. Building report.
Below is my source code which I believe is flawless.
MyApplication.java
package com.example.arcasample;
import org.acra.ACRA;
import org.acra.ErrorReporter;
import org.acra.annotation.ReportsCrashes;
import android.app.Application;
#ReportsCrashes(formKey = "XXXX")
public class MyApplication extends Application
{
#Override
public void onCreate()
{
// ErrorReporter.getInstance().init(this); This is not helping me
ACRA.init(this);
super.onCreate();
}
}
MainActivity.java
package com.example.arcasample;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int a = 10 / 0; <= This will cause crash.
Log.i("vipul", "" + a);
}
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.arcasample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.arcasample.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Can someone please let me know if I am missing anything.
Thanks in advance.
Well I tried deleting form created on Google docs and recreated it.I wonder what mistake i had done before?.
Anyways recreating form and carefully noting down form key resolved my issue.

Android java.lang.NoClassDefFoundError when launching new activity

I am getting a java.lang.NoClassDefFoundError when I try to launch my new activity. Below is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.practice.googlemaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".LoginActivity"
android:label="Login to your Account">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegisterActivity"
android:label="Register New Account">
</activity>
<activity
android:name=".GoogleMapsActivity"
android:label="Google Maps">
</activity>
<uses-library android:name="com.google.android.maps"/>
</application>
</manifest>
Code for GoogleMapsActivity.java
package com.practice.googlemaps;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class GoogleMapsActivity extends MapActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView)findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
And the following is the line I'm using to launch the new activity:
Intent i = new Intent(getApplicationContext(), GoogleMapsActivity.class);
startActivity(i);
I have checked my class GoogleMapsActivity.java, the file is present and the spelling/wording all match.
I suspect the error may be caused by my AndroidManifest.xml, but I cannot find the problem.
Could someone please point me in the right direction?
Be sure that the <uses-library android:name="com.google.android.maps"/> is right location .
you are definitely missing to add one jar file so that the Noclassdeffound error
will show. and if u have add all jar file even then this error comes then i give you one best answer that definitely works. just create libs folder in ur project and add all jar file in libs folder and your problem definitely solves out.

Simple Hello Android.....not workign

EDIT: SOLVED I JUST HAD TO WAIT FOR AWHILE
So I followed the simple "Hello Android" tutorial:
http://developer.android.com/resources/tutorials/hello-world.html
got everything set up fine.....stuff works but when I go to actually run it.....it just says "Android_" in my virtual device....
I tried running it on 2.1 2.2 2.3.1 and 2.3.3 VD's and get the same thing?
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
Any ideas? My first venture into android is a failing one ;_;
PIC:
bigger:http://img.photobucket.com/albums/v720/bmw_pyro/Untitled-2.png
MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloAndroid"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
"Android _" is the first loading emulator splash screen, so you are saying that you get stuck there? If that's the case, that has nothing to do with your code.

Categories

Resources