Error:Execution failed for task ':app:transformClassesWithDexForDebug'. - java

For some reason when i run the app in Android studio its giving me this:
Error:Could not create the Java Virtual Machine.
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
Error:A fatal exception has occurred. Program will exit.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\Java\jdk1.7.0_80\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
This happnes in android studio. Here is my app:
MainActivity.java:
package com.example.amanuel.webview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private Button button;
private WebView webView;
private EditText editText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickEvent();
}
public void OnClickEvent(){
button = (Button) findViewById(R.id.Url_Button);
webView = (WebView) findViewById(R.id.webView);
editText = (EditText) findViewById(R.id.Edit_Text_Url);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String url = editText.getText().toString();
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl(url);
}
});
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.amanuel.webview.MainActivity">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="URL"
android:id="#+id/Url_Button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webView"
android:layout_below="#+id/Edit_Text_Url"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/Edit_Text_Url"
android:layout_below="#+id/Url_Button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="https://google.com" />
</RelativeLayout>
And AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.amanuel.webview" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Help would be really appreciated!

You might be having multiple dex files with same signatures to fix this add this in your app level gradle file.
defaultConfig {
multiDexEnabled true
}

This ERROR have POSSIBLE SOLUTION
SOLUTION 1.
If some conflicting drawable resources found then It give the same error. So you have to clean the Project and rebuild it.
SOLUTION 2.
Problem with RAM : So close the application which are not used. and free the Memory RAM.
SOLUTION 3.
GC overhead (out of memory) :
so add this in build.gradle file.
android {
dexOptions {
incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g" // 2g should be also OK
}
}

Related

Android Internet Connectivity Listener Problem

I would like to put a Network Detector in an Android application, to inform a Screen immediately the Network state even if that state is changing. I have study similar questions in:
Android: Internet connectivity change listener
So my Java code in Main Activity is:
package com.example.netdetector;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
private TextView Screen;
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Screen = (TextView) findViewById(R.id.Screen);
Screen.setText("Start!");
ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
#Override
public void onAvailable(Network network) {
// network available
Screen.setText("Net On!");
}
#Override
public void onLost(Network network) {
// network unavailable
Screen.setText("Net Off!");
}
};
ConnectivityManager connectivityManager =
(ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
connectivityManager.registerDefaultNetworkCallback(networkCallback);
} else {
NetworkRequest request = new NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build();
connectivityManager.registerNetworkCallback(request, networkCallback);
}
}
}
The AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.netdetector">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.NetDetector">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The Layout activity_main.xml is:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<TextView
android:id="#+id/Screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Hello World!"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.222" />
</androidx.constraintlayout.widget.ConstraintLayout>
There are some issues:
Starting the App with the Network Off, the Screen displays "Start!" instead of "Net Off!"
Starting the App with the Network On, the Screen displays "Net On" that is fine
On changing Internet state while the app is running the Screen displays the right text for a few moments and the app closes immediately.
How can I fix 1 and 3? What went wrong?
Thanks
Nickolas

App stops when launching a new activity

