0
我完全禁用Android,剛開始學習並開始一個項目。一切都很好,但是當我想單擊註冊按鈕時,應用程序崩潰。我修正了一些錯誤,但這不能很久。 也嘗試debbug,但不要underestand什麼調試器說。 任何評論,請幫助Android Studio崩潰應用程序
package com.example.demir.carsharing;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Display;
import android.content.Intent;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
DatabaseHelper helper = new DatabaseHelper(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onButtonClick(View v){
if (v.getId()==R.id.bLogin)
{
EditText a = (EditText)findViewById(R.id.TFUsername);
String str = a.getText().toString();
EditText b = (EditText)findViewById(R.id.TFPassword);
String pass = b.getText().toString();
String password = helper.searchPass(str);
if(pass.equals(password))
{
Intent i = new Intent(MainActivity.this, Display.class);
i.putExtra("Username", str);
startActivity(i);
}
else
{
// DIsplay popup message
Toast temp =Toast.makeText(MainActivity.this, "Username and Password don't match", Toast.LENGTH_SHORT);
temp.show();
}
}
if (v.getId()==R.id.bSignUpHere)
{
Intent i = new Intent(MainActivity.this, signup.class);
startActivity(i);
}
}
}
下面是一個日誌文件
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.demir.carsharing, PID: 3566
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.demir.carsharing/com.example.demir.carsharing.signup}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
at android.app.Activity.startActivityForResult(Activity.java:4224)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:77)
at android.app.Activity.startActivityForResult(Activity.java:4183)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4507)
at android.app.Activity.startActivity(Activity.java:4475)
at com.example.demir.carsharing.MainActivity.onButtonClick(MainActivity.java:53)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
告訴我錯誤的圖片或更詳細 – omriherman
的錯誤是,當我打開標籤,不能關閉它解釋:我可以在這裏發佈的代碼。 – yimy
好吧,我仍然無法評論答案,所以我會在這裏評論你的最新答案: 你有兩個不同的活動,他們是主要和啓動器,這意味着你有兩個活動在應用程序啓動時打開權利,並且這當然是一個錯誤。 只需刪除unnecessery <操作機器人:名字= 「android.intent.action.MAIN」/> <類機器人:名字= 「android.intent.category.LAUNCHER」/> – omriherman