Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The error message </p> <blockquote> <p>Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit constructor.</p> </blockquote> <p>is quite clear. You have a base class of which the constructor throws an <code>IOException</code>:</p> <pre><code>public class BaseClass { public BaseClass() throws IOException { // ... } } </code></pre> <p>And you are trying to subclass it:</p> <pre><code>public class SubClass extends BaseClass { } </code></pre> <p>But the (now implicit) constructor of <code>SubClass</code> implicitly calls <code>super()</code> which throws an exception for which the subclass is not prepared at all, since the implicit constructor looks like this:</p> <pre><code>public SubClass() { super(); // this throws an IOException which is not declared to be thrown by SubClass constructor } </code></pre> <p>So, you must define an explicit constructor:</p> <pre><code>public SubClass() throws IOException { super(); } </code></pre> <p><strong>UPDATE</strong></p> <p>The problem in fact is caused by initializing instance fields with initializers throwing exceptions. In this case you have to move them in a constructor which throws the exception:</p> <pre><code>public MainActivity() throws IOException { File infile = new File("inputtextfile.txt"); Scanner fsc = new Scanner(infile); AssetManager assetManager = getAssets(); Scanner fsc1 = new Scanner(assetManager.open("inputtextfile.txt")); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload