zxing-android-embedded icon indicating copy to clipboard operation
zxing-android-embedded copied to clipboard

Unresolved class 'MainActivity'

Open 25DevDroid opened this issue 4 years ago • 1 comments

When adding the following implementtation: <<implementation 'com.journeyapps:zxing-android-embedded:4.1.0'>> in gradle, I get the the unresolved class 'MainActivity error message from main activity xml file and also, Error running 'app' Default Activity not found. This is when I try to run the app. If I clear fo the implement and sync again the error goes off but IntentIntegrator won't work anymore.

Which library version are you using? E.g. 4.1.0.

Which phone/tablet are you using, and which Android version does it run? (e.g. AVD API22)

Does the same happen on other devices or an emulator? YES

Can you reproduce the issue in the sample project included with the library? If not, can you provide your own sample project or sample code that produces this error?

XML

<RelativeLayout 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" tools:context=".MainActivity"> //********************** Here '.MaintActivity' **** is red showing unresolved class...

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="SCAN NOW"
    android:textSize="30sp"
    android:layout_centerInParent="true"
    android:id="@+id/button_Scan"
    android:backgroundTint="#D9DADC"
    android:textColor="#E5DEEF"/>

GRADLE apply plugin: 'com.android.application'

repositories { jcenter() }

android { compileSdkVersion 30

defaultConfig {
    applicationId "com.dev.cashout"
    minSdkVersion 15
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

}

dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'com.journeyapps:zxing-android-embedded:4.1.0'

}

MAIN package com.dev.cashout;

import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast;

import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

Button button_Scan;

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

    button_Scan = findViewById(R.id.button_Scan);
    button_Scan.setOnClickListener((View.OnClickListener) this);

}

@Override
public void onClick(View v) {
    scanCode();
}

private void scanCode(){
    IntentIntegrator integrator = new IntentIntegrator(this);
    integrator.setCaptureActivity(CaptureAct.class);
    integrator.setOrientationLocked(false);
    integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
    integrator.setPrompt("Scanning Code");
    integrator.initiateScan();

    //Added code for torch light in case environment is dark
    integrator.setTorchEnabled(true);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
    if (result != null){
        if (result.getContents() != null){
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(result.getContents());
            builder.setTitle("Scanning Result");
            builder.setPositiveButton("Scan Again", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    scanCode();
                }
            }).setNegativeButton("Finish", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();

        } else{
            Toast.makeText(this, "No Results", Toast.LENGTH_LONG).show();
        }

    } else{
        super.onActivityResult(requestCode, resultCode, data);

    }
}

}

In the case of an error do you have a stack trace or adb logs? Error running 'app' Default Activity not found

12-15 18:52:30.678 5398-5398/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<< 12-15 18:52:30.679 5398-5398/? D/AndroidRuntime: CheckJNI is ON 12-15 18:52:30.698 5398-5398/? E/memtrack: Couldn't load memtrack module (No such file or directory) 12-15 18:52:30.698 5398-5398/? E/android.os.Debug: failed to load memtrack module: -2 12-15 18:52:30.709 5398-5398/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am

--------- beginning of system

12-15 18:52:30.712 1558-2787/system_process I/ActivityManager: Force stopping com.dev.cashout appid=10062 user=0: from pid 5398 12-15 18:52:30.712 1558-2787/system_process I/ActivityManager: Killing 5190:com.dev.cashout/u0a62 (adj 0): stop com.dev.cashout 12-15 18:52:30.713 1558-2787/system_process W/libprocessgroup: failed to open /acct/uid_10062/pid_5190/cgroup.procs: No such file or directory 12-15 18:52:30.713 1558-2787/system_process W/ActivityManager: Force removing ActivityRecord{3089ea00 u0 com.dev.cashout/.MainActivity t249}: app died, no saved state 12-15 18:52:30.733 1558-1587/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! 12-15 18:52:30.737 5398-5398/? D/AndroidRuntime: Shutting down VM 12-15 18:52:31.562 1558-2786/system_process W/art: Long monitor contention event with owner method=void com.android.server.wm.WindowAnimator$1.run() from WindowAnimator.java:124 waiters=0 for 754ms 12-15 18:52:31.694 1843-2149/com.google.android.googlequicksearchbox D/EGL_emulation: eglMakeCurrent: 0xae964220: ver 2 0 12-15 18:52:31.751 1843-1843/com.google.android.googlequicksearchbox I/Choreographer: Skipped 55 frames! The application may be doing too much work on its main thread. 12-15 18:52:32.492 1558-1575/system_process W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 5190 uid 10062 12-15 18:52:32.493 1843-1843/com.google.android.googlequicksearchbox I/Choreographer: Skipped 44 frames! The application may be doing too much work on its main thread. 12-15 18:52:32.498 1843-2149/com.google.android.googlequicksearchbox D/EGL_emulation: eglMakeCurrent: 0xae964220: ver 2 0 12-15 18:52:32.540 2057-2057/com.google.android.googlequicksearchbox W/LocationOracleImpl: Best location was null 12-15 18:52:32.541 2057-2057/com.google.android.googlequicksearchbox W/ConcurrentUtils: Queue length for executor GrecoExecutor with 1 threads is now 10. Perhaps some tasks are too long, or the pool is too small. 12-15 18:52:32.552 1843-2149/com.google.android.googlequicksearchbox D/EGL_emulation: eglMakeCurrent: 0xae964220: ver 2 0 12-15 18:52:32.570 1843-2149/com.google.android.googlequicksearchbox D/EGL_emulation: eglMakeCurrent: 0xae964220: ver 2 0 12-15 18:52:32.572 2014-2267/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation() 12-15 18:52:32.572 1843-2149/com.google.android.googlequicksearchbox W/OpenGLRenderer: Incorrectly called buildLayer on View: aep, destroying layer... 12-15 18:52:32.572 1843-2149/com.google.android.googlequicksearchbox D/EGL_emulation: eglMakeCurrent: 0xae964220: ver 2 0 12-15 18:52:32.598 2014-2267/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation() 12-15 18:52:32.603 2014-2267/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation() 12-15 18:52:32.652 2014-2267/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation() 12-15 18:52:32.657 2183-2260/com.google.android.gms I/Icing: IndexChimeraService.getServiceInterface callingPackage=com.google.android.googlequicksearchbox componentName=null serviceId=21 12-15 18:52:32.679 2183-4908/com.google.android.gms I/Icing: Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0, imm upload true

25DevDroid avatar Dec 15 '20 18:12 25DevDroid

This is likely a general issue in the application, and not in this library. Looks at the suggestions on StackOverflow: https://stackoverflow.com/questions/15825081/default-activity-not-found-on-android-studio-upgrade

If you are convinced it is an issue with the library, please upload the complete project somewhere (e.g. public github repo), the pasted code above is not quite enough.

rkistner avatar Jan 11 '21 08:01 rkistner