my app contains 2 activities a logIn activity and a second activity with a listView but when i go from the first one to the second the app crashes here's the code.
Activity 1:
package com.example.med.proapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class ActivityA extends AppCompatActivity {
EditText username, password;
Button login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
login = (Button) findViewById(R.id.button);
}
public void switchPage(View v){
String stUsername = username.getText().toString();
String stPassword = password.getText().toString();
if (stUsername.equals("admin") && stPassword.equals("123456789")){
this.startActivity(new Intent(this,ActivityB.class));
}else if (stUsername.equals("") || stPassword.equals("")) {
Toast.makeText(getBaseContext(), "Enter username and password",
Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(getBaseContext(), "Wrong entries!!!!",
Toast.LENGTH_SHORT).show();
}
}
}
Activity 2:
package com.example.med.proapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class ActivityB extends AppCompatActivity {
int[] IMAGES = {R.drawable.telephone32, R.drawable.settings32, R.drawable.percentage32, R.drawable.credit_cards_payment32, R.drawable.payment_method32};
String[] DESCRIPTIONS = {"Facture Internet", "Emission d'un", "Paiement d'un", "Paiement par carte", "Retrait d'especes"};
double[] MONTANTS = {299.00, 5000.00, 2990.00, 500.00, 1000.00};
String[] DATES = {"20/12/2011", "20/12/2011", "20/12/2011", "20/12/2011", "20/12/2011"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
ListView listView = (ListView) findViewById(R.id.listView);
CustomAdapter customAdapter = new CustomAdapter();
listView.setAdapter(customAdapter);
}
class CustomAdapter extends BaseAdapter{
@Override
public int getCount() {
return IMAGES.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = getLayoutInflater().inflate(R.layout.customlayout, null);
ImageView imageView = (ImageView)convertView.findViewById(R.id.imageView2);
TextView textView = (TextView)convertView.findViewById(R.id.textView);
TextView textView_montant = (TextView)convertView.findViewById(R.id.textView_montant);
TextView textView_date = (TextView)convertView.findViewById(R.id.textView_date);
imageView.setImageResource(IMAGES[position]);
textView.setText(DESCRIPTIONS[position]);
textView_montant.setText((int) MONTANTS[position]);
textView_date.setText(DATES[position]);
return convertView;
}
}
}
the xml file for Activity 1 :
<?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=".ActivityB">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView">
</ListView>
</LinearLayout
>
and for the second activity :
<?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"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
tools:context=".ActivityA">
<ImageView
android:id="@+id/imageView"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/bank_building2"
android:contentDescription="@string/todo" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/username"
android:layout_marginBottom="20dp"
android:hint="Enter username"
android:layout_gravity="center_horizontal" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberPassword"
android:hint="Enter password"
android:layout_marginBottom="40dp"
android:layout_gravity="center_vertical"/>
<Button
android:id="@+id/button"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:text="Log In"
android:onClick="switchPage"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
and the components layout :
<?xml version="1.0" encoding="utf-8"?>
<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">
<TextView
android:textSize="20sp"
android:id="@+id/textView_montant"
android:layout_width="96dp"
android:layout_height="34dp"
android:layout_alignTop="@+id/textView"
android:layout_alignParentEnd="true"
android:layout_marginTop="-9dp"
android:layout_marginEnd="7dp"
android:text="TextView" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="13dp"
android:layout_marginTop="47dp"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:textSize="30sp"
android:id="@+id/textView"
android:layout_width="198dp"
android:layout_height="47dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="83dp"
android:layout_marginTop="61dp"
android:text="TextView" />
<TextView
android:textSize="20sp"
android:id="@+id/textView_date"
android:layout_width="95dp"
android:layout_height="29dp"
android:layout_alignBottom="@+id/textView"
android:layout_marginStart="0dp"
android:layout_marginBottom="-6dp"
android:layout_toEndOf="@+id/textView"
android:text="TextView" />
</RelativeLayout>
i don't know what causes the crash
the full stacktrace :
2018-10-23 02:47:13.827 1889-7934/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
2018-10-23 02:47:13.827 1889-8494/? I/AudioFlinger: AudioFlinger's thread 0xe1003200 tid=8494 ready to run
2018-10-23 02:47:13.831 2932-7736/com.google.android.googlequicksearchbox:search E/IAudioFlinger: createRecord returned error -12
2018-10-23 02:47:13.831 2932-7736/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
2018-10-23 02:47:13.831 2932-7736/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
2018-10-23 02:47:13.832 2932-7736/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
2018-10-23 02:47:13.832 2932-7736/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_started SR : 16000 CC : 16 SO : 6
2018-10-23 02:47:13.836 2932-2932/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: onReady
2018-10-23 02:47:13.854 2932-7736/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_close SR : 16000 CC : 16 SO : 6
2018-10-23 02:47:13.855 2932-7926/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Detection finished
2018-10-23 02:47:13.855 2932-7926/com.google.android.googlequicksearchbox:search W/ErrorReporter: reportError [type: 211, code: 524300]: Error reading from input stream
2018-10-23 02:47:13.856 2932-3198/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Stopping hotword detection.
2018-10-23 02:47:13.857 2932-7926/com.google.android.googlequicksearchbox:search W/ErrorProcessor: onFatalError, processing error from engine(4)
com.google.android.apps.gsa.shared.speech.b.g: Error reading from input stream
at com.google.android.apps.gsa.staticplugins.microdetection.d.k.a(SourceFile:91)
at com.google.android.apps.gsa.staticplugins.microdetection.d.l.run(Unknown Source:14)
at com.google.android.libraries.gsa.runner.a.a.b(SourceFile:32)
at com.google.android.libraries.gsa.runner.a.c.call(Unknown Source:4)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.concurrent.b.g.run(Unknown Source:4)
at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(SourceFile:6)
Caused by: com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space.
at com.google.android.apps.gsa.speech.audio.Tee.j(SourceFile:103)
at com.google.android.apps.gsa.speech.audio.au.read(SourceFile:2)
at java.io.InputStream.read(InputStream.java:101)
at com.google.android.apps.gsa.speech.audio.ao.run(SourceFile:17)
at com.google.android.apps.gsa.speech.audio.an.run(SourceFile:2)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.concurrent.b.g.run(Unknown Source:4)
at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(SourceFile:6)
2018-10-23 02:47:13.857 2932-7926/com.google.android.googlequicksearchbox:search I/AudioController: internalShutdown
2018-10-23 02:47:13.858 2932-2932/com.google.android.googlequicksearchbox:search I/MicroDetector: Keeping mic open: false
2018-10-23 02:47:13.858 2932-2932/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: #onError(false)
2018-10-23 02:47:13.859 2932-6407/com.google.android.googlequicksearchbox:search I/DeviceStateChecker: DeviceStateChecker cancelled
2018-10-23 02:47:18.868 2932-2932/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: #startMicroDetector [speakerMode: 0]
2018-10-23 02:47:18.868 2932-2932/com.google.android.googlequicksearchbox:search I/AudioController: Using mInputStreamFactoryBuilder
2018-10-23 02:47:18.869 2932-2932/com.google.android.googlequicksearchbox:search I/AudioController: Created new AudioSource
2018-10-23 02:47:18.871 2932-2932/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: onReady
2018-10-23 02:47:18.887 2932-6407/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Starting detection.
2018-10-23 02:47:18.888 2932-7736/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_starting SR : 16000 CC : 16 SO : 6
2018-10-23 02:47:18.891 1889-7935/? E/AudioFlinger: not enough memory for AudioTrack size=131296
2018-10-23 02:47:18.891 1889-7935/? D/MemoryDealer: AudioTrack (0xe5f1cb80, size=4194304)
0: 0xe5f1cb90 | 0x00000000 | 0x000200E0 | A
1: 0xe5f1cd20 | 0x000200E0 | 0x000200E0 | A
2: 0xe5b88320 | 0x000401C0 | 0x000200E0 | A
3: 0xe5b884b0 | 0x000602A0 | 0x000200E0 | A
4: 0xe5b88730 | 0x00080380 | 0x000200E0 | A
5: 0xe5b888f0 | 0x000A0460 | 0x000200E0 | A
6: 0xe5b88a80 | 0x000C0540 | 0x000200E0 | A
7: 0xe5b88c60 | 0x000E0620 | 0x000200E0 | A
8: 0xe5b88de0 | 0x00100700 | 0x000200E0 | A
9: 0xe5b88fa0 | 0x001207E0 | 0x000200E0 | A
10: 0xe40fc0e0 | 0x001408C0 | 0x000200E0 | A
11: 0xe40fc290 | 0x001609A0 | 0x000200E0 | A
12: 0xe40fc3e0 | 0x00180A80 | 0x000200E0 | A
13: 0xe40fc520 | 0x001A0B60 | 0x000200E0 | A
14: 0xe40fc720 | 0x001C0C40 | 0x000200E0 | A
15: 0xe5b88db0 | 0x001E0D20 | 0x000200E0 | A
16: 0xe5271320 | 0x00200E00 | 0x000200E0 | A
17: 0xe52714b0 | 0x00220EE0 | 0x000200E0 | A
18: 0xe52716a0 | 0x00240FC0 | 0x000200E0 | A
19: 0xe40fc3b0 | 0x002610A0 | 0x000200E0 | A
The issue is with this line in CustomAdapter
textView_montant.setText((int) MONTANTS[position]);
TextView.setText(int)
expects a Resource id
.
If you want to display a number then you have to convert it into a String. Try changing like this.
textView_montant.setText(String.valueOf(MONTANTS[position]));
User contributions licensed under CC BY-SA 3.0