I've been trying to launch a new activity in my app and, although it does for a moment, inmediately after opening the new screen, the app stops. I've already added the new actvity to the manifest.
This is the method I use to call to the new activity, whuich worked perfectly when it only had the toast in the clickListener:
public void Bs()
{
View.OnClickListener listSet = new View.OnClickListener()
{
#Override
public void onClick(View view)
{
Toast.makeText(getApplicationContext(), "settings", Toast.LENGTH_LONG).show();
Intent intent= new Intent(MainActivity.this, Set.class);
startActivity(intent);
}
};
b= (ImageButton) findViewById(R.id.imageButton7);
b.setOnClickListener(listSet);
}
This is the class that is being called:
public class Set extends Activity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
}
}
And this is the layout class setting that only has a textview(I've tried several layouts and nne of them work, so I guess this is no the problem but I add it anyway in case it helps):
?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="0dp"
android:text="#string/toolbar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
These are the errors I have in the logcat:
--------- beginning of crash
07-23 07:10:04.022 3267-2868/? A/google-breakpad: -----BEGIN BREAKPAD MICRODUMP-----
07-23 07:10:04.022 3267-2868/? A/google-breakpad: V WebView:51.0.2704.90
(...)
07-23 07:10:11.548 2202-2891/? E/SystemUpdateService: Failed to call RecoverySystem.cancelScheduledUpdate
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at xae.c(:com.google.android.gms:134)
at afuw.d(:com.google.android.gms:195)
at afuw.p(:com.google.android.gms:2178)
at afuw.a(:com.google.android.gms:448)
at afuw.doInBackground(:com.google.android.gms:50475)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.io.IOException: cancel scheduled update failed
at android.os.RecoverySystem.cancelScheduledUpdate(RecoverySystem.java:555)
at java.lang.reflect.Method.invoke(Native Method) 
at xae.c(:com.google.android.gms:134) 
at afuw.d(:com.google.android.gms:195) 
at afuw.p(:com.google.android.gms:2178) 
at afuw.a(:com.google.android.gms:448) 
at afuw.doInBackground(:com.google.android.gms:50475) 
at android.os.AsyncTask$2.call(AsyncTask.java:304) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at java.lang.Thread.run(Thread.java:761) 
07-23 07:10:12.453 2202-3333/? W/art: Verification of com.google.android.gms.common.data.DataHolder[] com.google.android.gms.games.broker.AppContentAgent.loadCardStream$3489344c(com.google.android.gms.games.broker.GamesClientContext, com.google.android.gms.games.broker.AppContentContext, long) took 841.459ms
07-23 07:10:12.592 2202-2891/? E/SystemUpdateTask: exception trying to cancel scheduled update
java.io.IOException: Failed to invoke RecoverySystem.cancelScheduledUpdate
at xae.c(:com.google.android.gms:140)
at afuw.d(:com.google.android.gms:195)
at afuw.p(:com.google.android.gms:2178)
at afuw.a(:com.google.android.gms:448)
at afuw.doInBackground(:com.google.android.gms:50475)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.lang.Thread.run(Thread.java:761)
[ 07-23 07:10:12.629 2443: 2488 D/ ]
HostConnection::get() New Host Connection established 0x895a1900, tid 2488
(...)
07-23 07:10:44.198 1534-2908/? E/RecoverySystemService: Timed out connecting to uncrypt socket
07-23 07:10:44.198 1534-2908/? E/RecoverySystemService: Failed to connect to uncrypt socket
07-23 07:10:44.201 2202-3376/? E/SystemUpdateService: Failed to call RecoverySystem.cancelScheduledUpdate
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at xae.c(:com.google.android.gms:134)
at afuw.d(:com.google.android.gms:195)
at afuw.p(:com.google.android.gms:2178)
at afuw.a(:com.google.android.gms:448)
at afuw.doInBackground(:com.google.android.gms:50475)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.io.IOException: cancel scheduled update failed
at android.os.RecoverySystem.cancelScheduledUpdate(RecoverySystem.java:555)
at java.lang.reflect.Method.invoke(Native Method) 
at xae.c(:com.google.android.gms:134) 
at afuw.d(:com.google.android.gms:195) 
at afuw.p(:com.google.android.gms:2178) 
at afuw.a(:com.google.android.gms:448) 
at afuw.doInBackground(:com.google.android.gms:50475) 
at android.os.AsyncTask$2.call(AsyncTask.java:304) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at java.lang.Thread.run(Thread.java:761) 
07-23 07:10:44.201 2202-3376/? E/SystemUpdateTask: exception trying to cancel scheduled update
java.io.IOException: Failed to invoke RecoverySystem.cancelScheduledUpdate
at xae.c(:com.google.android.gms:140)
at afuw.d(:com.google.android.gms:195)
at afuw.p(:com.google.android.gms:2178)
at afuw.a(:com.google.android.gms:448)
at afuw.doInBackground(:com.google.android.gms:50475)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.lang.Thread.run(Thread.java:761)
Am I doing something wrong when calling the new activity? Or is it the class I'm calling the one isn't fine?
EDIT
This is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xx.yy">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:debuggable="false"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.xx.yy.MainActivity"
android:configChanges= "orientation|screenSize"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.xx.yy.Set"
android:screenOrientation="portrait">
</activity>
</application>
</manifest>
I have been doing some more attempts and I think the problem was I had fullScreen on the first activity but not on the second one. Therefore, adding these two lines to the Set class solved the problem:
public class Set extends Activity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.settings);
}
}
Can you share your MANIFEST file here
I tried the similar kind of code you were written, Check the working code below.
MainActivity.java
package com.service.rajeshm.activitytest;
import android.content.Intent;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View.OnClickListener listSet = new View.OnClickListener()
{
#Override
public void onClick(View view)
{
Toast.makeText(getApplicationContext(), "settings", Toast.LENGTH_LONG).show();
Intent intent= new Intent(MainActivity.this, Set.class);
startActivity(intent);
}
};
ImageButton b= (ImageButton) findViewById(R.id.imageButton1);
b.setOnClickListener(listSet);
}
}
activity_main.xml
<?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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.service.rajeshm.activitytest.MainActivity">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="17dp"
android:id="#+id/imageButton1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Set.java
package com.service.rajeshm.activitytest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class Set extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set);
}
}
activity_set.xml
<?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:id="#+id/activity_set"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.service.rajeshm.activitytest.Set">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#android:drawable/btn_star_big_on"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="64dp"
android:layout_marginStart="64dp"
android:layout_marginTop="48dp"
android:id="#+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="32dp"
android:layout_marginEnd="32dp" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.service.rajeshm.activitytest">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Set"></activity>
</application>
</manifest>

