Runtime error on newly created google map activity - java

I just created a new google map activity in android studio but its giving runtime error. i am also using firebase in this project. im not that new in android development but this is my first time using google maps api. kindly help
MapsActivity.java
package com.dreamfighter.roomrental;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney 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));
}
}
activty_maps.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dreamfighter.roomrental">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<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">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="i dont want my api key on stack overflow" />
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login" />
<activity
android:name=".RegisterActivity"
android:label="#string/title_activity_register" />
<activity android:name=".single_full_post" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps"></activity>
</application>
</manifest>
Error:
11-24 02:05:00.185 14219-14219/com.dreamfighter.roomrental E/BoostFramework: BoostFramework() : Exception_1 = java.lang.ClassNotFoundException: Didn't find class "com.qualcomm.qti.Performance" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
11-24 02:05:00.397 14219-14219/com.dreamfighter.roomrental E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dreamfighter.roomrental/com.dreamfighter.roomrental.MapsActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: calling Fragment constructor caused an exception
at android.support.v4.app.Fragment.instantiate(Fragment.java:481)
at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.inflate(LayoutInflater.java:496)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446)
at android.app.Activity.setContentView(Activity.java:2544)
at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20)
at android.app.Activity.performCreate(Activity.java:6942)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.support.v4.app.Fragment.instantiate(Fragment.java:459)
at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33) 
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664) 
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338) 
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:378) 
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446) 
at android.app.Activity.setContentView(Activity.java:2544) 
at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20) 
at android.app.Activity.performCreate(Activity.java:6942) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
Caused by: java.lang.IllegalAccessError: Class com.google.android.gms.dynamic.zza extended by class com.google.android.gms.maps.SupportMapFragment$zzb is inaccessible (declaration of 'com.google.android.gms.maps.SupportMapFragment$zzb' appears in /data/app/com.dreamfighter.roomrental-1/split_lib_dependencies_apk.apk:classes2.dex)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
at android.support.v4.app.Fragment.instantiate(Fragment.java:459) 
at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33) 
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664) 
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338) 
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:378) 
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446) 
at android.app.Activity.setContentView(Activity.java:2544) 
at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20) 
at android.app.Activity.performCreate(Activity.java:6942) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
--------- beginning of crash
11-24 02:05:00.397 14219-14219/com.dreamfighter.roomrental E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dreamfighter.roomrental, PID: 14219
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dreamfighter.roomrental/com.dreamfighter.roomrental.MapsActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: calling Fragment constructor caused an exception
at android.support.v4.app.Fragment.instantiate(Fragment.java:481)
at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.inflate(LayoutInflater.java:496)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446)
at android.app.Activity.setContentView(Activity.java:2544)
at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20)
at android.app.Activity.performCreate(Activity.java:6942)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.support.v4.app.Fragment.instantiate(Fragment.java:459)
at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33) 
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664) 
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338) 
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:378) 
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446) 
at android.app.Activity.setContentView(Activity.java:2544) 
at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20) 
at android.app.Activity.performCreate(Activity.java:6942) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
Caused by: java.lang.IllegalAccessError: Class com.google.android.gms.dynamic.zza extended by class com.google.android.gms.maps.SupportMapFragment$zzb is inaccessible (declaration of 'com.google.android.gms.maps.SupportMapFragment$zzb' appears in /data/app/com.dreamfighter.roomrental-1/split_lib_dependencies_apk.apk:classes2.dex)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
at android.support.v4.app.Fragment.instantiate(Fragment.java:459) 
at android.support.v4.app.FragmentContainer.instantiate(FragmentContainer.java:33) 
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3664) 
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338) 
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:784) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:496) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:378) 
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:446) 
at android.app.Activity.setContentView(Activity.java:2544) 
at com.dreamfighter.roomrental.MapsActivity.onCreate(MapsActivity.java:20) 
at android.app.Activity.performCreate(Activity.java:6942) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.dreamfighter.roomrental"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:12.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.master.android:glideimageview:1.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.android.gms:play-services:12.0.1'
}
apply plugin: 'com.google.gms.google-services'

I also had the same issue and I was resolved using the following steps.
It is mainly version issues. Firebase supports only latest versions. if you are using firebase analytics ( implementation 'com.google.firebase:firebase-core:16.0.1'), then we should use latest google services. so you are using 12.0.1, it would not support.
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
The above versions resolved my problem.

