0

I tried to build a scanner and generator in 1 app. When I press the generator button, It suddenly crash. I don't have any error or warning in my log.

Here's my generator code:

public class GeneratorActivity extends AppCompatActivity {

EditText text;
Button gen_btn;
ImageView image;
String text2Qr;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_generator);
    text = findViewById(R.id.text);
    gen_btn = findViewById(R.id.gen_btn);
    image = findViewById(R.id.image);
    gen_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            text2Qr = text.getText().toString().trim();
            MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
            try{
                BitMatrix bitMatrix = multiFormatWriter.encode(text2Qr, BarcodeFormat.QR_CODE,200,200);
                BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
                Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
                image.setImageBitmap(bitmap);
            }
            catch (WriterException e){
                e.printStackTrace();
            }
        }
    });
}}

MainActivity code:

public class MainActivity extends AppCompatActivity {

Button gen, scan;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    gen = findViewById(R.id.gen);
    scan = findViewById(R.id.scan);
    gen.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent gIntent = new Intent(MainActivity.this, GeneratorActivity.class);
            startActivity(gIntent);
        }
    });
    scan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent rIntent = new Intent(MainActivity.this, ReaderActivity.class);
            startActivity(rIntent);
        }
    });
}}

Does anybody know how to fix this? Please help me.

UPDATE

Here's my xml code for the generator:

<EditText
    android:id="@+id/text"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="415dp"
    android:layout_marginTop="50dp"
    android:hint="@string/enter_text_to_generate"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/view" />

<Button
    android:id="@+id/gen_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="33dp"
    android:text="@string/generate"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/text" />

<view
    android:id="@+id/view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="48dp"
    android:layout_marginTop="155dp"
    android:background="@android:color/black"
    app:layout_constraintBottom_toTopOf="@+id/text"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="0dp"
    android:layout_height="293dp"
    android:layout_below="@+id/view"
    android:layout_marginEnd="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="188dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <ImageView
        android:id="@+id/image"
        android:layout_width="348dp"
        android:layout_height="match_parent"
        android:contentDescription="@string/todo" />
</LinearLayout>

I hope this will help my issue :(

UPDATED: This is fix by stupid typo from me ;). Thank you so much for everyone that replied to my question this far. I can't say much how grateful I am. Especially for the guy that I already vote for the right answer. You're truly a hero!

2 Answers2

0

enter image description herePlease don't vote. I know this is not a solution but this will definitely help us in identifying the issue.

This is regarding finding the error in the logcat. May be once Ricardo F. Seikka share the logcat, I can remove this answer.

On Windows (10), this is what I do when the logcat doesn't capture error(what actually happens is the logcat gets cleared when there is an error(only for some errors) and new logcat gets generated hence we cannot see the error in logcat)

@Ricardo F. Seikka (I assume you are using Windows too)

  • Launch your app
  • before clicking the button run below command in terminal

    "C:\Users\qwerty\AppData\Local\Android\sdk\platform-tools\adb.exe" logcat -c

(instead of qwerty add your name/ look for adb.exe)this will clear the logcat. - after clicking the button, run below command

"C:\Users\Dell\qwerty\Local\Android\sdk\platform-tools\adb.exe" logcat -d > "C:\Users\Dell\qwerty\log.txt"
  • then open log.txt, search for fatal, next few lines should give you an idea what is the issue.

If you are using any other OS, then search for adb.exe and try my suggestion.

tanni tanna
  • 544
  • 4
  • 12
  • I couldn't find the adb.exe, and from Local, I don't have android folder on it – Ricardo F. Seikka Feb 02 '18 at 19:16
  • try this, in android studio, tools->android-> SDK Manager. (on left) Appearance & Behavior->System Settings-> Android SDK . select Android SDK, on the Top Right 'Android SDK Location', here is where you can find adb.exe https://stackoverflow.com/questions/35854238/where-is-adb-exe-in-windows-10-located – tanni tanna Feb 02 '18 at 19:22
  • I'm working on windows 7. I can't find the sdk folder, but there's an android folder – Ricardo F. Seikka Feb 02 '18 at 19:23
  • Thank you so much. I just found the adb.exe. Now what should i do about it? – Ricardo F. Seikka Feb 02 '18 at 19:28
  • logcat -d > *.txt ( don't miss the > , because > is the one which redirects logcat to text file). – tanni tanna Feb 02 '18 at 19:31
  • when i tried to open the adb.exe, it just close by itself – Ricardo F. Seikka Feb 02 '18 at 19:31
  • with open do you mean, you trying to run it by double clicking on it? – tanni tanna Feb 02 '18 at 19:33
  • okay, now there's 'waiting for device' on the adb.exe terminal. what should i do? – Ricardo F. Seikka Feb 02 '18 at 19:35
  • see the answer section, I want you to run the command like that on terminal. – tanni tanna Feb 02 '18 at 19:36
  • open your app, run the first command. this will clear the logcat (just to make our job easy in finding the actual issue) then click the button, app crashes, run the second command ( this will redirect the logcat to that log file), – tanni tanna Feb 02 '18 at 19:37
  • any luck? were you able to get the log.txt? – tanni tanna Feb 02 '18 at 19:47
  • I can't open the SDK cause it makes my laptop run very slowly. But I already got an answer from Eduardo Herzer. Thank you so much for want to help me on this. I never been got help like this before in this stackoverflow. I'm really grateful. I have another 2 problems related to this case. If you can, please help me solve it. Again, Thank you very much :) – Ricardo F. Seikka Feb 02 '18 at 20:00
  • no problem mate:)Just remember this method. You will find it useful when logcat gets cleared. Put your questions on SO, I am happy to help you (If I can). – tanni tanna Feb 02 '18 at 20:10
  • my 2 other problems is the scanner result and the qr code image should be downloadable. But I can't really asking questions in the comment sections right? – Ricardo F. Seikka Feb 02 '18 at 20:16
  • better post on SO, I f I don't know the issue then will not be of any help to you. but there are many developers better than me, who would definitely help you. – tanni tanna Feb 02 '18 at 20:26
  • I already post the scanner result issue you can check it, but I can't post the download issue.I think i already on my limit to ask a questions. – Ricardo F. Seikka Feb 02 '18 at 20:38
0

Ok. I got your problem! (If it isn't a typo in the question...)

At your xml you declared a component named view, when the correct is View with an uppercase:

<View
    android:id="@+id/view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="48dp"
    android:layout_marginTop="155dp"
    android:background="@android:color/black"
    app:layout_constraintBottom_toTopOf="@+id/text"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

Let me know if it solves your problem

Eduardo Herzer
  • 2,033
  • 21
  • 24
  • Oh my God it works! hahahaha, I really didn't notice that. I still can't believe this is a typo problem. Thank you so much sir you help me a lot! I can't say how grateful I am. I still have 2 problems that related to this case. Can you help me solve it? I really need this to be done soon. Again, Thank you so much Sir! ;) – Ricardo F. Seikka Feb 02 '18 at 20:02