I want to translate english text to hindi using following API

Following is my TextActivity
package com.ds.texar;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
import java.util.Locale;
import java.util.concurrent.ExecutionException;
public class TextActivity extends AppCompatActivity {
Context context;
TextToSpeech textToSpeech;
private String textFromMain = "";
ToggleButton languageToggleButton;
private String outputHindiString = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//setting text string received from main activity
final TextView textView = (TextView)findViewById(R.id.mtextview);
textFromMain = getIntent().getStringExtra("mytext");
textView.setText(textFromMain);
context = getApplicationContext();
textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener(){
#Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
textToSpeech.setLanguage(Locale.UK);
}
}
});
languageToggleButton = (ToggleButton) findViewById(R.id.language_toggle_button);
languageToggleButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(languageToggleButton.isChecked()){
try {
Translate.setHttpReferrer("http://android-er.blogspot.com/");
outputHindiString = Translate.execute(textFromMain,
Language.ENGLISH, Language.HINDI);
} catch (Exception ex) {
ex.printStackTrace();
outputHindiString = "Error";
}
textView.setText(outputHindiString);
}
else{
textView.setText(textFromMain);
}
}
});
FloatingActionButton copyText = (FloatingActionButton) findViewById(R.id.copy_text);
copyText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("myText", textFromMain);
clipboard.setPrimaryClip(clip);
Toast.makeText(context, "Your text copied.", Toast.LENGTH_SHORT).show();
// toast.setGravity(Gravity.TOP| Gravity.LEFT, 10, 300);
// toast.show();
}
});
final FloatingActionButton textToSpeechButton = (FloatingActionButton) findViewById(R.id.text_to_speech);
textToSpeechButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Toast.makeText(getApplicationContext(), textFromMain, Toast.LENGTH_SHORT).show();
textToSpeech.speak(textFromMain, TextToSpeech.QUEUE_FLUSH, null, null);
}
});
}
#Override
public void onPause(){
if(textToSpeech !=null){
textToSpeech.stop();
textToSpeech.shutdown();
}
super.onPause();
}
}
Here is Layout xml file
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.ds.texar.TextActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include
android:id="#+id/include2"
layout="#layout/content_text" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/text_to_speech"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="#android:drawable/ic_lock_silent_mode_off" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/copy_text"
android:layout_width="51dp"
android:layout_height="55dp"
android:layout_gravity="top|left"
android:layout_margin="16dp"
android:clickable="true"
app:fabSize="mini"
app:layout_anchor="#+id/include2"
app:layout_anchorGravity="bottom|right"
app:srcCompat="?attr/actionModeCopyDrawable" />
<ToggleButton
android:id="#+id/language_toggle_button"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:layout_margin="16dp"
android:background="#drawable/check"
android:textOff=""
android:textOn=""
android:focusable="false"
android:focusableInTouchMode="false"
app:layout_anchor="#+id/include2"
app:layout_anchorGravity="bottom|center_horizontal" />
</android.support.design.widget.CoordinatorLayout>
Here is AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ds.texar">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.sensor.accelerometer" />
<uses-feature android:name="android.hardware.sensor.light" />
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="ocr" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TextActivity"
android:label="#string/title_activity_text"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
Error log:
Information:Gradle tasks [:app:generateDebugSources,
:app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies,
:app:generateDebugAndroidTestSources, :app:compileDebugSources,
:app:compileDebugUnitTestSources, :app:compileDebugAndroidTestSources]
C:\Users\DELL_PC\Desktop\Texar\app\src\main\java\com\ds\texar\TextActivity.java
Error:(16, 32) error: package com.google.api.translate does not exist
Error:(17, 32) error: package com.google.api.translate does not exist
Error:(58, 29) error: cannot find symbol variable Translate Error:(60,
37) error: cannot find symbol variable Language Error:(60, 55) error:
cannot find symbol variable Language Error:(59, 49) error: cannot find
symbol variable Translate Error:Execution failed for task
':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details. Information:BUILD FAILED Information:Total time: 6.836 secs
Information:7 errors Information:0 warnings Information:See complete
output in console
Download jar file from http://code.google.com/p/google-api-translate-java/.
Import it in current project folder.
Import jar into eclipse
Right-click on the project & select Properties.
Select Java Build Path.
Select the Libraries tab.
Click the Add External JARs button.
Find the path to your JAR and add it.

