我一直在玩一个Android应用程序,然后重新启动再次对其进行编码,看看我能记住的东西。问题是,我完全破坏了应用程序并且不明白为什么。
应用程序将加载一点,并显示某种形式的布局(不是任何已定义的布局)然后崩溃。
以下是一些代码,如果您需要查看其他内容,请告诉我们:
清单:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name="org.mjth.online_sn.main" 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="org.mjth.online_sn.live" android:label="@string/app_name"></activity>
<activity android:name="org.mjth.online_sn.login_form" android:label="@string/app_name"></activity>
</application>
</manifest>
Main.java
import java.util.EmptyStackException;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
//Will do the default setup and checks
public class main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//Locks screen orientation to portrait for now
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//Checks to see if we have valid authorisation keys and files
SharedPreferences pref = getSharedPreferences("org.mjth.online_sn", MODE_PRIVATE);
try{
if(pref.getString("auth_id", "").equals("") == false){
throw new EmptyStackException();
}
if(pref.getString("auth_pass", "").equals("") == false){
throw new EmptyStackException();
}
if(pref.getString("lcl_first_name", "").equals("") == false){
throw new EmptyStackException();
}
if(pref.getString("lcl_last_name", "").equals("") == false){
throw new EmptyStackException();
}
if(pref.getString("lcl_expiry", "").equals("") == false){
throw new EmptyStackException();
}
//TODO: Check if expiry is past todays date.
//We passed all local checks, set view to live and double check on background
Intent myIntent = new Intent(getApplicationContext(), live.class);
startActivityForResult(myIntent, 0);
}catch (EmptyStackException e){
//No valid credentials were found.
Intent myIntent = new Intent(getApplicationContext(), login_form.class);
startActivityForResult(myIntent, 0);
}
}
}
login_form.java
import org.mjth.online_sn.R;
import android.app.Activity;
import android.os.Bundle;
public class login_form extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.login_form);
}
}
live.java
import org.mjth.online_sn.R;
import android.app.Activity;
import android.os.Bundle;
public class live extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.live);
}
}
更新:当禁用操作意图代码时,我收到以下错误:
12-12 22:58:49.653: E/AndroidRuntime(1930): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.mjth.online_sn/org.mjth.online_sn.main}: java.lang.ClassNotFoundException: org.mjth.online_sn.main
12-12 22:58:49.653: E/AndroidRuntime(1930): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
12-12 22:58:49.653: E/AndroidRuntime(1930): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
12-12 22:58:49.653: E/AndroidRuntime(1930): at android.app.ActivityThread.access$600(ActivityThread.java:140)
12-12 22:58:49.653: E/AndroidRuntime(1930): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
12-12 22:58:49.653: E/AndroidRuntime(1930): at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 22:58:49.653: E/AndroidRuntime(1930): at android.os.Looper.loop(Looper.java:137)
12-12 22:58:49.653: E/AndroidRuntime(1930): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-12 22:58:49.653: E/AndroidRuntime(1930): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 22:58:49.653: E/AndroidRuntime(1930): at java.lang.reflect.Method.invoke(Method.java:511)
12-12 22:58:49.653: E/AndroidRuntime(1930): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-12 22:58:49.653: E/AndroidRuntime(1930): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-12 22:58:49.653: E/AndroidRuntime(1930): at dalvik.system.NativeStart.main(Native Method)
12-12 22:58:49.653: E/AndroidRuntime(1930): Caused by: java.lang.ClassNotFoundException: org.mjth.online_sn.main
12-12 22:58:49.653: E/AndroidRuntime(1930): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-12 22:58:49.653: E/AndroidRuntime(1930): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-12 22:58:49.653: E/AndroidRuntime(1930): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-12 22:58:49.653: E/AndroidRuntime(1930): at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
12-12 22:58:49.653: E/AndroidRuntime(1930): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
12-12 22:58:49.653: E/AndroidRuntime(1930): ... 11 more