2014-02-14 138 views
-2

當我運行我的項目時,不幸的是應用程序停止運行時出現問題。我發佈了我的代碼。我想用sq-lite數據庫連接我的應用程序。你能否爲我提供工作模式?我只是在執行過程中存儲和檢索值。不幸的是,app_name(DateWithMe)已經停止

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#999999" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true"> 

      <Button 
       android:id="@+id/sign_in" 
       android:layout_width="wrap_content" 
       android:layout_weight="1" 
       android:layout_height="wrap_content" 
       android:textSize="20sp" 
       android:text="Sign In" 
       android:onClick="login_sigin" /> 

      <Button 
       android:id="@+id/log_in" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:textSize="20sp" 
       android:onClick="login_sigin" 
       android:text="Log In" /> 

     </LinearLayout> 

     <TextView 
      android:id="@+id/text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:background="#CCCCCC" 
      android:text=" Welcome " 
      android:gravity="center" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#333333" 
      android:textSize="25sp" /> 

    </RelativeLayout> 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#999999" > 

     <RelativeLayout 
      android:id="@+id/rl" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/phone2" 
      android:layout_alignRight="@+id/phone2" 
      android:layout_centerVertical="true" 
      android:addStatesFromChildren="true" 
      android:background="@android:drawable/edit_text" 
      android:baselineAligned="false" 
      android:gravity="center_vertical" > 



       <EditText 
        android:id="@+id/password2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 

        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_toLeftOf="@+id/show_hide2" 
        android:background="@null" 
        android:ems="10" 
        android:maxLength="40" 
        android:focusable="true" 
        android:focusableInTouchMode="true" 
        android:hint="Password" 
        android:inputType="textPassword" 
        android:maxLines="1" 
        android:singleLine="true" /> 

      </RelativeLayout> 

     <EditText 
      android:id="@+id/phone2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/rl" 
      android:layout_centerHorizontal="true" 
      android:ems="10" 
      android:hint="Mobile No." 
      android:maxLength="10" 
      android:inputType="phone" > 

      <requestFocus /> 
     </EditText> 

     <Button 
      android:id="@+id/signin2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:text="Sign in" 
      android:onClick="action" 
      android:textSize="20sp"/> 

     <Button 
      android:id="@+id/start" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/rl" 
      android:layout_alignRight="@+id/rl" 
      android:layout_below="@+id/rl" 
      android:layout_marginTop="10dp" 
      android:textSize="20sp" 
      android:onClick="action" 
      android:text="Continue.." /> 

    </RelativeLayout> 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#999999" 
      > 
     <EditText 
      android:id="@+id/email_id" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/phone" 
      android:layout_centerVertical="true" 
      android:ems="10" 
      android:hint="Email id" 
      android:maxLength="40" 
      android:inputType="textEmailAddress" > 

     </EditText> 

     <EditText 
      android:id="@+id/phone" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/email_id" 
      android:layout_centerHorizontal="true" 
      android:ems="10" 
      android:maxLength="10" 
      android:hint="Mobile No." 
      android:inputType="number" /> 

     <EditText 
      android:id="@+id/name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/phone" 
      android:layout_centerHorizontal="true" 
      android:ems="10" 
      android:maxLength="30" 
      android:hint="Name" 
      android:inputType="textPersonName"> 
      <requestFocus /> 
      </EditText> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/email_id" 
      android:layout_alignRight="@+id/email_id" 
      android:layout_below="@+id/email_id" 
      android:addStatesFromChildren="true" 
      android:background="@android:drawable/edit_text" 
      android:baselineAligned="false" 
      android:id="@+id/rl" 
      android:gravity="center_vertical" > 



       <EditText 
        android:id="@+id/password" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 

        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_toLeftOf="@+id/show_hide" 
        android:background="@null" 
        android:ems="10" 
        android:maxLength="40" 
        android:focusable="true" 
        android:focusableInTouchMode="true" 
        android:hint="Password" 
        android:inputType="textPassword" 
        android:maxLines="1" 
        android:singleLine="true" /> 

      </RelativeLayout> 

     <Button 
      android:id="@+id/login" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:text="Log in" 
      android:onClick="action" 
      android:textSize="20sp"/> 

     <Button 
      android:id="@+id/signin" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/rl" 
      android:layout_alignRight="@+id/rl" 
      android:layout_below="@+id/rl" 
      android:layout_marginTop="10dp" 
      android:text="Continue.." 
      android:onClick="action" 
      android:textSize="20sp" /> 

    </RelativeLayout> 


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#999999"> 

     <ImageButton 
      android:id="@+id/w_image" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:src="@drawable/ic_launcher" /> 

     <TextView 
      android:id="@+id/w_welcome" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/w_image" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_toRightOf="@+id/w_image" 
      android:text="Welcome Mohsin" 
      android:gravity="center" 
      android:background="#444444" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

    </RelativeLayout> 