Solution Found:
Replace classpath 'com.google.gms:google-services:4.0.1' to classpath 'com.google.gms:google-services:3.2.1' in project level build.gradle file.
Update
Solution Found again:
Error came back again after i added some more dependencies. Just Update all dependencies to their latest versions and it will solve the problem.

Related

Can't make http request in android

I am trying to make a simple android app that makes a request to google, the expected behavior that my app should make a connection to google and then stop, what I got this error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 4431
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
at android.view.View.performClick(View.java:7339)
at android.widget.TextView.performClick(TextView.java:14275)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7305)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27787)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7078)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
at android.view.View.performClick(View.java:7339) 
at android.widget.TextView.performClick(TextView.java:14275) 
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119) 
at android.view.View.performClickInternal(View.java:7305) 
at android.view.View.access$3200(View.java:846) 
at android.view.View$PerformClick.run(View.java:27787) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7078) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1513)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:117)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:105)
at java.net.InetAddress.getAllByName(InetAddress.java:1154)
at com.android.okhttp.Dns$1.lookup(Dns.java:39)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:196)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:89)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:190)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:142)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:104)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:392)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:325)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:488)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
at com.example.myapplication.HttpRequest.request(HttpRequest.java:25)
at com.example.myapplication.MainActivity.onClick(MainActivity.java:64)
at java.lang.reflect.Method.invoke(Native Method) 
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409) 
at android.view.View.performClick(View.java:7339) 
at android.widget.TextView.performClick(TextView.java:14275) 
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119) 
at android.view.View.performClickInternal(View.java:7305) 
at android.view.View.access$3200(View.java:846) 
at android.view.View$PerformClick.run(View.java:27787) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7078) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 
I am working on android studio 4.1.2 with API 30,I am running the app on my phone with android 9 Pie.
My app has one button that makes a request, the that being executed is right here:
public void onClick(View view) {
try {
URL url = new URL("http://www.google.com/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
//do something
conn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
I have tried solutions that I found on internet but nothing work,I tried to edit my AndroidManifest.xml and I ended with this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:networkSecurityConfig="#xml/network_security_config"
android:usesCleartextTraffic="true"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MyApplication">
<activity android:name=".MainActivity2"></activity>
<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>
I created a file network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">google.com</domain>
</domain-config>
</network-security-config>
I am new to mobile development and I don't understand everything in the xml fils so maybe there is obvious mistake but I don't see it.
Thank you for your help.
According to your error log, your problem is you're attempting to connect to the internet on the main thread. Android does not allow you to setup an internet connection on the main thread because that would freeze up everything else while it makes the connection. You need to connect on a different thread.
EDIT: In light of AsyncTask being depreciated, the recommended alternatives appear to be using the interfaces contained in java.util.concurrent to make threads and/or threadpools or the coroutine libraries for Kotlin. Be sure to check the documentation and make a thread that establishes the connection in the background.

Android java.lang.RuntimeException: Parcelable encountered ClassNotFoundException reading a Serializable object

I'm trying to send the Serializable object from one application to another.
My android application has a serializable class
public class MyClass implements Serializable
and I then put one instance of it to the intent
MyClass myObject = new MyClass();
intent.putExtra("payItem", myObject);
intent.setAction("com.mypackage.some.action");
when I call startActiviy
startActivity(intent);
I got app crash
5-16 11:09:24.738 30673-30673/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: system:ui, PID: 30673
java.lang.RuntimeException: Unable to start activity ComponentInfo{android/com.android.internal.app.ResolverActivity}: java.lang.RuntimeException: Parcelable encountered ClassNotFoundException reading a Serializable object (name = com.mypackage.MyClass)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2955)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.RuntimeException: Parcelable encountered ClassNotFoundException reading a Serializable object (name = com.mypackage.MyClass)
at android.os.Parcel.readSerializable(Parcel.java:2956)
at android.os.Parcel.readValue(Parcel.java:2742)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3058)
at android.os.BaseBundle.unparcel(BaseBundle.java:257)
at android.os.Bundle.getParcelable(Bundle.java:888)
at android.content.Intent.getParcelableExtra(Intent.java:7734)
at android.app.Activity.getReferrer(Activity.java:5398)
at com.android.internal.app.ResolverActivity.getReferrerPackageName(ResolverActivity.java:554)
at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:435)
at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:331)
at android.app.Activity.performCreate(Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6938) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
Caused by: java.lang.ClassNotFoundException: com.mypackage.MyClass
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at android.os.Parcel$2.resolveClass(Parcel.java:2942)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1616)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1777)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:374)
at android.os.Parcel.readSerializable(Parcel.java:2950)
at android.os.Parcel.readValue(Parcel.java:2742) 
at android.os.Parcel.readArrayMapInternal(Parcel.java:3058) 
at android.os.BaseBundle.unparcel(BaseBundle.java:257) 
at android.os.Bundle.getParcelable(Bundle.java:888) 
at android.content.Intent.getParcelableExtra(Intent.java:7734) 
at android.app.Activity.getReferrer(Activity.java:5398) 
at com.android.internal.app.ResolverActivity.getReferrerPackageName(ResolverActivity.java:554) 
at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:435) 
at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:331) 
at android.app.Activity.performCreate(Activity.java:7174) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6938) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mypackage.MyClass" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/vendor/lib64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:453) 
at android.os.Parcel$2.resolveClass(Parcel.java:2942) 
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1616) 
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521) 
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1777) 
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354) 
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:374) 
at android.os.Parcel.readSerializable(Parcel.java:2950) 
at android.os.Parcel.readValue(Parcel.java:2742) 
at android.os.Parcel.readArrayMapInternal(Parcel.java:3058) 
at android.os.BaseBundle.unparcel(BaseBundle.java:257) 
at android.os.Bundle.getParcelable(Bundle.java:888) 
at android.content.Intent.getParcelableExtra(Intent.java:7734) 
at android.app.Activity.getReferrer(Activity.java:5398) 
at com.android.internal.app.ResolverActivity.getReferrerPackageName(ResolverActivity.java:554) 
at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:435) 
at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:331) 
at android.app.Activity.performCreate(Activity.java:7174) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6938) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
Actually my phone has installed two applications with both register an activity
with the same action name
<activity
android:name="com.mypackage.MyActivity"
android:exported="true"
>
<intent-filter>
<action android:name="com.mypackage.some.action"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
I would expect a dialog shown to let me choose which activity should be started, but I just got the error above. If I uninstall one of the applications, no error occurs and it runs as expected.
My question is
Why the dialog is not shown
Is it the reason of the crash
What's the solution to avoid that error if the two applications are both installed

