My app runs properly on simulator for Android 5.0.0 (Genymotion), but it crashes on all other lower API. MultiDex support has been added to mainactivity.java and build.gradle but it did not fix it.
Kindly advice.
build.gradle
android {
compileSdkVersion 21
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "gym.myapp"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7}
buildTypes {
release {minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' }
debug {
debuggable true}}
productFlavors {}}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:cardview-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:multidex:1.0.0'}
Mainactivity.java
public class MainActivity extends ListActivity {
protected ImageButton composeButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
composeButton=(ImageButton)findViewById(R.id.mainComposeButton);}
#Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }
activity_main.XML
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mainComposeButton"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:minHeight="60dp"
android:minWidth="60dp"
android:layout_margin="8dp"
android:layout_gravity="center_vertical|end|center"
android:src="#drawable/ic_content_create"
LogCat
java.lang.RuntimeException: Unable to start activity ComponentInfo{gym.myapp/gym.myApp.MainActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class android.widget.ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class android.widget.ImageButton
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at gym.myapp.MainActivity.onCreate(MainActivity.java:73)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
Related
I have a very frustrating error. The application was running just fine till yesterday, I closed android studio then when I opened it today it showed this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication11, PID: 29530
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication11/com.example.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class androidx.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2506)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5491)
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)
Caused by: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class androidx.fragment.app.FragmentContainerView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:19)
at android.app.Activity.performCreate(Activity.java:6270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2506)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5491)
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)
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class androidx.fragment.app.FragmentContainerView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:19)
at android.app.Activity.performCreate(Activity.java:6270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2506)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5491)
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)
Caused by: java.lang.IllegalStateException: Fragment class was not set
at androidx.navigation.fragment.FragmentNavigator$Destination.getClassName(FragmentNavigator.java:322)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:158)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:58)
at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.java:71)
at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.java:28)
at androidx.navigation.NavController.navigate(NavController.java:1057)
at androidx.navigation.NavController.onGraphCreated(NavController.java:637)
at androidx.navigation.NavController.setGraph(NavController.java:590)
at androidx.navigation.NavController.setGraph(NavController.java:555)
at androidx.navigation.NavController.setGraph(NavController.java:537)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:248)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2685)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2236)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2009)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1965)
at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1830)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
at androidx.fragment.app.FragmentContainerView.<init>(Frag
The activity_main layout in which this error is popping up is :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#color/design_default_color_primary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</androidx.appcompat.widget.Toolbar>
// This is the line 22 in error
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
app:navGraph="#navigation/nav_graph" >
</androidx.fragment.app.FragmentContainerView>
</androidx.constraintlayout.widget.ConstraintLayout>
I want to point out that the third line in error
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication11/com.example.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class androidx.fragment.app.FragmentContainerView
this part "{com.example.myapplication11/com.example.myapplication.MainActivity}". I dont know why it shows myapplication11 here my apps name is just myapplication... my application11 was an old project I was working on so is it related to that?
My activitymain.kt file is
package com.example.myapplication
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.onNavDestinationSelected
import androidx.navigation.ui.setupActionBarWithNavController
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
private lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navController = navHostFragment.findNavController()
setSupportActionBar(toolbar)
setupActionBarWithNavController(navController)
}
override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp() || super.onSupportNavigateUp()
}
}
Gradle build (MODULE) file is
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'androidx.navigation.safeargs.kotlin'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapplication11"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.fragment:fragment-ktx:1.2.5'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Gradle build file (project):
buildscript {
ext.kotlin_version = "1.3.72"
ext.nav_version = "2.3.0"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
So, In your activity_main.xml file..
Change: android:name="androidx.navigation.fragment.NavHostFragment"
To: class = "androidx.navigation.fragment.NavHostFragment"
I have this strange error I do not know how to resolve. I test my App in my phone samsung j5 (Marshmellow) and it's working ok. But now i'm testing it in samsung j3 (lollipop) the app crash as startup and the error is this one:
10-02 22:28:59.426 4395-4395/com.example.sony.snapcamera E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sony.snapcamera, PID: 4395
java.lang.RuntimeException: Unable to instantiate application com.example.sony.snapcamera.App: java.lang.ClassNotFoundException: Didn't find class "com.example.sony.snapcamera.App" on path: DexPathList[[zip file "/data/app/com.example.sony.snapcamera-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.sony.snapcamera-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:661)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6002)
at android.app.ActivityThread.access$1700(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6934)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.sony.snapcamera.App" on path: DexPathList[[zip file "/data/app/com.example.sony.snapcamera-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.sony.snapcamera-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newApplication(Instrumentation.java:1003)
at android.app.LoadedApk.makeApplication(LoadedApk.java:651)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6002)
at android.app.ActivityThread.access$1700(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6934)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Suppressed: java.lang.NoClassDefFoundError: com.example.sony.snapcamera.App
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:321)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 14 more
Suppressed: java.lang.ClassNotFoundException: com.example.sony.snapcamera.App
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
This is my AndroidManifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sony.snapcamera">
.....
<application
android:name="com.example.sony.snapcamera.App"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/App_icon"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme"
>
...
This is my App class :
package com.example.sony.snapcamera;
import android.app.Application;
import android.content.Context;
import com.adobe.creativesdk.foundation.AdobeCSDKFoundation;
import com.adobe.creativesdk.foundation.auth.IAdobeAuthClientCredentials;
import com.bumptech.glide.request.target.ViewTarget;
public class App extends Application implements IAdobeAuthClientCredentials {
/* Be sure to fill in the two strings below. */
private static final String CREATIVE_SDK_CLIENT_ID = "";
private static final String CREATIVE_SDK_CLIENT_SECRET = "";
private static final String CREATIVE_SDK_REDIRECT_URI = "";
private static final String[] CREATIVE_SDK_SCOPES = {"email", "profile", "address"};
#Override
public void onCreate() {
super.onCreate();
ViewTarget.setTagId(R.id.glide_tag);
AdobeCSDKFoundation.initializeCSDKFoundation(getApplicationContext());
}
#Override
public String getClientID() {
return CREATIVE_SDK_CLIENT_ID;
}
#Override
public String getClientSecret() {
return CREATIVE_SDK_CLIENT_SECRET;
}
#Override
public String[] getAdditionalScopesList() {
return CREATIVE_SDK_SCOPES;
}
#Override
public String getRedirectURI() {
return CREATIVE_SDK_REDIRECT_URI;
}
}
Here it is my app gradle :
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
}
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.sony.snapcamera"
minSdkVersion 21
targetSdkVersion 25
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
manifestPlaceholders = [appPackageName: "${applicationId}"]
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
pickFirst 'AndroidManifest.xml'
}
dexOptions {
jumboMode true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.makeramen:roundedimageview:2.2.1'
compile 'com.github.XunMengWinter:CircularAnim:0.3.4'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.zomato:androidphotofilters:1.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:design:25.3.1'
compile 'com.github.chrisbanes:PhotoView:1.3.1'
compile 'com.writingminds:FFmpegAndroid:0.3.2'
compile 'com.google.firebase:firebase-database:11.4.0'
compile 'com.google.android.gms:play-services:11.4.0'
compile 'com.google.maps.android:android-maps-utils:0.4.3'
compile 'com.firebaseui:firebase-ui:0.4.0'
compile 'com.google.firebase:firebase-auth:11.4.0'
compile 'com.google.firebase:firebase-crash:11.4.0'
compile 'com.google.code.gson:gson:2.8.1'
// compile 'com.firebase:geofire-android:2.1.1'
compile 'com.algolia:algoliasearch-android:3.10.1'
// compile 'com.android.support:cardview-v7:25.1.1'
/* Add the CSDK framework dependencies (Make sure these version numbers are correct) */
compile 'com.adobe.creativesdk.foundation:auth:0.9.1251'
compile 'com.adobe.creativesdk:image:4.8.4'
compile 'com.localytics.android:library:3.8.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
I already tested to clean and rebuild project, I also tested to disable instant run but nothing worked for me, I can't even realise the problem because it works very good in j5 and it crash in j3, Please help.
enable multidex,
1. Add following dependency in app gradle file compile
'com.android.support:multidex:1.0.1' and
defaultConfig {
multiDexEnabled true
}
2. Your application class need to extends MultiDexApplication
I am trying to configure maps in my app but i am getting a fatal exception. I have obtained the google API key and added it to the manifest file.
My XML file layout is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.aadesh.maps.MainActivity">
<com.google.android.gms.maps.MapFragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="201dp"
android:id="#+id/mapFragment" />
There was also some rendering problems in the layout.
The main activity is:
public class MainActivity extends FragmentActivity implements OnMapReadyCallback {
GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
//add a marker and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
Here is my logcat error:
FATAL EXCEPTION: main
Process: com.example.aadesh.maps, PID: 6677
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aadesh.maps/com.example.aadesh.maps.MainActivity}: android.view.InflateException: Binary XML file line #13: Class is not a View com.google.android.gms.maps.MapFragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$900(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5511)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #13: Class is not a View com.google.android.gms.maps.MapFragment
at android.view.LayoutInflater.createView(LayoutInflater.java:617)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:366)
at android.app.Activity.setContentView(Activity.java:2009)
at com.example.aadesh.maps.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:5322)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2303)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$900(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5511)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.view.View
at java.lang.Class.asSubclass(Class.java:1259)
at android.view.LayoutInflater.createView(LayoutInflater.java:565)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:366)
at android.app.Activity.setContentView(Activity.java:2009)
at com.example.aadesh.maps.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:5322)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2303)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$900(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5511)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
What could be the problem and how do i solve this?
Here is the gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.aadesh.maps"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-maps:9.8.00'
}
Please use fragment instead of MapFragment Class in XML file. Change as below code
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="201dp"
android:id="#+id/mapFragment" />
I'm using lastest AndroidAnnotations 4.1.0(link) and try to change appcompat to 24.2.1 to support targetVersion 24. But, My app is crashed when using appcompat-v7 version 23+, however, it runs normally on appcompat-v7:22.2.0. Any suggestion is appriciated. Below is my error logs:
FATAL EXCEPTION: main
Process: ABC, PID: 1275
java.lang.RuntimeException: Unable to start activity ComponentInfo{MyPackage/MyPackage.activities.MainActivity_}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5137)
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:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at MyPackage.activities.MainActivity_.setContentView(MainActivity_.java:51)
at MyPackage.activities.MainActivity_.onCreate(MainActivity_.java:40)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5137)
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:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Must specify unique android:id, android:tag, or have a parent with an id for MyPackage.fragments.MainFragment_
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2387)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:376)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at MyPackage.activities.MainActivity_.setContentView(MainActivity_.java:51)
at MyPackage.activities.MainActivity_.onCreate(MainActivity_.java:40)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5137)
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:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718)
at dalvik.system.NativeStart.main(Native Method)
And this is my gradle
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
...
def PACKAGE_NAME = "MyPackage"
def VERSION_CODE = 1
def VERSION_NAME = "1.0.0"
def AAVersion = '4.1.0'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
buildscript {
repositories {
mavenCentral()
...
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:2.2.0'
// replace with the current version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
...
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName PACKAGE_NAME
}
}
repositories {
mavenCentral()
...
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId PACKAGE_NAME
minSdkVersion 14
targetSdkVersion 24
versionCode VERSION_CODE
versionName VERSION_NAME
// Enabling multidex support.
multiDexEnabled true
}
signingConfigs {
...
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
...
}
dexOptions {
...
}
...
}
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
...
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-maps:9.6.1'
compile 'com.google.android.gms:play-services-location:9.6.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
compile('com.squareup.okhttp3:okhttp:3.2.0') {
exclude module: 'okhttp'
}
compile 'io.reactivex:rxandroid:1.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.github.mrmike:ok2curl:0.2.3'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.android.support:multidex:1.0.1'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2#aar') {
transitive = true;
}
}
repositories {
flatDir {
dirs 'libs'
}
}
As it is an be ready from the stack trace, the problem is that you did not add any ID neither a tag for your Fragment in the xml layout where you declare an instance if it. The Fragment in question is MyPackage.fragments.MainFragment_. This is a standard error, not related to AndroidAnnotations.
<fragment android:name="MyPackage.fragments.MainFragment_"
android:id="#+id/fragment_id" <!-- Add an ID -->
android:layout_width="match_parent"
android:layout_height="match_parent" />
I am trying to use MapFragment in ViewPager. Although I defined FragmentManager as SupportFragmentManager, if I slide to the page contains MapFragment, I see InflateException. I read most of the titles mentioned this issue but cannot see a solution yet. I hope you can. Here is the layout of my MapFragment class:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="7dp"
android:orientation="vertical"
android:gravity="left">
<ImageButton
android:id="#+id/searchButton"
android:background="#drawable/search_button"
android:layout_marginTop="10dp"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentTop="true"/>
<ImageButton
android:id="#+id/originButton"
android:background="#drawable/origin_button"
android:layout_marginBottom="10dp"
android:layout_marginRight="7dp"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true"/>
<ImageButton
android:id="#+id/earthButton"
android:background="#drawable/earth_button"
android:layout_marginBottom="10dp"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/originButton"/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginRight="14dp"
android:orientation="vertical"
android:gravity="right" >
<ImageButton
android:id="#+id/plusButton"
android:background="#drawable/plus_button"
android:layout_centerInParent="true"
android:layout_width="50dip"
android:layout_height="50dip"/>
<View
android:layout_width="0dp"
android:layout_height="7dp"
android:layout_weight="1"/>
<ImageButton
android:id="#+id/minusButton"
android:background="#drawable/minus_button"
android:layout_centerInParent="true"
android:layout_width="50dip"
android:layout_height="50dip"/>
</LinearLayout>
</RelativeLayout>
The log:
Process: net.geotune.app, PID: 17582
android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at net.geotune.app.dorukhan.MapFragment.onCreateView(MapFragment.java:177)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1302)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:729)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:555)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:514)
at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:495)
at net.geotune.app.main.MainPager.onTabSelected(MainPager.java:95)
at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:578)
at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:1108)
at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:556)
at android.view.View.performClick(View.java:4478)
at android.view.View$PerformClick.run(View.java:18698)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5268)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f090093, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2164)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory.onCreateView(CalligraphyLayoutInflater.java:249)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:163)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at net.geotune.app.dorukhan.MapFragment.onCreateView(MapFragment.java:177)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1302)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:729)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:555)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:514)
at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:495)
at net.geotune.app.main.MainPager.onTabSelected(MainPager.java:95)
at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:578)
at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:1108)
at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:556)
at android.view.View.performClick(View.java:4478)
at android.view.View$PerformClick.run(View.java:18698)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5268)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
I got the error in the following segment of ViewPager's class:
#Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
viewPager.setCurrentItem(tab.getPosition());
}
Lastly, build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
defaultConfig {
applicationId 'net.geotune.app'
minSdkVersion 19
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.spotify.sdk:spotify-player:1.0.0-beta9#aar'
compile 'com.spotify.sdk:spotify-auth:1.0.0-beta9#aar'
compile files('libs/Android/android-async-http-1.3.1.jar')
compile files('libs/Android/jackson-core-asl-1.8.5.jar')
compile files('libs/Android/jackson-mapper-asl-1.8.5.jar')
compile files('libs/Android/KumulosAndroid.0.2.3.jar')
compile files('libs/spotify-web-api-android-0.1.0.jar')
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile group: 'io.orchestrate', name: 'orchestrate-client', version: '0.9.0'
compile 'uk.co.chrisjenx:calligraphy:2.0.2'
compile 'com.sothree.slidinguppanel:library:3.0.0'
}
I know I added too much code above, I am sorry for that. I just want to leave no stone unturned.
There is not problem with neither gradle nor layout file. MapFragment's onCreateView() should be set as follows:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (container == null)
return null;
if (v != null) {
ViewGroup parent = (ViewGroup) v.getParent();
if (parent != null)
parent.removeView(v);
}
try {
v = inflater.inflate(R.layout.fragment_map, container, false);
} catch (InflateException e) { }
mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
if (mapFragment != null) {
mapFragment.onCreate(savedInstanceState);
mapFragment.onResume();
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
googleMap = mapFragment.getMap();
// Do whatever you want on map here
}
return v;
}
This problem is thoroughly discussed in this question. Thus, I did not explain the code segment in detail.