美好的一天!我试图解决这个问题已经有一个星期了(以前是不存在的)。
问题:我的登录表单的GUI将不再加载。
鉴于:
(LoginScreen类视图)
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!");
}
}
我的login_screen xml代码:
<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>
最后,我的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>
这是我的Logcat输出:
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
注意:每当我在“扩展活动”之后删除代码“实现JPacketListener”时,
删除它的方法(onPacketReceived / onPacketSent),LoginScreen GUI将加载到我的模拟器上。
任何帮助,将不胜感激!先感谢您!
最佳答案
Failed resolving Lcom/androidtutorial/app/view/LoginScreen; interface 577 'Lcom/jeshop/jtcpconnection/packet/JPacketListener;'
这就是
ClassNotFoundException
的原因。有一个未解决的接口,类加载器拒绝该类。您是否在项目中包括了包含
JPacketListener
的库?