Virtual phone error : "App has stopped working"

I have the following github project
GITHUB file Project
Every time I run the app on a virtual phone through android studio it comes up with "App has stopped working". I have updated android studio.
The errors which keep arising in the logcat are as follow:
05.182 4961-4961/app.monmos E/AndroidRuntime: FATAL EXCEPTION: main
Process: app.monmos, PID: 4961
java.lang.RuntimeException: Unable to start activity ComponentInfo{app.monmos/app.monmos.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at app.monmos.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
at android.content.res.TypedArray.getColor(TypedArray.java:473)
at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
at info.hoang8f.widget.FButton.<init>(FButton.java:52)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:334) 
at android.view.LayoutInflater.createView(LayoutInflater.java:647) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at app.monmos.MainActivity.onCreate(MainActivity.java:19) 
at android.app.Activity.performCreate(Activity.java:6999) 
at android.app.Activity.performCreate(Activity.java:6990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
I have also updated the gradle version and still nothing is working.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#drawable/backgroundimage"
tools:context="app.monmos.Signin">
<LinearLayout
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2">
<com.rengwuxian.materialedittext.MaterialAutoCompleteTextView
android:id="#+id/edtphone"
android:hint ="Phone Number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text ="00000001"
android:textColorHint="#android:color/white"
android:textColor="#android:color/white"
android:textSize="34sp"
android:inputType="phone"
app:met_baseColor="#android:color/white"
app:met_floatingLabel="highlight"
app:met_primaryColor="#android:color/white"
app:met_singleLineEllipsis = "true"
/>
<com.rengwuxian.materialedittext.MaterialAutoCompleteTextView
android:id="#+id/edtPassword"
android:hint ="Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text ="1234"
android:textColorHint="#android:color/white"
android:textColor="#android:color/white"
android:textSize="34sp"
android:inputType="phone"
app:met_baseColor="#android:color/white"
app:met_floatingLabel="highlight"
app:met_primaryColor="#android:color/white"
app:met_singleLineEllipsis = "true"
/>
</LinearLayout>
<info.hoang8f.widget.FButton
android:id="#+id/btnSignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:text="Sign In"
android:textColor="#android:color/white"
app:buttonColor="#color/btsSignActive"
app:cornerRadius="4dp"
app:shadowColor="#android:color/black"
app:shadowEnabled="true"
app:shadowHeight="5dp" />
//Added grade file
</RelativeLayout>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3' +
'.0.1'
classpath 'com.google.gms:google-services:3.1.0'
// 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
}
You don't have maven set up in your project's gradle file. Your gradle file should look like this:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Error inflating class info.hoang8f.widget.FButton

