每当我尝试运行我的应用程序时,它会显示一个对话框,说明应用程序已经意外停止,无论是在手机还是模拟器上。该程序没有错误,我已经尝试清理我的项目和几个解决方案,但没有他们工作。即使是hello world项目,几个项目也会出现同样的问题。
这是我的主要活动:MainActivity.java
package com.noura.luba;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
TextView forgotPass, createAcc;
Button loginButton;
EditText userID, pass;
LoginDataBaseAdapter loginDataBaseAdapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginDataBaseAdapter=new LoginDataBaseAdapter(this);
loginDataBaseAdapter=loginDataBaseAdapter.open();
forgotPass= (TextView)findViewById(R.id.forgotPasswordTextView);
createAcc= (TextView)findViewById(R.id.createAccountTextView);
loginButton= (Button)findViewById(R.id.loginButton);
userID=(EditText)findViewById(R.id.userIDEditText);
pass=(EditText)findViewById(R.id.passwordEditText);
createAcc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intentCreateAcc = new Intent(getApplicationContext(), CreateAccActivity.class);
startActivity(intentCreateAcc);
}
});
forgotPass.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intentForgotPass = new Intent(getApplicationContext(), ForgotPassActivity.class);
startActivity(intentForgotPass);
}
});
loginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String id=userID.getText().toString();
Intent intentLogin = new Intent(getApplicationContext(), Home.class);
intentLogin.putExtra("User_ID", id);
startActivity(intentLogin);
}
});
}
public void LogIn(View V)
{
final Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.activity_main);
dialog.setTitle("LUBA LogIn");
final EditText userID=(EditText)dialog.findViewById(R.id.userIDEditText);
final EditText pass=(EditText)dialog.findViewById(R.id.passwordEditText);
Button login = (Button)dialog.findViewById(R.id.loginButton);
//Set On ClickListener
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String userName= userID.getText().toString();
String password=pass.getText().toString();
String storedPassword = loginDataBaseAdapter.getSingleEntry(userName);
if(password.equals(storedPassword))
{
Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_LONG).show();
dialog.dismiss();
}
else
{
Toast.makeText(MainActivity.this, "User Name and Password do not match", Toast.LENGTH_LONG).show();
}
}
});
dialog.show();
}
protected void onDestroy() {
super.onDestroy();
loginDataBaseAdapter.close();
}
}
这是我的xml页面:activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context="com.noura.luba.MainActivity"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@string/blue" >
<ImageView
android:id="@+id/LUBAimageView"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/userIDEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/LUBAimageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:ems="10"
android:inputType="number"
android:text="@string/user_edit_text"
android:textColor="@string/yellow"
>
<requestFocus />
</EditText>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/userIDEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:ems="10"
android:inputType="textPassword"
android:text="@string/password_edit_text"
android:textColor="@string/yellow" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_below="@+id/passwordEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="@string/login_button"
android:textColor="@string/yellow" />
<TextView
android:id="@+id/forgotPasswordTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/LUBAimageView"
android:layout_alignStart="@+id/LUBAimageView"
android:layout_below="@+id/loginButton"
android:layout_marginTop="20dp"
android:autoLink="web"
android:clickable="true"
android:ems="8"
android:onClick="forgotPassword"
android:text="@string/forgot_password"
android:textColor="@string/yellow" />
<TextView
android:id="@+id/createAccountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/forgotPasswordTextView"
android:layout_alignBottom="@+id/forgotPasswordTextView"
android:layout_alignRight="@+id/LUBAimageView"
android:layout_alignEnd="@+id/LUBAimageView"
android:onClick="createAccount"
android:text="@string/create_account"
android:textColor="@string/yellow" />
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/forgotPasswordTextView"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignStart="@+id/forgotPasswordTextView"
layout="@layout/noura" />
</RelativeLayout>
这是logcat
11-13 22:17:54.092: D/AndroidRuntime(340): Shutting down VM
11-13 22:17:54.092: W/dalvikvm(340): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-13 22:17:54.162: E/AndroidRuntime(340): FATAL EXCEPTION: main
11-13 22:17:54.162: E/AndroidRuntime(340): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.noura.luba/com.noura.luba.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
11-13 22:17:54.162: E/AndroidRuntime(340): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.os.Looper.loop(Looper.java:123)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-13 22:17:54.162: E/AndroidRuntime(340): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 22:17:54.162: E/AndroidRuntime(340): at java.lang.reflect.Method.invoke(Method.java:507)
11-13 22:17:54.162: E/AndroidRuntime(340): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-13 22:17:54.162: E/AndroidRuntime(340): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-13 22:17:54.162: E/AndroidRuntime(340): at dalvik.system.NativeStart.main(Native Method)
11-13 22:17:54.162: E/AndroidRuntime(340): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
11-13 22:17:54.162: E/AndroidRuntime(340): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
11-13 22:17:54.162: E/AndroidRuntime(340): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-13 22:17:54.162: E/AndroidRuntime(340): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.app.Activity.setContentView(Activity.java:1657)
11-13 22:17:54.162: E/AndroidRuntime(340): at com.noura.luba.MainActivity.onCreate(MainActivity.java:25)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-13 22:17:54.162: E/AndroidRuntime(340): ... 11 more
11-13 22:17:54.162: E/AndroidRuntime(340): Caused by: java.lang.reflect.InvocationTargetException
11-13 22:17:54.162: E/AndroidRuntime(340): at java.lang.reflect.Constructor.constructNative(Native Method)
11-13 22:17:54.162: E/AndroidRuntime(340): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
11-13 22:17:54.162: E/AndroidRuntime(340): ... 21 more
11-13 22:17:54.162: E/AndroidRuntime(340): Caused by: android.content.res.Resources$NotFoundException: File #2E5894 from drawable resource ID #0x7f0a0027
11-13 22:17:54.162: E/AndroidRuntime(340): at android.content.res.Resources.loadDrawable(Resources.java:1714)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.view.View.<init>(View.java:1951)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.view.View.<init>(View.java:1899)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.view.ViewGroup.<init>(ViewGroup.java:286)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.widget.RelativeLayout.<init>(RelativeLayout.java:173)
11-13 22:17:54.162: E/AndroidRuntime(340): ... 24 more
11-13 22:17:54.162: E/AndroidRuntime(340): Caused by: java.io.FileNotFoundException: #2E5894
11-13 22:17:54.162: E/AndroidRuntime(340): at android.content.res.AssetManager.openNonAssetNative(Native Method)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.content.res.AssetManager.openNonAsset(AssetManager.java:406)
11-13 22:17:54.162: E/AndroidRuntime(340): at android.content.res.Resources.loadDrawable(Resources.java:1706)
11-13 22:17:54.162: E/AndroidRuntime(340): ... 29 more
11-13 22:22:54.263: I/Process(340): Sending signal. PID: 340 SIG: 9
我是Android应用程序开发的新手,但我认真尝试了我能找到的每个解决方案。如果有人能帮我找到合适的解决方案。
修改
这是LoginDataBaseAdapter.java
package com.noura.luba;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;
public class LoginDataBaseAdapter {
static final String DATABASE_NAME = "seniorLUBA.db";
static final int DATABASE_VERSION = 1;
public static final int NAME_COLUMN = 1;
public SQLiteDatabase db;
private final Context context;
private DataBaseHelper dbHelper;
public LoginDataBaseAdapter(Context _context)
{
context = _context;
dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public LoginDataBaseAdapter open() throws SQLException
{
db=dbHelper.getWritableDatabase();
return this;
}
public void close()
{
db.close();
}
public SQLiteDatabase getDatabaseInstance()
{
return db;
}
public void insertEntry(String userName, String password)
{
ContentValues newValues = new ContentValues();
newValues.put("USERNAME", userName);
newValues.put("PASSWORD", password);
db.insert("student", null, newValues);
Toast.makeText(context, "User Info Saved", Toast.LENGTH_LONG).show();
}
public int deleteEntry(String UserName)
{
String where="StdId=?";
int numberOFEntriesDeleted = db.delete("student", where, new String[]{UserName});
Toast.makeText(context, "Number of Entry Deleted Successfully : " +numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
return numberOFEntriesDeleted;
}
public String getSingleEntry(String userName)
{
Cursor cursor=db.query("student", null, " USERNAME=?", new String[]{userName}, null, null, null);
if(cursor.getCount()<1)
return "DOES NOT EXIST";
cursor.moveToFirst();
String password= cursor.getString(cursor.getColumnIndex("StdPass"));
return password;
}
public void updateEntry(String userName, String password)
{
ContentValues updatedValues = new ContentValues();
updatedValues.put("UserName", userName);
updatedValues.put("Password", password);
String where="UserName = ?";
db.update("student", updatedValues, where, new String[]{userName});
}
}
这是新的logcat
11-14 02:03:10.618: I/Database(341): sqlite returned: error code = 1, msg = near "seniorLUBA": syntax error
11-14 02:03:10.629: E/Database(341): Failure 1 (near "seniorLUBA": syntax error) on 0x2bee98 when preparing 'seniorLUBA.db'.
11-14 02:03:10.668: D/AndroidRuntime(341): Shutting down VM
11-14 02:03:10.668: W/dalvikvm(341): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-14 02:03:10.698: E/AndroidRuntime(341): FATAL EXCEPTION: main
11-14 02:03:10.698: E/AndroidRuntime(341): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.noura.luba/com.noura.luba.MainActivity}: android.database.sqlite.SQLiteException: near "seniorLUBA": syntax error: seniorLUBA.db
11-14 02:03:10.698: E/AndroidRuntime(341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.os.Looper.loop(Looper.java:123)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-14 02:03:10.698: E/AndroidRuntime(341): at java.lang.reflect.Method.invokeNative(Native Method)
11-14 02:03:10.698: E/AndroidRuntime(341): at java.lang.reflect.Method.invoke(Method.java:507)
11-14 02:03:10.698: E/AndroidRuntime(341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-14 02:03:10.698: E/AndroidRuntime(341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-14 02:03:10.698: E/AndroidRuntime(341): at dalvik.system.NativeStart.main(Native Method)
11-14 02:03:10.698: E/AndroidRuntime(341): Caused by: android.database.sqlite.SQLiteException: near "seniorLUBA": syntax error: seniorLUBA.db
11-14 02:03:10.698: E/AndroidRuntime(341): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763)
11-14 02:03:10.698: E/AndroidRuntime(341): at com.noura.luba.DataBaseHelper.onCreate(DataBaseHelper.java:18)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:126)
11-14 02:03:10.698: E/AndroidRuntime(341): at com.noura.luba.LoginDataBaseAdapter.open(LoginDataBaseAdapter.java:32)
11-14 02:03:10.698: E/AndroidRuntime(341): at com.noura.luba.MainActivity.onCreate(MainActivity.java:28)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-14 02:03:10.698: E/AndroidRuntime(341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-14 02:03:10.698: E/AndroidRuntime(341): ... 11 more
答案 0 :(得分:0)
如果从堆栈跟踪的底部开始,您的资源FileNotFoundException
为2E5894
。
因为看起来你的代码/布局中引用drawable的唯一部分是单ImageView
,并且它使用启动器图标我将从清理和重建你的项目开始确定有些奇怪的事情没有发生。 Eclipse尤其习惯于有时会搞砸资源。
如果这不起作用,那么您应该能够查看生成的R
课程,找出哪些有问题的资源,并尝试找出设备认为它丢失的原因
修改强>
你的评论暗示了一个可能是原因的问题。
颜色资源应声明为color
标记而不是字符串:
<resources>
<color name="my_color">#ffffffff</color>
</resources>
然后当您在视图中使用它们时:
<TextView
android:textColor="@color/my_color" />
答案 1 :(得分:-1)
这是布局xml文件中的资源未找到异常。