• Register
0 votes
134 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 5 3
6,930 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

9 7 4
38,600 points
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.

10 6 4
31,120 points

Related questions

0 votes
1 answer 67 views
67 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 34 views
34 views
Cannot create controller in thread that did not call Looper.prepare () What does the following exception mean? How can I fix it? Here is the code: Toast toast = Toast.makeText (mContext, "Something", Toast.LENGTH_SHORT); This is the exception: Java.lang.RuntimeException: Cannot ... :121)      on Android.widget.Toast. <init> (Toast.Java:68)      on Android.widget.Toast.makeText (Toast.Java:231)
asked Aug 17 game 4.3k points
0 votes
1 answer 355 views
355 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 67 views
67 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