这是我的日志猫。当我在模拟器上运行我的应用程序时,通过发出消息“unfortunatelt launcher has stooped”停止...我正在使用API 19 4.4.2和APPTHEME
12-15 19:45:46.180: D/AndroidRuntime(1407): Shutting down VM
12-15 19:45:46.180: W/dalvikvm(1407): threadid=1: thread exiting with uncaught exception (group=0xb3ae1ba8)
12-15 19:45:46.220: E/AndroidRuntime(1407): FATAL EXCEPTION: main
12-15 19:45:46.220: E/AndroidRuntime(1407): Process: com.example.laundry, PID: 1407
12-15 19:45:46.220: E/AndroidRuntime(1407): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.laundry/com.example.laundry.LoginActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.laundry.LoginActivity" on path: DexPathList[[zip file "/data/app/com.example.laundry-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.laundry-2, /system/lib]]
12-15 19:45:46.220: E/AndroidRuntime(1407): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
12-15 19:45:46.220: E/AndroidRuntime(1407): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
12-15 19:45:46.220: E/AndroidRuntime(1407): at android.app.ActivityThread.access$800(ActivityThread.java:135)
12-15 19:45:46.220: E/AndroidRuntime(1407): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
12-15 19:45:46.220: E/AndroidRuntime(1407): at android.os.Handler.dispatchMessage(Handler.java:102)
12-15 19:45:46.220: E/AndroidRuntime(1407): at android.os.Looper.loop(Looper.java:136)
12-15 19:45:46.220: E/AndroidRuntime(1407): at android.app.ActivityThread.main(ActivityThread.java:5001)
12-15 19:45:46.220: E/AndroidRuntime(1407): at java.lang.reflect.Method.invokeNative(Native Method)
12-15 19:45:46.220: E/AndroidRuntime(1407): at java.lang.reflect.Method.invoke(Method.java:515)
12-15 19:45:46.220: E/AndroidRuntime(1407): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
12-15 19:45:46.220: E/AndroidRuntime(1407): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
12-15 19:45:46.220: E/AndroidRuntime(1407): at dalvik.system.NativeStart.main(Native Method)
12-15 19:45:46.220: E/AndroidRuntime(1407): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.laundry.LoginActivity" on path: DexPathList[[zip file "/data/app/com.example.laundry-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.laundry-2, /system/lib]]
12-15 19:45:46.220: E/AndroidRuntime(1407): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-15 19:45:46.220: E/AndroidRuntime(1407): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
12-15 19:45:46.220: E/AndroidRuntime(1407): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
12-15 19:45:46.220: E/AndroidRuntime(1407): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-15 19:45:46.220: E/AndroidRuntime(1407): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
12-15 19:45:46.220: E/AndroidRuntime(1407): ... 11 more
12-15 19:45:51.210: I/Process(1407): Sending signal. PID: 1407 SIG: 9
这是我的主要活动是什么。我试着在这里登录和注册使用php我的SQL数据库
public class MainActivity extends Activity {
private TextView txtName;
private TextView txtEmail;
private Button btnLogout;
private SQLiteHandler db;
private SessionManager session;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtName = (TextView) findViewById(R.id.name);
txtEmail = (TextView) findViewById(R.id.email);
btnLogout = (Button) findViewById(R.id.btnLogout);
// SqLite database handler
db = new SQLiteHandler(getApplicationContext());
// session manager
session = new SessionManager(getApplicationContext());
if (!session.isLoggedIn()) {
logoutUser();
}
// Fetching user details from sqlite
HashMap<String, String> user = db.getUserDetails();
String name = user.get("name");
String email = user.get("email");
txtName.setText(name);
txtEmail.setText(email);
// Logout button click event
btnLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logoutUser();
}
});
}
private void logoutUser() {
session.setLogin(false);
db.deleteUsers();
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
}
这是我的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.laundry"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="app.AppController"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".LoginActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegisterActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop" />
</application>
这是我的登录活动
package activity;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import com.example.laundry.MainActivity;
import com.example.laundry.R;
import app.AppConfig;
import app.AppController;
import helper.SQLiteHandler;
import helper.SessionManager;
public class LoginActivity extends Activity {
private static final String TAG = RegisterActivity.class.getSimpleName();
private Button btnLogin;
private Button btnLinkToRegister;
private EditText inputEmail;
private EditText inputPassword;
private ProgressDialog pDialog;
private SessionManager session;
private SQLiteHandler db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
// Progress dialog
pDialog = new ProgressDialog(this);
pDialog.setCancelable(false);
// SQLite database handler
db = new SQLiteHandler(getApplicationContext());
// Session manager
session = new SessionManager(getApplicationContext());
// Check if user is already logged in or not
if (session.isLoggedIn()) {
// User is already logged in. Take him to main activity
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
// Login button Click Event
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String email = inputEmail.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
// Check for empty data in the form
if (!email.isEmpty() && !password.isEmpty()) {
// login user
checkLogin(email, password);
} else {
// Prompt user to enter credentials
Toast.makeText(getApplicationContext(),
"Please enter the credentials!", Toast.LENGTH_LONG)
.show();
}
}
});
// Link to Register Screen
btnLinkToRegister.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(),
RegisterActivity.class);
startActivity(i);
finish();
}
});
}
/**
* function to verify login details in mysql db
* */
private void checkLogin(final String email, final String password) {
// Tag used to cancel the request
String tag_string_req = "req_login";
pDialog.setMessage("Logging in ...");
showDialog();
StringRequest strReq = new StringRequest(Method.POST,
AppConfig.URL_LOGIN, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Login Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
// user successfully logged in
// Create login session
session.setLogin(true);
// Now store the user in SQLite
String uid = jObj.getString("uid");
JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String created_at = user
.getString("created_at");
// Inserting row in users table
db.addUser(name, email, uid, created_at);
// Launch main activity
Intent intent = new Intent(LoginActivity.this,
MainActivity.class);
startActivity(intent);
finish();
} else {
// Error in login. Get the error message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Login Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<String, String>();
params.put("email", email);
params.put("password", password);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
private void showDialog() {
if (!pDialog.isShowing())
pDialog.show();
}
private void hideDialog() {
if (pDialog.isShowing())
pDialog.dismiss();
}
}
答案 0 :(得分:1)
明白了。转到您的登录活动并使用此
public func NSLocalizedString(key: String) -> String {
return NSLocalizedString(key, comment: "")
}
http://developer.android.com/intl/es/guide/topics/manifest/manifest-element.html