简体   繁体   中英

RuntimeException: Unable to instantiate activity componentInfo

Good day! I'm trying to solve this problem for a week now that was not present before (That means to say that the program was working before).

Problem: My Login form's GUI won't load anymore.

Given: (LoginScreen Class-View)

public class LoginScreen extends Activity implements JPacketListener { 

private EditText editTextUsername;
private EditText editTextPassword;
private Button btnSubmit;
private boolean isReady = true;

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

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  menu.add(1,1,1,"Change IP Connection");       
  return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {

  if (item.getTitle() == "Change IP Connection") {

    Intent intent = new Intent(LoginScreen.this,ChangeIp.class);
    startActivity(intent);
  }

  return super.onMenuItemSelected(featureId, item);
}

private void loadUIReferences() {

  editTextUsername = (EditText) this.findViewById(R.id.editTextUsername);
  editTextPassword = (EditText) this.findViewById(R.id.editTextPassword);
  btnSubmit = (Button) this.findViewById(R.id.btnSubmit);

  btnSubmit.setOnTouchListener(new OnTouchListener() {


@Override
public boolean onTouch(View v, MotionEvent event) {

if (!isReady) {
  return true;
}
  Toast.makeText(LoginScreen.this, "Loading...",Toast.LENGTH_SHORT).show();

  isReady = false;
try {
  Builder tpol = new ThreadPolicy.Builder().permitAll();
  StrictMode.setThreadPolicy(tpol.build());
  Toast.makeText(LoginScreen.this, "Connecting To Server...",Toast.LENGTH_LONG).show();
  JTCPConnectionClient client = new JTCPConnectionClient(Settings.IP, Settings.PORT);
  client.addListener(LoginScreen.this);
  client.send("Parameter too long, checkers, don't mind this");

} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {

// TODO Auto-generated catch block
e.printStackTrace();
}

  return true;
}

});

}

@Override
  public void onPacketReceived(final JPacket arg0, JTCPConnection arg1) {

this.runOnUiThread(new Runnable() {

  @Override
    public void run() {
     try {

     String message = arg0.getMessage();
     isReady = true;
     String[] fields = message.split("\n");
Toast.makeText(LoginScreen.this, fields[1].split("=")[1],Toast.LENGTH_SHORT).show();
      if (fields[0].split("=")[1].equals("1")) {
    UserData.getInstance().setUsername(editTextUsername.getText().toString());
    Intent intent = new Intent(LoginScreen.this,SimpleCalendarViewActivity.class);
    startActivity(intent);
    finish();

}
} catch (Exception e) {

e.printStackTrace();
}
   }

 });

}

@Override
 public void onPacketSent(JPacket arg0, JTCPConnection arg1) {
 System.out.println("Packet Sent!");
}
}

My login_screen xml code:

<ScrollView 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"
tools:context=".MainActivity" >


<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:orientation="vertical"              
    android:background="@drawable/background_lyceum_2" >
<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:background="#CD6600"
    android:gravity="left"
    android:textColor="#FFFFFF"
    android:paddingBottom="20dp"
    android:text="My Application"
    android:textSize="11sp"
    />


<LinearLayout 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:weightSum="3"
    >
<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />  
<TextView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="USERNAME:"
    android:textSize="11sp"
    android:gravity="left"
    android:layout_weight="0.5"
    android:textColor="#000000"
    android:padding="5dp"
    android:layout_marginTop="20dp" />
<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />  
    </LinearLayout>
<LinearLayout 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:weightSum="3"
    >
<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />  
<EditText
    android:id="@+id/editTextUsername"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"
    android:layout_weight="0.5"   
     />
<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />
</LinearLayout>
<LinearLayout 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:weightSum="3"
    >
<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />  
<TextView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="PASSWORD:"
    android:textSize="12sp"
    android:layout_weight="0.5"
    android:gravity="left"
    android:textColor="#000000"
    android:padding="11dp"
    android:layout_marginTop="20dp" />
<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />
</LinearLayout>
<LinearLayout 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:weightSum="3"
    >
<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />  

    <EditText
    android:id="@+id/editTextPassword"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"
    android:layout_weight="0.5"
    android:inputType="textPassword" />

<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />
</LinearLayout>
<LinearLayout 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:weightSum="3"
    >
    <TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />
<Button
    android:id="@+id/btnSubmit"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:background="#CD6600"
    android:gravity="center"
    android:padding="5dp"
    android:text="LOGIN"
    android:layout_weight="0.5"
    android:textColor="#FFFFFF"
    android:textSize="20sp"
    android:textStyle="bold" />
