i'm building an app for my project in which it contains a layout which opens the camera and takes photo while other converts text to speech, whenever I click on the button which navigates to text to speech layout, the app is closing and I cannot reach that layout
text to speech code works fine when separately tested in a new project but when linked as a navigating page by button it closes
//code of java //
public class Text extends AppCompatActivity {
Button ak,bk;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text);
ak=(Button)findViewById(R.id.cam);
ak.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(Text.this,Camera.class);
startActivity(i);
}
});
bk=(Button)findViewById(R.id.spe);
bk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent k=new Intent(Text.this,Speech.class);
startActivity(k);
}
});
}
//code of 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=".major.Text">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/spe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text to speech"
android:textColor="#2976d5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/cam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="190dp"
android:text="camera"
android:textColor="#2976d5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</RelativeLayout>
//code of text to speech java class
public class Speech extends AppCompatActivity {
Button b1;
EditText ed1;
TextToSpeech t1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = (EditText) findViewById(R.id.editText);
b1 = (Button) findViewById(R.id.button);
t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
}
}
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String toSpeak = ed1.getText().toString();
Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH,null);
}
});
}
public void onPause() {
if (t1 != null) {
t1.stop();
t1.shutdown();
}
super.onPause();
}
}
//logcat:
2019-10-06 20:15:53.294 20959-21006/com.example.omen.loginmajor
E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
2019-10-06 20:15:53.294 20959-21006/com.example.omen.loginmajor
E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
the app keeps closing instead of going to another page
Maybe you can change
Intent k=new Intent( Text.this ,Speech.class);
to
Intent k=new Intent( getApplicationContext() ,Speech.class);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.