和我Login.java

package com.example.datewithme; 

    import android.app.Activity; 
    import android.content.Intent; 
    import android.database.Cursor; 
    import android.database.sqlite.SQLiteDatabase; 
    import android.os.Bundle; 
    import android.text.InputType; 
    import android.view.View; 
    import android.widget.EditText; 
    import android.widget.ImageView; 
    import android.widget.Toast; 

    public class Login extends Activity{ 
     Intent i=null; 
     ImageView im=null; 
     EditText tv1,tv4; 
     boolean flag=false; 
     SQLiteDatabase db=null; 
     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.login); 
      im=(ImageView)findViewById(R.id.show_hide2); 
      tv1=(EditText)findViewById(R.id.phone2); 
      tv4=(EditText)findViewById(R.id.password2); 
      db=openOrCreateDatabase("mydb", MODE_PRIVATE, null); 
     // db.execSQL("create table if not exists login(name varchar,mobile_no varchar,email_id varchar,password varchar,flag varchar)"); 

      im.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View arg0) { 

        if(flag==false) 
        { 

         tv4.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); 
         flag=true; 
        } 
        else 
        { 

         tv4.setInputType(129); 
         flag=false; 

        } 
       } 
      }); 
     } 

     public void action(View v) 
     { 
     switch(v.getId()) 
     { 
     case R.id.signin2: 
      i=new Intent(this,Signin.class); 
      startActivityForResult(i, 500); 
      overridePendingTransition(R.anim.slide_in_top, R.anim.slide_out_bottom); 
      finish(); 
      break; 
     case R.id.start: 
      String mobile_no=tv1.getText().toString(); 
      String password=tv4.getText().toString(); 
      if(mobile_no==null||mobile_no==""||mobile_no.length()<10) 
      { 
       show("Please Enter Correct mobile number."); 
      } 
      else if(password==null||password==""||password.length()<6) 
      { 
       show("Please Enter Correct Password."); 
      } 
      else 
      {  
       Cursor c=db.rawQuery("select * from login where mobile_no='"+mobile_no+"' and password='"+password+"'",null); 
       c.moveToFirst(); 
       if(c.getCount()>0) 
       { 
       i=new Intent(this,Welcome.class); 
       startActivityForResult(i,500); 
       overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); 
       db.close(); 
       finish(); 
       } 
       else 
        show("Wrong Password or Mobile number."); 

      } 
      break; 
     } 
     } 
     @Override 
     protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right); 
     } 

     public void show(String str) 
     { 
     Toast.makeText(this, str, Toast.LENGTH_LONG).show();  
     } 

    } 

和我的MainActivity

package com.example.datewithme; 

    import android.os.Bundle; 
    import android.app.Activity; 
    import android.view.Menu; 

    public class MainActivity extends Activity { 

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

     @Override 
     public boolean onCreateOptionsMenu(Menu menu) { 
      // Inflate the menu; this adds items to the action bar if it is present. 
      getMenuInflater().inflate(R.menu.main, menu); 
      return true; 
     } 

    } 

和我簽到的.java

package com.example.datewithme; 

import android.app.Activity; 
import android.content.Intent; 
import android.database.sqlite.SQLiteDatabase; 
import android.os.Bundle; 
import android.text.InputType; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.ImageView; 
import android.widget.Toast; 

public class Signin extends Activity{ 
    Intent i=null; 
    ImageView im=null; 
    EditText tv1,tv2,tv3,tv4; 
    boolean flag=false; 
    SQLiteDatabase db=null; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.signin); 
     im=(ImageView)findViewById(R.id.show_hide); 
     tv1=(EditText)findViewById(R.id.name); 
     tv2=(EditText)findViewById(R.id.email_id); 
     tv3=(EditText)findViewById(R.id.phone); 
     tv4=(EditText)findViewById(R.id.password); 
     db=openOrCreateDatabase("mydb", MODE_PRIVATE, null); 
     db.execSQL("create table if not exists login(name varchar,mobile_no varchar,email_id varchar,password varchar,flag varchar)"); 

     im.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View arg0) { 

       if(flag==false) 
       { 

        tv4.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); 
        flag=true; 
       } 
       else 
       { 

        tv4.setInputType(129); 
        flag=false; 

       } 
      } 
     }); 
    } 

    public void action(View v) 
    { 
    switch(v.getId()) 
    { 
    case R.id.login: 
     i=new Intent(this,Login.class); 
     startActivityForResult(i, 500); 
     overridePendingTransition(R.anim.slide_in_top, R.anim.slide_out_bottom); 
     finish(); 
     break; 
    case R.id.signin: 
     String name=tv1.getText().toString(); 
     String email_id=tv2.getText().toString(); 
     String mobile_no=tv3.getText().toString(); 
     String password=tv4.getText().toString(); 
     if(name==null||name==""||name.length()<3) 
     { 
      show("Please Enter Correct Name."); 
     } 
     else if(mobile_no==null||mobile_no==""||mobile_no.length()<10) 
     { 
      show("Please Enter Correct mobile number."); 
     } 
     else if(email_id==null||email_id==""||email_id.length()<10) 
     { 
      show("Please Enter Correct Email id."); 
     } 
     else if(password==null||password==""||password.length()<6) 
     { 
      show("Please Enter Strong Password."); 
     } 
     else 
     { 
      db.execSQL("insert into login values('"+name+"','"+mobile_no+"','"+email_id+"','"+password+"','nothing')"); 
      i=new Intent(this,Welcome.class); 
      startActivityForResult(i, 500); 
      overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); 
      db.close(); 
      finish(); 
     } 
     break; 
    } 
    } 
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right); 
    } 

    public void show(String str) 
    { 
    Toast.makeText(this, str, Toast.LENGTH_LONG).show();  
    } 
} 

