2014-10-24 6 views
0

나는 많은 게시물을 읽었지 만 도움은되지 않았습니다. 나는 cleanre-build 프로젝트를 시도했지만 나 역시 도움이되지 못했다. 이 오류의 의미를 이해하지 못합니다. 누군가가이 오류를 해결하는 데 도움을 줄 수 있습니까?EditText에서 Button으로 변환 할 수 없습니다.

RegisterActivity.java

import android.app.Activity; 
import android.app.ProgressDialog; 
import android.content.Context; 
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; 
import library.DatabaseHandler; 
import library.UserFunctions; 

public class RegisterActivity extends Activity { 
Button buttonRegister; 
Button buttonLinkToLogin; 
EditText inputFullName; 
EditText inputEmail; 
EditText inputPassword; 
TextView registerErrorMsg; 

// JSON Response node names 
private static String KEY_SUCCESS = "success"; 
private static String KEY_ERROR = "error"; 
private static String KEY_ERROR_MSG = "error_msg"; 
private static String KEY_UID = "uid"; 
private static String KEY_NAME = "name"; 
private static String KEY_EMAIL = "email"; 
private static String KEY_CREATED_AT = "created_at"; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.register); 

    // Importing all assets like buttons, text fields 
    inputFullName = (EditText) findViewById(R.id.registerName); 
    inputEmail = (EditText) findViewById(R.id.registerEmail); 
    inputPassword = (EditText) findViewById(R.id.registerPassword); 
    buttonRegister = (Button) findViewById(R.id.buttonRegister); 
    buttonLinkToLogin = (Button) findViewById(R.id.buttonLinkToLoginScreen); 
    registerErrorMsg = (TextView) findViewById(R.id.register_error); 

    // Register Button Click event 
    buttonRegister.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      ProgressDialog progressDialog = new ProgressDialog(RegisterActivity.this); 
      progressDialog.setMessage("Registering..."); 
      RegisterTask registerTask = new RegisterTask(RegisterActivity.this, progressDialog); 
      registerTask.execute(); 
     } 
    }); 

    // Link to Login Screen 
    buttonLinkToLogin.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View view) { 
      Intent i = new Intent(getApplicationContext(), 
        LoginActivity.class); 
      startActivity(i); 
      // Close Registration View 
      finish(); 
     } 
    }); 
} 

public void registerReport(Integer responseCode) { 
    int duration = Toast.LENGTH_LONG; 
    Context context = getApplicationContext(); 

    if (responseCode == 0) { 
     Toast toast = Toast.makeText(context, "Register Error", duration); 
     toast.show(); 
    } 
    else { 
     Toast toast = Toast.makeText(context, "Register Success", duration); 
     toast.show(); 
     Intent i = new Intent(getApplicationContext(), 
       DashboardActivity.class); 
     startActivity(i); 
     finish(); 
    } 



} 

public EditText findViewById(int registeremail) { 
    // TODO Auto-generated method stub 
    return null; 
} 
} 

그리고 라인이

buttonRegister = (Button) findViewById(R.id.buttonRegister); 
buttonLinkToLogin = (Button) findViewById(R.id.buttonLinkToLoginScreen); 

Register.xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#3b3b3b" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="10dip" > 
    <!-- View Title Label --> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dip" 
     android:text="REGISTER" 
     android:textSize="25dip" 
     android:textStyle="bold" /> 
    <!-- Name Label --> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Full Name" /> 
    <!-- Name TextField --> 
    <EditText 
     android:id="@+id/registerName" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:singleLine="true"/> 

    <!-- Email Label --> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Email" /> 
    <!-- Email TextField --> 
    <EditText 
     android:id="@+id/registerEmail" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:singleLine="true"/> 

    <!-- Password Label --> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="15dip" 
     android:text="Password" /> 
    <!-- Password TextField --> 
    <EditText 
     android:id="@+id/registerPassword" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:password="true" 
     android:singleLine="true"/> 


    <!-- Error message --> 
    <TextView android:id="@+id/register_error" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textColor="#e30000" 
       android:padding="10dip" 
       android:textStyle="bold"/> 

    <!-- Login Button --> 

    <Button 
     android:id="@+id/buttonRegister" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dip" 
     android:text="Register" /> 

    <!-- Link to Login Screen --> 
    <Button 
     android:id="@+id/buttonLinkToLoginScreen" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="40dip" 
     android:background="@null" 
     android:text="Already registred. Login Me!" 
     android:textColor="#21dbd4" 
     android:textStyle="bold" /> 
</LinearLayout> 

</ScrollView> 

갱신

Button buttonRegister; 
Button buttonLinkToLogin; 
있습니다

나는 당신이 TextFields하지 Buttons로 두 개의 버튼을 선언한다고 가정 콘솔 출력이

res\layout\register.xml:75: error: Error: No resource found that matches the given name (at 'id' with value '@id/buttonLinkToLoginScreen'). 
res\layout\register.xml:67: error: Error: No resource found that matches the given name (at 'id' with value '@id/buttonRegister'). 
+0

당신을 위해 테스트 할 수있는 데모가 있으십니까? 또한 완전한 stacktrace를 추가하십시오. – Manmohan

+0

프로젝트에 오류가있어 말하기 때문에 runnit을 할 수 없습니다. 오류는이 두 줄입니다. –

+0

입력 한 Register.xml보기 파일을 팽창 하시겠습니까? 귀하의 질문에 전체 오류 스택 트레이스를 복사하여 붙여 넣으면 더 자세한 내용을 볼 수 있습니다. – vitalikaz

답변

1

에서 볼 수 있습니다. 그래서 프로젝트에 오류가 있으며 runned조차되지 않는다고 말합니다. 실행되고 오류가 발생하면 캐스팅 할 수 없으며 문제는 발생하지 않습니다.

컨트롤 붙여 넣기 컨트롤 붙여 넣기 선언하고 해당 형식을 잊어 버린 것 같아요.

UPDATE

findViewById 방법을 재정의? 그것을 제거. 보시다시피 올바른 객체를 반환하는 기본 메소드를 무시하고 있습니다. 귀하의 메서드는 잘못된 개체 (TextField)를 반환합니다. 즉, TextField에서 Button으로 캐스팅 할 수 없다고 말하고, 충분하지 않은 경우 null 인 경우입니다.

+0

제 질문을 전체'register.xml'로 업데이트했습니다. –

+0

필드'declaration'을 제공하십시오.문제가 Java 코드에 있고 선언이 무엇인지 모르는 경우 Java 클래스의 전체 코드를 제공하십시오. –

+0

전체'RegisterActivity.java' 코드로 업데이트되었습니다. –

0

3 가지 가능한 솔루션;

  • 는 XML 파일에서 ID 년대에 모두 소문자를 시도
  • 이클립스를 다시 시작
  • 오류가, 그렇지 않으면 ID의의를 인식 할 수 없습니다, 고해상도 디렉토리에 분명 남아 있어야 어떤 빨간색 표시

이 경우 종종 이러한 종류의 문제를 해결합니다.

+0

소문자를 사용하지 않으려 고 시도했습니다. 또한 Eclipse를 다시 시작합니다. 빨간색 마크는'res'에서'src'에 있습니다. –

+0

다시 ... 필드 선언문을 제공합니다 –

+0

나는 이것을 ony buttonRegister와 buttonLinkToLogin으로 테스트했고 제대로 작동합니다. xmlns : android = "http://schemas.android.com/apk/res/android" 을 부모 LinearLayout에 포함시키지 않았습니까? –

관련 문제