Blank Page after clicking button android eclipse?

I thought I did everything right but when I click the button I get a blank page instead of a page with a text. I want that the creation.xml comes up after clicking the button on the main xml. What did I wrong ?
My main activity xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#drawable/creeper" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/hello"
android:textSize="20sp" />
<Button
android:id="#+id/button1"
android:layout_width="200dp"
android:layout_height="60dp"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:textSize="20sp"
android:text="#string/button1_text" />
</RelativeLayout>
My main activity java
package com.berkcoop.deneme;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button button1, button2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent1 = new Intent(MainActivity.this, Creation.class);
startActivity(intent1);
}
});
}
My creation xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="Creations"
android:textSize="25sp"
android:gravity="center"/>
</LinearLayout>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.berkcoop.deneme"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.berkcoop.deneme.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.berkcoop.deneme.Creation"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
and my creation java
package com.berkcoop.deneme;
import android.app.Activity;
public class Creation extends Activity{
#Override
public void setContentView(int layoutResID) {
// TODO Auto-generated method stub
super.setContentView(R.layout.creation);
}
}
Thank you..
Why do you override the setContentView method in your Creation class? Since you don't call it, it won't set the correct view.
You should call setContentView from onCreate, and as far as I know, there is no need to override setContentView.
Try this in Creation:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.creation);
}

android application error

my xml code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enable="true"
android:clickable="true"
android:apiKey="0THdCiXY7jaJ9Br1ZQahFE4Lu1xTv1hAiVJBvxQ"
/>
</RelativeLayout>
and manifest is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.haha"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".NewActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And this is main code:
package com.google.haha;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.app.Activity;
import android.os.Bundle;
public class NewActivity extends MapActivity {
/** Called when the activity is first created. */
MapController mControl;
GeoPoint GeoP;
MapView mapV;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapV=(MapView)findViewById(R.id.mapView);
mapV.displayZoomControls(true);
mapV.setBuiltInZoomControls(true);
double lat=21.00;
double longi=79.00;
GeoP=new GeoPoint((int)(lat*1E6),(int)(longi*1E6));
mControl=mapV.getController();
mControl.animateTo(GeoP);
mControl.setZoom(12);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Everything is fine but I am getting error an on line:
mapV=(MapView)findViewById(R.id.mapView);
id field is not recognised.
try to clean and rebuild your project, because that problem comes up sometimes on Eclipse IDE , the id of your MapView is not recognised on your R.java file :
Project ==> Clean ==> Choose your Project and Clic OK
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
**android:enable="true"** MUST BE android:enabled="true"
android:clickable="true"
android:apiKey="0THdCiXY7jaJ9Br1ZQahFE4Lu1xTv1hAiVJBvxQ"
/>
</RelativeLayout>

Categories