很好的一天!我正在努力解决这个问题一周,这是以前没有的(也就是说,这个程序以前是有效的)。
问题:我的登录表单的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_screenxml代码:
<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>
最后,我的AndroidID清单。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
注意:每当我在“扩展活动”之后删除代码“implements JPacketListener”,并删除它的方法(onPacketReceived/onPacketSent),我的模拟器上就会加载LoginScreen GUI。
任何帮助都将不胜感激!提前谢谢!
Failed resolving Lcom/androidtutorial/app/view/LoginScreen; interface 577 'Lcom/jeshop/jtcpconnection/packet/JPacketListener;'
这就是出现ClassNotFoundException
的原因。有一个未解析的接口,类加载器拒绝该类。
您是否在项目中包含了包含JPacketListener
的库?
我的应用程序运行得很好,我可以从一个活动转到另一个活动,然后我添加了一些Toast消息用于注册按钮,然后我在尝试从MainActivity转到RegistrationActivity时遇到了这个错误。。 美娜ctivity.kt 注册ctivity.kt activity_main.xml 活动注册。xml 显示 和logchat 2019-12-09 09:08:16.171 28691-286
我有一段时间在写代码 我的错误是: 无法实例化活动组件信息{com.example.example/com.example.sample.MainActivity}:java。lang.NullPointerException:尝试调用虚拟方法“android”。所容纳之物下午。Android应用信息。所容纳之物上下文对空对象引用执行getApplicationInfo()
我目前正在一个android项目,当试图运行后构建的应用程序平原崩溃。以下是LogCat详细信息: 2021-11-13 13:37:08.105 11908-11908/com.example.finalprojectE/AndroidRuntime: FATAL EXCEPTION:主进程:com.example.finalproject, PID: 11908java.lang.Runtim
RegistrationActivity.kt activity_main.xml activity_registraion.xml
我是Android程序员的新手。最近,我尝试在android应用程序中使用google map v2制作项目,但是我得到了很多错误(我已经将google play服务添加到我的库中,并且在这里找到了类似的主题,但是没有解决我的问题)。请看我的日志猫吼: my mainactivity.java: 我在这里使用的是fragment,所以这里是fragment_main.xml: 还有我的舱单 这里是