和welcome.java

package com.example.datewithme; 

import android.app.Activity; 
import android.os.Bundle; 

public class Welcome extends Activity{ 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.welcome); 
    } 
} 

// logcat的錯誤

02-14 00:50:12.357: D/gralloc_goldfish(1045): Emulator without GPU emulation detected. 
    02-14 00:50:32.427: D/AndroidRuntime(1045): Shutting down VM 
    02-14 00:50:32.427: W/dalvikvm(1045): threadid=1: thread exiting with uncaught exception (group=0xb4af8b90) 
    02-14 00:50:32.457: E/AndroidRuntime(1045): FATAL EXCEPTION: main 
    02-14 00:50:32.457: E/AndroidRuntime(1045): Process: com.example.datewithme, PID: 1045 
    02-14 00:50:32.457: E/AndroidRuntime(1045): java.lang.IllegalStateException: Could not find a method login_sigin(View) in the activity class com.example.datewithme.MainActivity for onClick handler on view class android.widget.Button with id 'sign_in' 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at android.view.View$1.onClick(View.java:3801) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at android.view.View.performClick(View.java:4424) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at android.view.View$PerformClick.run(View.java:18383) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at android.os.Handler.handleCallback(Handler.java:733) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at android.os.Handler.dispatchMessage(Handler.java:95) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at android.os.Looper.loop(Looper.java:137) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at android.app.ActivityThread.main(ActivityThread.java:4998) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at java.lang.reflect.Method.invokeNative(Native Method) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at java.lang.reflect.Method.invoke(Method.java:515) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at dalvik.system.NativeStart.main(Native Method) 
    02-14 00:50:32.457: E/AndroidRuntime(1045): Caused by: java.lang.NoSuchMethodException: login_sigin [class android.view.View] 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at java.lang.Class.getConstructorOrMethod(Class.java:472) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at java.lang.Class.getMethod(Class.java:857) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  at android.view.View$1.onClick(View.java:3794) 
    02-14 00:50:32.457: E/AndroidRuntime(1045):  ... 11 more 
    02-14 00:50:37.817: I/Process(1045): Sending signal. PID: 1045 SIG: 9 
    02-14 00:50:41.567: D/gralloc_goldfish(1071): Emulator without GPU emulation detected. 
    02-14 00:50:46.827: D/AndroidRuntime(1071): Shutting down VM 
    02-14 00:50:46.827: W/dalvikvm(1071): threadid=1: thread exiting with uncaught exception (group=0xb4af8b90) 
    02-14 00:50:46.887: E/AndroidRuntime(1071): FATAL EXCEPTION: main 
    02-14 00:50:46.887: E/AndroidRuntime(1071): Process: com.example.datewithme, PID: 1071 
    02-14 00:50:46.887: E/AndroidRuntime(1071): java.lang.IllegalStateException: Could not find a method login_sigin(View) in the activity class com.example.datewithme.MainActivity for onClick handler on view class android.widget.Button with id 'log_in' 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at android.view.View$1.onClick(View.java:3801) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at android.view.View.performClick(View.java:4424) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at android.view.View$PerformClick.run(View.java:18383) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at android.os.Handler.handleCallback(Handler.java:733) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at android.os.Handler.dispatchMessage(Handler.java:95) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at android.os.Looper.loop(Looper.java:137) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at android.app.ActivityThread.main(ActivityThread.java:4998) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at java.lang.reflect.Method.invokeNative(Native Method) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at java.lang.reflect.Method.invoke(Method.java:515) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at dalvik.system.NativeStart.main(Native Method) 
    02-14 00:50:46.887: E/AndroidRuntime(1071): Caused by: java.lang.NoSuchMethodException: login_sigin [class android.view.View] 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at java.lang.Class.getConstructorOrMethod(Class.java:472) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at java.lang.Class.getMethod(Class.java:857) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  at android.view.View$1.onClick(View.java:3794) 
    02-14 00:50:46.887: E/AndroidRuntime(1071):  ... 11 more 
    02-14 00:55:13.447: D/gralloc_goldfish(1098): Emulator without GPU emulation detected. 
    02-14 00:55:17.007: D/AndroidRuntime(1098): Shutting down VM 
    02-14 00:55:17.007: W/dalvikvm(1098): threadid=1: thread exiting with uncaught exception (group=0xb4af8b90) 
    02-14 00:55:17.027: E/AndroidRuntime(1098): FATAL EXCEPTION: main 
    02-14 00:55:17.027: E/AndroidRuntime(1098): Process: com.example.datewithme, PID: 1098 
    02-14 00:55:17.027: E/AndroidRuntime(1098): java.lang.IllegalStateException: Could not find a method login_sigin(View) in the activity class com.example.datewithme.MainActivity for onClick handler on view class android.widget.Button with id 'sign_in' 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at android.view.View$1.onClick(View.java:3801) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at android.view.View.performClick(View.java:4424) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at android.view.View$PerformClick.run(View.java:18383) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at android.os.Handler.handleCallback(Handler.java:733) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at android.os.Handler.dispatchMessage(Handler.java:95) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at android.os.Looper.loop(Looper.java:137) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at android.app.ActivityThread.main(ActivityThread.java:4998) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at java.lang.reflect.Method.invokeNative(Native Method) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at java.lang.reflect.Method.invoke(Method.java:515) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at dalvik.system.NativeStart.main(Native Method) 
    02-14 00:55:17.027: E/AndroidRuntime(1098): Caused by: java.lang.NoSuchMethodException: login_sigin [class android.view.View] 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at java.lang.Class.getConstructorOrMethod(Class.java:472) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at java.lang.Class.getMethod(Class.java:857) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  at android.view.View$1.onClick(View.java:3794) 
    02-14 00:55:17.027: E/AndroidRuntime(1098):  ... 11 more 
    02-14 00:56:38.717: I/Process(1098): Sending signal. PID: 1098 SIG: 9 
