I’m new to android. I built an application in which there is a Button
which starts an Activity
and there are two more Buttons
in that Activity
which will open two seperate activities. One of that Activity
contains Google map named as nearby search. When I start the nearby search the app is crashing while this Activity
was running perfectly before integrating the map.
Here is the log cat
04-02 02:32:40.354: E/AndroidRuntime(22037): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jamaat_times/com.example.jamaattiming.NearbySearch}: java.lang.NullPointerException
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.app.ActivityThread.access$600(ActivityThread.java:162)
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.os.Handler.dispatchMessage(Handler.java:107)
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.os.Looper.loop(Looper.java:194)
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.app.ActivityThread.main(ActivityThread.java:5371)
04-02 02:32:40.354: E/AndroidRuntime(22037): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 02:32:40.354: E/AndroidRuntime(22037): at java.lang.reflect.Method.invoke(Method.java:525)
04-02 02:32:40.354: E/AndroidRuntime(22037): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
04-02 02:32:40.354: E/AndroidRuntime(22037): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-02 02:32:40.354: E/AndroidRuntime(22037): at dalvik.system.NativeStart.main(Native Method)
04-02 02:32:40.354: E/AndroidRuntime(22037): Caused by: java.lang.NullPointerException
04-02 02:32:40.354: E/AndroidRuntime(22037): at com.example.jamaattiming.NearbySearch.onCreate(NearbySearch.java:36)
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.app.Activity.performCreate(Activity.java:5122)
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
04-02 02:32:40.354: E/AndroidRuntime(22037): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
04-02 02:32:40.354: E/AndroidRuntime(22037): ... 11 more
here is the java file:
public class NearbySearch extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nearby_search);
GoogleMapOptions mapOptions = new GoogleMapOptions();
GoogleMap maps=(((MapFragment) getFragmentManager().findFragmentById(R.id.map2)).getMap());
mapOptions.mapType(GoogleMap.MAP_TYPE_HYBRID);
//maps.setMapType(GoogleMap.MAP_TYPE_HYBRID);
maps.setMyLocationEnabled(true);
maps.addMarker(new MarkerOptions()
.position(new LatLng(24.9967 , 66.1234))
.title("Hello world"));
}
}
here is the xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#808080">
<fragment
android:id="@+id/map2"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
and here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jamaat_times"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_jamaat"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.jamaattiming.Splash"
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="com.example.jamaattiming.MainPage"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.jamaattiming.Qibla"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="com.example.COMPASS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.jamaattiming.JamaatFinder"
android:label="@string/title_activity_jamaat_finder" >
</activity>
<activity
android:name="com.example.jamaattiming.QiblaFinder"
android:label="@string/title_activity_qibla_finder" >
</activity>
<activity
android:name="com.example.jamaattiming.TagYourself"
android:label="@string/title_activity_tag_yourself" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.jamaattiming.NearbySearch"
android:label="@string/title_activity_nearby_search" >
</activity>
<activity
android:name="com.example.jamaattiming.ManualSearch"
android:label="@string/title_activity_manual_search" >
</activity>
</application>
</manifest>
I am creating an android application consists of progress bar downloaded from here but i am getting an error called java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.milanprogress/com.example.milanprogress.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class is.arontibo.library.ElasticDownloadView
can any one tell me how to overcome this
This is my activity:
package com.example.milanprogress;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import is.arontibo.library.ElasticDownloadView;
import is.arontibo.library.ProgressDownloadView;
public class MainActivity extends Activity {
ElasticDownloadView elastic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
elastic = (ElasticDownloadView)findViewById(R.id.elastic_download_view);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_run_success_animation) {
new Handler().post(new Runnable() {
@Override
public void run() {
elastic.startIntro();
}
});
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
elastic.success();
}
}, 2*ProgressDownloadView.ANIMATION_DURATION_BASE);
return true;
} else if (id == R.id.action_run_fail_animation) {
new Handler().post(new Runnable() {
@Override
public void run() {
elastic.startIntro();
}
});
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
elastic.setProgress(45);
}
}, 2*ProgressDownloadView.ANIMATION_DURATION_BASE);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
elastic.fail();
}
}, 3*ProgressDownloadView.ANIMATION_DURATION_BASE);
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is my xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:elastic="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.milanprogress.MainActivity" >
<is.arontibo.library.ElasticDownloadView
android:id="@+id/elastic_download_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
This is my Logcat:
01-02 08:04:43.980: E/AndroidRuntime(30127): FATAL EXCEPTION: main
01-02 08:04:43.980: E/AndroidRuntime(30127): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.milanprogress/com.example.milanprogress.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class is.arontibo.library.ElasticDownloadView
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.os.Looper.loop(Looper.java:137)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-02 08:04:43.980: E/AndroidRuntime(30127): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 08:04:43.980: E/AndroidRuntime(30127): at java.lang.reflect.Method.invoke(Method.java:525)
01-02 08:04:43.980: E/AndroidRuntime(30127): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-02 08:04:43.980: E/AndroidRuntime(30127): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-02 08:04:43.980: E/AndroidRuntime(30127): at dalvik.system.NativeStart.main(Native Method)
01-02 08:04:43.980: E/AndroidRuntime(30127): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class is.arontibo.library.ElasticDownloadView
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-02 08:04:43.980: E/AndroidRuntime(30127): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.app.Activity.setContentView(Activity.java:1895)
01-02 08:04:43.980: E/AndroidRuntime(30127): at com.example.milanprogress.MainActivity.onCreate(MainActivity.java:20)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.app.Activity.performCreate(Activity.java:5133)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-02 08:04:43.980: E/AndroidRuntime(30127): ... 11 more
01-02 08:04:43.980: E/AndroidRuntime(30127): Caused by: java.lang.reflect.InvocationTargetException
01-02 08:04:43.980: E/AndroidRuntime(30127): at java.lang.reflect.Constructor.constructNative(Native Method)
01-02 08:04:43.980: E/AndroidRuntime(30127): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-02 08:04:43.980: E/AndroidRuntime(30127): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
01-02 08:04:43.980: E/AndroidRuntime(30127): ... 22 more
01-02 08:04:43.980: E/AndroidRuntime(30127): Caused by: java.lang.NoClassDefFoundError: is.arontibo.library.R$styleable
01-02 08:04:43.980: E/AndroidRuntime(30127): at is.arontibo.library.ElasticDownloadView.<init>(ElasticDownloadView.java:30)
01-02 08:04:43.980: E/AndroidRuntime(30127): ... 25 more
asked Jun 30, 2015 at 12:23
6
You might have not included that lib properly in your build path. Try re adding that lib with a clean and make sure you have added all the styleables , layouts , colors XML files which are included with that library. This seems like you have not added this library properly.
answered Jun 30, 2015 at 12:40
rd7773rd7773
4093 silver badges13 bronze badges
In your xml, try to close with a tag like this :
<is.arontibo.library.ElasticDownloadView
android:id="@+id/elastic_download_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"></is.arontibo.library.ElasticDownloadView>
The problem seems to happen in ElasticDownloadView. Check line 30 of source code. The library seems to use a resource called R.styleable.ColorOptionsView_backgroundColor
, that you have probably not defined.
EDIT
Well if you imported the whole project in Eclipse and set it as «library» (check http://developer.android.com/tools/projects/projects-eclipse.html)
you should be good. If you have still errors, try to modify the code inside the library. On line 30 change :
mBackgroundColor = a.getColor(R.styleable.ColorOptionsView_backgroundColor,
R.color.orange_salmon);
to
mBackgroundColor = Color.WHITE;
Once it’s done, run and post your LogCat again if you still have issues.
answered Jun 30, 2015 at 12:26
GordakGordak
2,06022 silver badges32 bronze badges
6
Your stack says the error is
java.lang.NoClassDefFoundError
Here is the solution of same problem just used library is diffrent
http://stackoverflow.com/questions/26494346/error-inflating-class-and-android-support-v7-widget-cardview
answered Jun 30, 2015 at 13:11
Adi TiwariAdi Tiwari
7611 gold badge5 silver badges17 bronze badges
Take a look at the last lines of your logs:
Caused by: java.lang.NoClassDefFoundError: is.arontibo.library.R$styleable
Styleable properties are missing!!
Please make sure to have this defined in the library if you imported it:
<declare-styleable name="ColorOptionsView">
<attr name="backgroundColor" format="color" />
</declare-styleable>
in the attrs.xml file.
answered Jul 9, 2015 at 13:43
TíbóTíbó
1,18813 silver badges28 bronze badges
В чём ошибка не понимаю?
Ошибка скажите что она имеет ввиду
java.lang.RuntimeException: Unable to resume activity {com.example.location/com.example.location.MainActivity}: java.lang.SecurityException: «gps» location provider requires ACCESS_FINE_LOCATION permission.
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3824)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3856)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6826)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.SecurityException: «gps» location provider requires ACCESS_FINE_LOCATION permission.
at android.os.Parcel.createException(Parcel.java:1953)
at android.os.Parcel.readException(Parcel.java:1921)
at android.os.Parcel.readException(Parcel.java:1871)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:755)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:1019)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:562)
at com.example.location.MainActivity.onResume(MainActivity.java:46)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1413)
at android.app.Activity.performResume(Activity.java:7400)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3816)
… 11 more
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.LocationManagerService.checkResolutionLevelIsSufficientForProviderUse(LocationManagerService.java:1568)
at com.android.server.LocationManagerService.requestLocationUpdates(LocationManagerService.java:2156)
at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:72)
at android.os.Binder.execTransact(Binder.java:731)
-
Вопрос заданболее двух лет назад
-
809 просмотров
Пригласить эксперта
Все написано. Не выдано разрешение на доступ к местоположению (выдаётся пользователем по запросу или в настройках).
-
Показать ещё
Загружается…
22 июн. 2023, в 00:59
8000 руб./за проект
22 июн. 2023, в 00:56
8000 руб./за проект
22 июн. 2023, в 00:39
12000 руб./за проект
Минуточку внимания