Error Log:
10-26 12:22:33.144 26926-26926/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: ksmk.sahip.com.ecom, PID: 26926
java.lang.RuntimeException: Unable to start activity ComponentInfo{ksmk.sahip.com.ecom/ksmk.sahip.com.ecom.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at ksmk.sahip.com.ecom.MainActivity.onCreate(MainActivity.java:36)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
at android.content.res.TypedArray.getColor(TypedArray.java:463)
at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
at info.hoang8f.widget.FButton.(FButton.java:52)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at ksmk.sahip.com.ecom.MainActivity.onCreate(MainActivity.java:36)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
10-26 12:22:33.692 1305-1305/? E/EGL_emulation: tid 1305: eglCreateSyncKHR(1901): error 0x3004 (EGL_BAD_ATTRIBUTE)
use this dependency this is will solve error
implementation 'com.github.jd-alexander:android-flat-button:v1.1'
use this in code for casting the button
Button btn_CreateNewVideo;
btn_CreateNewVideo = (FButton) findViewById(R.id.createnewvideo);
As of this time the problem occurs in android gradle plugin version 3.0.0. So just change the android gradle plugin version to 2.3.3. You can change it in build.gradle (Project level) file, like:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
If you have updated your android studio version to 3.o then go to file -> Project Structure -> Project -> Change gradle plugin version to 2.3.0 and gradle version to 3.3
I hope this helps
Same Flat FButton theme can be found here:
Use the library as a dependency https://github.com/jd-alexander/android-flat-button
https://jitpack.io/#jd-alexander/android-flat-button/v1.1
dependencies {
implementation 'com.github.jd-alexander:android-flat-button:v1.1'
}
Another solution I have found
Change for:
Dependence {
implementation 'info.hoang8f:android-segmented:1.0.6'
}
or
You can change casting (FButton) to (Button) with same previous dependency
So, some time ago I've got the exactly same error 'cause my Android Studio Version is higher than the version for which info.hoang8f was implemented, so, step-by-step how to fix it:
In your build.gradle project:level add this line inside allprojects -> repositories: maven { url 'https://jitpack.io' }
In your build.gradle app:level add this line in dependencies: implementation 'com.github.jd-alexander:android-flat-button:v1.1'
Remove the implementation line of 'info.hoang8f...' and Clean Project;
Remember, this new implementation use fButtonColor, so, you need to change in your XML files app:buttonColor='#color/someColor' to: app:fButtonColor='#color/someColor'
Do not:
Change your Gradle Version, this can raise some implementation errors;

java.lang.NoSuchFieldError: No static field KL of type Lcom/google/android/gms/internal/zzsb$zzb

I'm trying to open a Camera Activity on my Android but I got this error when the Activity starts:
FATAL EXCEPTION: main
Process: bookreader.bookreader, PID: 19132
java.lang.NoSuchFieldError: No static field KL of type Lcom/google/android/gms/internal/zzsb$zzb; in class Lcom/google/android/gms/internal/zzsb; or its superclasses (declaration of 'com.google.android.gms.internal.zzsb' appears in /data/app/bookreader.bookreader-1/split_lib_dependencies_apk.apk:classes4.dex)
at com.google.android.gms.vision.text.internal.client.zze.zzcic(Unknown Source)
at com.google.android.gms.vision.text.internal.client.zze.<init>(Unknown Source)
at com.google.android.gms.vision.text.TextRecognizer$Builder.build(Unknown Source)
at bookreader.bookreader.CameraActivity.onCreate(CameraActivity.java:97)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
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)
I don't know how to solve it. In my Android Manifest, I have this:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
make sure everything is up to date inside your build.gradle
no such method/field/class error usually occur because of dependency version mismatch (obfuscated fields names may be different across versions)

Categories