Android Studio崩溃应用程序

问题描述:

我完全禁用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) 

尝试做这样的事情:

private Button v; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    v = (Button) findViewById(R.id.bSignUpHere); 
    v.setOnClickListener(SignUpOnClick); 


} 

View.OnClickListener SignUpOnClick = new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     Intent i = new Intent(MainActivity.this, signup.class); 
     startActivity(i); 
    } 
}; 

你链接的错误是因为你没有带在清单中宣布通缉活动。

因此在mainActivity下方会在清单中添加另一个decleration。

像这样:

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/title_activity_main" 
     android:theme="@style/AppTheme.NoActionBar"></activity> 

    <activity 
     android:name=".signup"></activity> 
</application> 
+0

告诉我错误的图片或更详细 – omriherman

+0

的错误是,当我打开标签,不能关闭它解释:我可以在这里发布的代码。 – yimy

+0

好吧,我仍然无法评论答案,所以我会在这里评论你的最新答案: 你有两个不同的活动,他们是主要和启动器,这意味着你有两个活动在应用程序启动时打开权利,并且这当然是一个错误。 只需删除unnecessery – omriherman

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.demir.carsharing"> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 


     <activity android:name=".Welcome"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 


     <activity android:name=".MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <activity android:name=".TripRegistration"></activity> 
    </application> 

</manifest>