Today, we will learn about another runtime exception that says Unable to instantiate activity ComponentInfo
.
We will explore different possible reasons that result in java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
. Finally, we will have a solution to eradicate it.
Resolve the java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
Error
Example Code for Error Demonstration (MainActivity.java
file):
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//write your remaining code here
}
Example Code (AndroidManifest.xml
file):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.app">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.App"
tools:targetApi="31">
<activity
android:name="MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When we try to run this while launching an application in the android emulator, we get the error saying java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
.
There are a few possible causes that we must consider to resolve this. All of them are listed below.
-
Make sure that your
Activity
is added to theAndroidManifest.xml
file. Why is it necessary?It is because whenever we want to make a new
Activity
, we must register in ourAndroidManifest.xml
file. Also, verify all the access modifiers. -
We also get this error when we try to view before
onCreate()
, which is incorrect and results in an error stating unable to instantiate activity component info error. -
Another reason for getting
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
is that we have added ourActivity
inAndroidManifest.xml
, which is declared asabstract
. In other words, we can say that theActivity
we are trying to access is declaredabstract
. -
Make sure that we are not missing a preceding dot before an activity path (this thing is causing an error in the example code given above).
-
We also have to face this error if we did not declare our
MainActivity.java
file aspublic
. Also, check if your file is in the right package or not.
Now, we know all the possible reasons. How can we fix it?
See the following solution.
Example Code for Solution (MainActivity.java
file):
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//write your remaining code here
}
Example Code (AndroidManifest.xml
file):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.app">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.App"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
We have added a preceding dot before an activity path. We also confirm that our MainActivity.java
file is declared as public
, and we are not trying to access an Activity
declared as abstract
.
Be careful of all the points given as causes because those points are actual solutions if we consider them.