0

this question is related to this one. My activity can't implement lifecycleOwner I suppose this question may contains the answer of lifecycleOwner one. I find this answer AppCompatActivity not implementing LifecycleOwner but it didn't solve my problem

I'm doing an android project in android. In every activity, it just doesn't recognize my imports. like this:

private EditText edAccount;
edAccount = findViewById(R.id.edAccount);

it says: required: android.widget.EditText Found:android.view.View But I do imports android.widget.EditText. This happened after i import a new library module. But i don't know what's going on.

Also, the AppCompatActivity doesn't implement lifecycleOwner anymore.

Thank you for your answer

the build.gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.finaldesigntest"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable true
        }
    }
    buildToolsVersion '27.0.3'
    productFlavors {
    }
}


repositories {
    flatDir {
        dirs 'libs'
    }
    mavenCentral()
}

repositories {
    flatDir { dirs project(':library').file('libs') }
//    maven { url 'https://jitpack.io' }
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
    mavenCentral()
}

allprojects {
    repositories {
        //jcenter()
        //maven { url 'https://maven.google.com' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.contrarywind:Android-PickerView:4.0.1'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation project(':library')
    compile 'io.reactivex.rxjava2:rxjava:2.1.6'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'android.arch.lifecycle:runtime:1.1.1'
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    implementation 'android.arch.lifecycle:reactivestreams:1.1.1'
    annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
}

this is activity's layout.xml

   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.finaldesigntest.LoginActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="90dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textSize="18sp"
            android:text="Account: "/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/edAccount"
            android:layout_gravity="center_vertical"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="90dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textSize="18sp"
            android:text="Password: "/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/edPassword"
            android:layout_gravity="center_vertical"
            android:inputType="textPassword"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/remember_pass"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:text="Remember password"/>
    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:id="@+id/login"
        android:text="Login"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/view_login_result"/>

</LinearLayout>
Endrol
  • 1
  • 4

2 Answers2

2

Make sure you build your project successfully. it only happen when gradle build is not success.

Prashant Jajal
  • 3,469
  • 5
  • 24
  • 38
0

You need to cast it like this:

 private EditText edAccount;
 edAccount = (EditText) findViewById(R.id.edAccount);
D. O.
  • 109
  • 2
  • 9
  • I know it works, but i wanna know why it suddenly went wrong. I hope to know the reason to solve this one. https://stackoverflow.com/q/49812582/9608562 – Endrol Apr 13 '18 at 12:54