newInstance failed: no <init>

I cannot instantiate a sub activity. In the logcat I see this line:

01-22 15:14:38.906: DEBUG/dalvikvm(411): newInstance failed: no <init>()

This is the line in dalvik that generates that logcat.

/*
 * public T newInstance() throws InstantiationException, IllegalAccessException
 *
 * Create a new instance of this class.
 */
static void Dalvik_java_lang_Class_newInstance(const u4* args, JValue* pResult)
...
    /* find the "nullary" constructor */
    init = dvmFindDirectMethodByDescriptor(clazz, "<init>", "()V");
    if (init == NULL) {
        /* common cause: secret "this" arg on non-static inner class ctor */
        LOGD("newInstance failed: no <init>()\n");
        dvmThrowExceptionWithClassMessage("Ljava/lang/InstantiationException;",
            clazz->descriptor);
        RETURN_VOID();
    }

Here is the action I take to activate the activity in a timer handler.

// move on to Activation
// ePNSplash is this activity a splash screen

Intent i = new Intent (ePNSplash.this, Activation.class);
startActivity (i);

The activity that I am trying to start is 2 extensions above Activity

Here is the first extension

public abstract class AndroidScreen extends Activity {
    ....

public AndroidScreen (String title, AndroidScreen parent, AndroidScreen main)
{
    super ();

    myGlobals = Globals.getGlobals ();

    myGlobals.myLogger.logString("AndroidScreen: 001");

    myParent = parent;
    myMainScreen = main;
    myTitle = title;
}

This is only the constructor, which seems to be the part that has the problem. Here is the 2nd extension and the class i am trying to instantiate.

public class Activation extends AndroidScreen {

public Activation (String title, AndroidScreen parent, AndroidScreen main)
{
    super (title, parent, main);
}

I am absolutely confused, I have a constructor, I make sure I call my super constructors, what could possibly be wrong?

Thank you

Julian


Asked by: Victoria715 | Posted: 25-01-2022






Answer 1

dalvikvm's looking for a zero-argument constructor (that's what they mean by "nullary", as in "binary" for 2 arguments, "unary" for 1 argument, it's "nullary" for 0 arguments).

in the snippet you've shown, you only have a three-argument constructor. that's no good: you'll be instantiated with no arguments, so you need a zero-argument constructor.

Answered by: Aida401 | Posted: 26-02-2022



Similar questions

android - newInstance failed: no <init>()

I got 3 files. One serves as a database handler ( insert, delete, update etc... ) and the other maintains the object constructors with its functions. The last file just prints some values after it inserts them to the database. The error i got is : 12-29 01:54:21.584: D/dalvikvm(574): newInstance failed: no &lt;init&gt;() 12-29 01:54:21.634: D/AndroidRuntime(574): Shutting down VM 12-29 01:54:21.634:...


newInstance failed: no <init> error in android program development

I am writing a sample code to use android orientation sensor to view 3D scenes. The error i got is : 03-22 16:12:48.939: D/dalvikvm(9532): newInstance failed: no &lt;init&gt;() 03-22 16:12:48.939: D/AndroidRuntime(9532): Shutting down VM 03-22 16:12:48.939: W/dalvikvm(9532): threadid=1: thread exiting with uncaught exception (group=0x40018560) 03-22 16:12:48.949: E/AndroidRuntime(95...


android - Backstack for newInstance

I have 3 activities : A (launcher), B and C. I have specified A's launchMode (in manifest) as singleInstance. A has a button to go to B, B has a button to launch C, C has a button to launch A - all using default "standard" mode of invocation. I take following steps : Launch app -> A -> Launch B -> B -> Launch C -> C -> Launch A -> A -> Launch B -> C This takes me to C (and not B) ! I ca...


android - Fragment newinstance method if fragment is added through xml layout

As it's mentioned in various articles about using a static newInstance method for creating a fragment. I understand we can call this method if we create a fragment in code. But there is no way of getting this method called if fragment is added through xml layout file. In that case only constructor gets called. So what should be the approach in this case ? Thanks Dalvin


android - when Class newInstance is called

I have created One Android app using fragment layout. I faced an issue of "empty constructor" So I have Change my code. public static final GridFragment newInstance(Item[] gridItems) { GridFragment f = new GridFragment(); Bundle bdl = new Bundle(1); bdl.putParcelableArray("objitem", gridItems); f.setArguments(bdl); return f; } GridFragment


Android How to call newInstance Constructor

I want to display the slideshow using ViewPager with ImageView and Textview. When I called Fragment.newinstance(int image,String value) constructor it shows up the error below. Did I called the constructor correctly or not? Error: 06-09 15:26:17.746: E/AndroidRuntime(14955): FATAL EXCEPTION: main 06-09 15:26:17.746: E/Andro...


android - "newInstance failed: no <init>()" when starting another Activity

This app was working, and now it isn't, and I can't see why. The exception happens on setContentView(R.layout.activity_todo); I looked at all the other answers to similar questions that I could find, and none of them solved my problem. Here's the main activity: public class TodoActivity extends Activity { ... lvItems.setOnItemClickListener(new OnItemClic...


android - Passing individual variables vs passing bundle to newInstance

For passing arguments to fragments, I see the best practice is to use a newInstance() method as such: public static MyFragment newInstance(int myInt) { MyFragment myFragment = new MyFragment(); Bundle args = new Bundle(); args.putInt("myInt", myInt); myFragment.setArguments(args); return myFragment; } and this would be instantiated as such: int myInt =...


android - Inflating a fragment with newInstance and animations

What is the equivalent of fragmentTransaction.setCustomAnimations (android.R.animator.fade_in, android.R.animator.fade_out); when inflating a fragment using MyFragment.newInstance() in a ViewPager rather than using a FragmentTransaction andNew MyFragment() ? Please note that if I simply add android:animateLayoutChanges="true" to the ViewPager in MainActivity.xml ...


android - Fragment newInstance why use arguments?

What is the real difference between these two approaches? 1.I am using standard old-fashined bundle: public static final Fragment newInstance(int val1, int val2) { TestFragment f = new TestFragment(); Bundle bundle = new Bundle(); bundle.putInt("val1", val1); bundle.putInt("val2", val2); f.setArguments(bundle); return f; } 2.I am setting as instance memb...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top