+0

給我們錯誤代碼和logcat。 – hypd09

+0

消息很清楚! – 2014-02-14 06:14:35

+0

請嘗試下面的解決方案,讓我知道它是否工作與否。 – InnocentKiller

回答

2

刪除android:onClick="login_sigin"android:onClick="login_sigin"這從您的按鈕XML

<Button 
      android:id="@+id/sign_in" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:onClick="login_sigin" 
      android:text="Sign In"/> 

     <Button 
      android:id="@+id/log_in" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:textSize="20sp" 
      android:onClick="login_sigin"/> 

因爲你定義了onClick事件對於這一點,你不使用它。所以你的XML按鈕應該是這樣的。

<Button 
       android:id="@+id/sign_in" 
       android:layout_width="wrap_content" 
       android:layout_weight="1" 
       android:layout_height="wrap_content" 
       android:textSize="20sp" 
       android:text="Sign In" /> 

      <Button 
       android:id="@+id/log_in" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:textSize="20sp" 
       android:text="Log In" /> 

在錯誤它自它明確定義

java.lang.IllegalStateException: Could not find a method login_sigin(View) in the activity class com.example.datewithme.MainActivity for onClick handler on view class android.widget.Button with id 'sign_in' 
+0

我已經做出了改變,因爲你告訴..不幸的是,它的顯示不幸DateWithMe已停止。 – user3295933

+0

,我沒有收到任何logcat錯誤 – user3295933

+0

你可以發佈你正在得到什麼錯誤,因爲我不認爲你得到相同的錯誤。 – InnocentKiller

1

logcat的輸出:

java.lang.IllegalStateException: Could not find a method login_sigin(View) in the activity class com.example.datewithme.MainActivity for onClick handler on view class android.widget.Button with id 'sign_in' 
02-14 00:50:32.457: E/AndroidRuntime(1045): Caused by: java.lang.NoSuchMethodException: login_sigin [class android.view.View] 

logcat的本身給你你的錯誤的提示,以及解決方案。嘗試閱讀和理解。

正如你已經宣佈onClick方法sign_inlog_in按鈕在login.xml文件

<Button 
    android:id="@+id/sign_in" 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:textSize="20sp" 
    android:text="Sign In"/> 
<Button 
    android:id="@+id/log_in" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textSize="20sp" 
    android:onClick="login_sigin"/> 

You must add method to your java file with a name given in onClick attribute.

在你的代碼忘了寫login_sigin()方法在login.java文件

將此方法添加到您的login.java

public void login_sigin(view v) { 

// Actions 

}