<TextView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1.25"
    />
</LinearLayout>
</LinearLayout>

</ScrollView>

And finally, my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.tsmirror"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.androidtutorial.app.view.LoginScreen"
        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.androidtutorial.app.view.SimpleCalendarViewActivity" >
    </activity>
    <activity android:name="com.androidtutorial.app.view.ChangeIp" >
    </activity>
    <activity android:name="com.androidtutorial.app.view.RecipientList" >
    </activity>
    <activity android:name="com.androidtutorial.app.view.EventOptionShow" >
    </activity>
    <activity android:name="com.androidtutorial.app.view.EventList" >
    </activity>
    <activity android:name="com.android.tsmirror.LoginScreen" >
    </activity>
    <activity android:name="com.androidtutorial.app.view.CalendarOption" >
    </activity>
    <activity android:name="com.androidtutorial.app.view.CalendarList" >
    </activity>
    <activity android:name="com.androidtutorial.app.view.EventOption" >
    </activity>
</application>

</manifest>

This is my Logcat output:

05-20 06:40:26.451: W/Trace(802): Unexpected value from nativeGetEnabledTags: 0
05-20 06:40:26.812: W/Trace(802): Unexpected value from nativeGetEnabledTags: 0
05-20 06:40:26.812: W/Trace(802): Unexpected value from nativeGetEnabledTags: 0
05-20 06:40:26.812: I/dalvikvm(802): Failed resolving Lcom/androidtutorial/app/view/LoginScreen; interface 577 'Lcom/jeshop/jtcpconnection/packet/JPacketListener;'
05-20 06:40:26.822: W/dalvikvm(802): Link of class 'Lcom/androidtutorial/app/view/LoginScreen;' failed
05-20 06:40:26.832: D/AndroidRuntime(802): Shutting down VM
05-20 06:40:26.832: W/dalvikvm(802): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
05-20 06:40:26.852: E/AndroidRuntime(802): FATAL EXCEPTION: main
05-20 06:40:26.852: E/AndroidRuntime(802): java.lang.RuntimeException: Unable to instantiate     activity ComponentInfo{com.android.tsmirror/com.androidtutorial.app.view.LoginScreen}: java.lang.ClassNotFoundException: Didn't find class "com.androidtutorial.app.view.LoginScreen" on path: /data/app/com.android.tsmirror-1.apk
05-20 06:40:26.852: E/AndroidRuntime(802):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
05-20 06:40:26.852: E/AndroidRuntime(802):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-20 06:40:26.852: E/AndroidRuntime(802):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-20 06:40:26.852: E/AndroidRuntime(802):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-20 06:40:26.852: E/AndroidRuntime(802):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 06:40:26.852: E/AndroidRuntime(802):  at android.os.Looper.loop(Looper.java:137)
05-20 06:40:26.852: E/AndroidRuntime(802):  at android.app.ActivityThread.main(ActivityThread.java:5039)
05-20 06:40:26.852: E/AndroidRuntime(802):  at java.lang.reflect.Method.invokeNative(Native Method)
05-20 06:40:26.852: E/AndroidRuntime(802):  at java.lang.reflect.Method.invoke(Method.java:511)
05-20 06:40:26.852: E/AndroidRuntime(802):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-20 06:40:26.852: E/AndroidRuntime(802):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-20 06:40:26.852: E/AndroidRuntime(802):  at dalvik.system.NativeStart.main(Native Method)
05-20 06:40:26.852: E/AndroidRuntime(802): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.androidtutorial.app.view.LoginScreen" on path: /data/app/com.android.tsmirror-1.apk
05-20 06:40:26.852: E/AndroidRuntime(802):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-20 06:40:26.852: E/AndroidRuntime(802):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-20 06:40:26.852: E/AndroidRuntime(802):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-20 06:40:26.852: E/AndroidRuntime(802):  at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
05-20 06:40:26.852: E/AndroidRuntime(802):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
05-20 06:40:26.852: E/AndroidRuntime(802):  ... 11 more

Note: Whenever I remove the code 'implements JPacketListener' after the 'extends Activity' and also remove it's methods (onPacketReceived/onPacketSent), LoginScreen GUI loads on my emulator.

Any help would be appreciated! Thank you in advance!

Failed resolving Lcom/androidtutorial/app/view/LoginScreen; interface 577 'Lcom/jeshop/jtcpconnection/packet/JPacketListener;'

This is the reason for the ClassNotFoundException . There's an unresolved interface and the class loader rejects the class.

Have you included the library that contains JPacketListener in your project?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM