• Register
search
Log In
0 votes
98 views

Problem :

I was trying to run a sample code While launching the application in the android 1.5 emulator , I got bellow errors.... Any one have any hint ?
java.lang.runtimeexception: unable to instantiate activity componentinfo
6.9k points

2 Answers

0 votes

Solution :

image

I unchecked the jars that needed be exported to the apk and this same thing happened. Please tick the jars that your app Needs to run.And your issue will be resolved.

Further Readings:

https://github.com/NativeScript/nativescript-dev-webpack/issues/285

36.1k points
edited by
0 votes

Solution:

Please include your Activity in your AndroidManifest.xml.

At the time you want to create a new activity, you must register it in your AndroidManifest.xml.

You may be attempting to find the view before onCreate() which is incorrect.

public class MainActivity extends Activity {

  ImageView mainImage = (ImageView) findViewById(R.id.imageViewMain); //incorrect

  @Override
  protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  }
  ...
}

There is another method to obtain an java.lang.RuntimeException: Unable to instantiate activity Component Info exception and that is the activity that you are attempting to begin is abstract. I made this stupid mistake at one time and its very simple to overlook.

In my instance I forgot to include the google maps library

<application>
    ....

    <uses-library android:name="com.google.android.maps" />
</application>

Further, check that you're not missing the former dot prior the activity path

<activity android:name=".activities.MainActivity"/>

This error can also be the ultimate sign of a dumb mistake (like when I - I imply, cough, like at the time a friend of mine who showed me their code once) where they attempt to execute code outside of a method like attempting to do this:

SQLiteDatabase db = openOrCreateDatabase("DB", MODE_PRIVATE, null); //trying to perform function where you can only set up objects, primitives, etc

@Override
public void onCreate(Bundle savedInstanceState) {
....
}

Rather than this:

SQLiteDatabase db;

@Override
public void onCreate(Bundle savedInstanceState) {
db = openOrCreateDatabase("DB", MODE_PRIVATE, null);
....
}

For me, my package string in AndroidManifest.xml was inaccurate . Ensure that the package string in this file is the similar as where your main activity is, for example

 package="com.example.app"

A simple method to do this is to open the AndroidManifest.xml file in the "Manifest" tab, and type it in the text box next to Package, or usage the Browse button.

Further, the package string for my activity was wrong, for example

<activity android:name="com.example.app.MainActivity" android:label="@string/app_name">

In case this is the instance, you require to include an extra configuration in the webpack.config.js file. To resolve the incident include `MainActivity: ./activity', to the entry in webpack.config.js like this:

const entry = {
    // Discover entry module from package.json
    bundle: `./${nsWebpack.getEntryModule()}`,
 
    // Vendor entry with third-party libraries
    vendor: `./vendor`,
 
    /// HERE
    MainActivity: './activity',
 
    // Entry for stylesheet with global application styles
    [mainSheet]: `./${mainSheet}`,
};

Remember that after you make those changes, you must remove node_modules and platforms folder before rebuilding the app.

12.8k points
edited by

Related questions

0 votes
1 answer 65 views
65 views
Problem : I am getting bellow error while trying to run my android code. java.lang.runtimeexception: unable to start activity componentinfo
asked Nov 2, 2019 peterlaw 6.9k points
0 votes
1 answer 223 views
223 views
Problem : I am getting bellow in Android Studio java.lang.runtimeexception: an error occurred while executing doinbackground()
asked Oct 19, 2019 peterlaw 6.9k points
0 votes
1 answer 63 views
63 views
Problem : While executing Android code getting below error java.lang.illegalstateexception could not execute method of the activity
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
2 answers 53 views
53 views
Problem : Currently I am working on my app for Android but I am getting following error while working with the SharedPreferences. I am very new to Android App Programming. I am trying to debug it from past 2 days but unable to find the solution ... " android:inputType="number" android:key="capitalownership" android:title="@string/capitalownership" /> Can somebody help me in resolving this error?
asked Feb 17 mphil 2.3k points
0 votes
1 answer 128 views
128 views
Problem : I am trying to learn Android programming also I am trying to develop a very basic weather app. My code works perfectly if I try to enter any valid city name. But I want to use the toast and it shows me the error and also to the ... .nextCleanInternal(JSONTokener.java:116) at org.json.JSONTokener.nextValue(JSONTokener.java:94) at org.json.JSONObject. How can I fix the above error?
asked Feb 14 mphil 2.3k points