I'm already look for an answer in other questions, but i didn't found it or didn't see it, i'm grateful for any help thanks.
these are the errors shown in the Log Cat
E/Trace(1417): error opening trace file: No such file or directory (2)
E/AndroidRuntime(1417): java.lang.RuntimeException: Unable to start activity ComponentInfo{gabrielrojas.com/gabrielrojas.com.primeraventana}: android.view.InflateException: Binary XML file line #7: Error inflating class textview
E/AndroidRuntime(1417): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class textview
The androidmanifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".PruebaNumero3"
android:label="#string/title_activity_prueba_numero3" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".primeraventana"/>
<activity android:name=".segundaventana" />
</application>
</manifest>
PruebaNumero3.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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
tools:context=".PruebaNumero3" />
<Button android:id="#+id/boton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Primera_Ventana"/>
<Button
android:id="#+id/boton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="60dp"
android:text="#string/Segunda_Ventana" />
</RelativeLayout>
PruebaNumero3.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prueba_numero3);
// Visualizamos Los botones
Button boton1 = (Button) findViewById(R.id.boton1);
Button boton2 = (Button) findViewById(R.id.boton2);
// Fijamos los eventos que haran ir a las otras actividades
boton1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(PruebaNumero3.this, primeraventana.class);
startActivity(intent);
}} );
boton2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(PruebaNumero3.this, segundaventana.class);
startActivity(intent);
}} );}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_prueba_numero3, menu);
return true;
} } ;
primeraventana.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:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Escala_Uno"/>
<Button android:id="#+id/boton3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Menú_Principal"/>
</LinearLayout>
primeraventana.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);
TextView text = (TextView) findViewById(R.id.textview1);
Button boton3 = (Button) findViewById(R.id.boton3);
text.setText(R.string.Escala_Uno);
boton3.setText(R.string.Menú_Principal);
boton3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
segundaventana.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:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Escala_Dos"/>
<Button android:id="#+id/boton4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Menú_Principal"/>
</LinearLayout>
segundaventana.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);
TextView text = (TextView) findViewById(R.id.textview2);
Button boton4 = (Button) findViewById(R.id.boton4);
text.setText(R.string.Escala_Dos);
boton4.setText(R.string.Menú_Principal);
boton4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish ();
Check your primeraventana.xml layout file. You opened TextView tag with textview which is not existing. Change it as below
<?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:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Escala_Uno"/>
<Button android:id="#+id/boton3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Menú_Principal"/>
</LinearLayout>
I don't know exactly what the problem is, but I do have a few things you can try:
1)
In primeraventana.xml your TextView should be spelled in capitals. Like so:
<TextView android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Escala_Uno"/>
2)
In segundaventana.java the String names can only be English letters and numbers. Remove the "ú" in:
boton4.setText(R.string.Menú_Principal);
Lastly, I declare OnClickListeners() like this:
button.setOnClickListener(new View.OnClickLister() {
public void onClick(View v) {
// You code here.
}
}
I don't know weather that makes any difference to not having the View. It just looks nicer. :)
Related
i'm developing android App which is full-screen App,
in the main activity there are 2 buttons
The issue is when i click in the About button the pop-out activity appear
after click on dismiss the title bar appear in the main activity, see the screen capture:
The main activity
After clicking About button and clicking on dismiss
about_popout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="60"
android:background="#android:color/transparent"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:background="#drawable/about_shape"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12pt"
android:textColor="#FFFFFF"
android:text="It's a PopupWindow" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/common_ic_googleplayservices" />
<Button
android:id="#+id/btn_dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="Dismiss"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
activity_main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#ff5722"
android:orientation="vertical"
tools:context="com.game.circle.thecirclegame.MainMenu">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/textView" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To the Game"
android:id="#+id/startButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btn_about"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20px"
android:layout_marginLeft="100px"
android:layout_marginRight="100px"
android:text="About"/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game.circle.thecirclegame">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainMenu">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GamePanel"></activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
The class MainMenu.java where the title bar appears, after clicking btn_about
package com.game.circle.thecirclegame;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;
import android.app.ActionBar.LayoutParams;
public class MainMenu extends AppCompatActivity {
Button btn_startGame, btn_about;
final Context context = this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
setContentView(R.layout.activity_main_menu);
addListinerToButtons();
}
public void addListinerToButtons(){
btn_startGame = (Button)findViewById(R.id.startButton);
btn_about = (Button)findViewById(R.id.btn_about);
btn_startGame.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,GamePanel.class);
startActivity(intent);
}
});
btn_about.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater layoutInflater = (LayoutInflater)
getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.about_popout, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
Button btn_dismiss = (Button)popupView.findViewById(R.id.btn_dismiss);
btn_dismiss.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btn_about, 50, -30);
}
});
}
}
i need to get red of the blue title bar.
You can remove the title bar forever by calling:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
before the setContentView(R.layout.x) in your activity class.
To make the app fullscreen, you can do:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Again, put the above code before the setContentView method.
And make sure, if you are doing this, you should extend your Activity class by Activity and not AppCompatActivity or any other class.
Problem solved.
Because i didn't continue using the popup window,
i create a new activity instead and make the button redirect from main menu to About activity
I am not able to set specifc locale on button press. when the button is press of the specific lang. i want the button to redirect to the mainmenu page and then render the basic structure there which consist of five buttons.
Do i need to have the languages installed in the emulator? they are not present in the emulator
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.selectlocale);
Button eng =(Button)findViewById(R.id.en);
eng.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Locale local=new Locale("en");
GlobalClass globalvariable=(GlobalClass)getApplicationContext();
globalvariable.setLocale(local);
Intent ints =new Intent(getApplication(),MainMenu.class);
startActivity(ints);
}
});
Button dar =(Button)findViewById(R.id.dr);
dar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{
Locale local=new Locale("fa");
GlobalClass globalvariable=(GlobalClass)getApplicationContext();
globalvariable.setLocale(local);
Intent ints =new Intent(getApplication(),MainMenu.class);
startActivity(ints);
}
});
Button pas =(Button)findViewById(R.id.ps);
pas.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Locale local=new Locale("ps");
GlobalClass globalvariable=(GlobalClass)getApplicationContext();
globalvariable.setLocale(local);
Intent ints =new Intent(getApplication(),MainMenu.class);
startActivity(ints);
}
});
}
then redirect to Mainmenu activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GlobalClass glb=(GlobalClass)getApplicationContext();
Locale loc =glb.getLocale();
Locale.setDefault(loc);
Configuration config =new Configuration();
config.locale=loc;
getBaseContext().getResources().updateConfiguration(config,getBaseContext().getResources().getDisplayMetrics());
setContentView(R.layout.main_menu);
}
mainmenu.xml page
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.sepia2.myapplication.Main3Activity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Link1"
android:id="#+id/link1"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="100dp"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Link2"
android:id="#+id/link2"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Link3"
android:id="#+id/link3"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Link4"
android:id="#+id/link4"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Link5"
android:id="#+id/link5"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal" />
My values-fa
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Darri HajjApp</string>
<string name="link1">darri link1</string>
<string name="link2">darri link2</string>
<string name="link3">darri link3</string>
<string name="link4">darri link4</string>
<string name="link5">darri link5</string>
</resources>
My values-ps
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">pashto HajjApp</string>
<string name="link1">pashto link1</string>
<string name="link2">pashto link2</string>
<string name="link3">pashto link3</string>
<string name="link4">pashto link4</string>
<string name="link5">pashto link5</string>
</resources>
Global Class
public class GlobalClass extends Application {
private Locale _slocale;
public void setLocale(Locale loc)
{
_slocale=loc;
}
public Locale getLocale()
{
return _slocale;
}
}
This is what I missed in xml file (above is a complete code that works)
just change instead of
android:text="Link1"
it should be from resource
android:text="#string/link1"
And Don't forget to add GlobalClass in AndroidManifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="com.example.sepia2.myapplication.GlobalClass">
<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=".settlocale" />
<activity android:name=".Main3Activity" />
<activity android:name=".MainMenu"></activity>
</application>
The problem is when i get sendBtn from my second activity (called :ClientInterFace) , it always returns null . and even when i want to pass something from my mainActivity(called:loginPage) to the constructor of the second activity , it also returns null!
public class LoginPage extends ActionBarActivity {
Button exitNow;
EditText Username;
TextView conStatus;
EditText Password;
Button LoginBtn;
ProgressBar progressBar;
static String serverAddress = "192.168.1.4";// Set
static int serverPort = 8081;// Set
static String user = "";// received from GUI
static String password = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
exitNow = (Button) findViewById(R.id.exitbtn);
Username = (EditText) findViewById(R.id.username);
conStatus = (TextView) findViewById(R.id.connectionStatus);
Password = (EditText) findViewById(R.id.password);
LoginBtn = (Button) findViewById(R.id.loginBtn);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setEnabled(false);
exitNow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
LoginBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Runnable r = new Runnable() {
#Override
public void run(){
try {
user = Username.getText().toString();
password = Password.getText().toString();
theRest();
} catch (Exception e) {
e.printStackTrace();
}
}
};
Handler h = new Handler();
h.postDelayed(r, 1500);
}
}
});
}
public void theRest() throws Exception {
final ClientNetworkInterface Connection = new ClientNetworkInterface(serverAddress, serverPort, user, password);
if (Connection.isConnected()) {
Toast.makeText(getApplicationContext(), "Congrats ! You Are channeled through the ClientInterface !", Toast.LENGTH_LONG).show();
final ClientInterFace SecondFrame = new ClientInterFace(user);//this passes "user" to the constructor of ClientInterFace and it gets null .
startActivity(new Intent(LoginPage.this, ClientInterFace.class));
conStatus.setText("Connected!");
progressBar.setVisibility(View.INVISIBLE);
SecondFrame.getSendBtn().setOnClickListener(new View.OnClickListener() {// this is where i get null pointer
#Override
public void onClick(View v) { ...}
// here is second activity , ClientInterFace.
public class ClientInterFace extends ActionBarActivity {
public Button sendBtn;
public EditText Commands;
public Button orm;
public ExtractEditText result;
public String message="";
public String User="";
public ClientInterFace(String user) {
this.User=user;
}
public ClientInterFace(){
}
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.client_layout);
setTitle("Welcome " + User + " !");
TextView textView3=(TextView)findViewById(R.id.textView3);
textView3.setText("Welcome to " + User + " Client Page !");
sendBtn = (Button) findViewById(R.id.sendbtn);
orm=(Button) findViewById(R.id.ORM);
result=(ExtractEditText) findViewById(R.id.extractEditText);
Commands=(EditText) findViewById(R.id.editText);
}
public EditText getTextArea() {
return Commands;
}
public Button getSendBtn() {
return sendBtn;
}
public ExtractEditText getTextArea_1() {
return result;
}
//here is my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kooshan.cli" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="kooshan.finalap.cli.LoginPage"
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="kooshan.finalap.cli.ClientInterFace"
android:screenOrientation="portrait" />
</application>
</manifest>
//here is main_layout (login_layout)
<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="kooshan.finalap.cli.LoginPage"
android:id="#+id/rel">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout"
android:weightSum="1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Username :"
android:id="#+id/textView"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/username"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Password :"
android:id="#+id/textView2"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/password"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="exit now ! "
android:id="#+id/exitbtn"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/connectionStatus"
android:layout_weight="0.38"
android:editable="false"
android:gravity="center" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_gravity="center_horizontal"
android:indeterminate="false"
android:visibility="invisible" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log in now !"
android:id="#+id/loginBtn"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/linearLayout"
android:layout_alignEnd="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
//here is client_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="#+id/secpage"
android:orientation="horizontal"
tools:context="kooshan.finalap.cli.ClientInterFace">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frame2">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ORM Page"
android:id="#+id/ORM"
android:layout_gravity="left|top" />
<EditText
android:layout_width="272dp"
android:layout_height="177dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText"
android:layout_gravity="left|center_vertical"
android:text="SQL>"
android:gravity="top" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="93dp"
android:layout_height="159dp"
android:text="Send Command"
android:id="#+id/sendbtn"
android:layout_gravity="right|center_vertical" />
<android.inputmethodservice.ExtractEditText
android:layout_width="302dp"
android:layout_height="181dp"
android:text="The Result"
android:id="#+id/extractEditText"
android:layout_gravity="left|bottom"
android:inputType="textMultiLine"
android:gravity="top" />
<TextView
android:layout_width="155dp"
android:layout_height="137dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textView3"
android:layout_gravity="center_horizontal|top"
android:gravity="bottom|center" />
</FrameLayout>
</LinearLayout>
You might have not quite grasped how Activity works in Android. At the moment you are using them like normal Java classes, when they actually differ quite a lot. They might not exist when you normally would suppose a class would exist, which results in the nulls you see. Read up on Activity life cycles.
The correct way to pass variables between Activity classes is using Intents. There is a method called putExtra(..) that you can use to add data that is received by another Activity. Check out the API.
Edit: for example, I am pretty sure this is not a good way to create an activity and will most likely have no effect when you start the Activity with startActivity():
final ClientInterFace SecondFrame = new ClientInterFace(user)
I have tried editing the code as it would re-install the application on the emulator but again I'm getting the same error again and again.
It's saying edit source lookup path and showing a button for it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/images"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter the text here"
android:textColor="#000000"
android:textSize="30dp" />
<EditText
android:id="#+id/textReader"
android:layout_width="match_parent"
android:layout_height="150dp"
android:inputType="textMultiLine"
/>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/startReading"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Start reading"
android:textSize="15dp" />
<Button
android:id="#+id/clearBox"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Clear Box"
android:textSize="15dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7.58" >
</RelativeLayout>
</LinearLayout>
<EditText
android:id="#+id/textDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
That was the main.xml file above.
package a.fr.read;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class FastreaderActivity extends Activity {
/** Called when the activity is first created. */
Button startReading,clearBox;
EditText textReader;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startReading=(Button)findViewById(R.id.textReader);
clearBox=(Button)findViewById(R.id.textReader);
textReader=(EditText) findViewById(R.id.textReader);
clearBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
textReader.setText("");
}
});
startReading.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
}
And this is the java code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="a.fr.read"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:name=".FastreaderActivity"
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 that was Android manifest file.
First clean your project and refresh that project(In Eclipse- Project-clean)for refresh(go that projectName(ListVeiwdemo) and right click and refresh option will come.)
I am here to seek some help with my code which i am facing a dead end road with. I'm trying to pass values from screen1.java using Intent to screen2.java. Passing the values is fine and I managed to get through it; however, when I check using if statement the program crash down. Here are my files, plzzzzzzzzzzz help
screen1.java
package test.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class screen1 extends Activity
{
static String strKey = "Hello";
static final String strValue = "Hello";
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.screen1);
//** button A
Button A = (Button) findViewById(R.id.btnClickA);
A.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(screen1.this, screen2.class);
strKey = "NAME";
i.setClassName("packageName", "packageName.IntentClass");
String term = "Hello";
i.putExtra("packageName.term", term);
//i.putExtra(strKey, strValue);
startActivity(i);
}
});
//**
//** button B
Button B = (Button) findViewById(R.id.btnClickB);
B.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(screen1.this, screen3.class);
startActivity(i);
}
});
//**
}
}
screen2.java
package test.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class screen2 extends Activity
{
public void onCreate(Bundle icicle)
{
Bundle extras = getIntent().getExtras();
String term = extras.getString("packageName.term");
System.out.println("--- Name is -->"+ term);
if(term.equalsIgnoreCase("Hello") || term.equalsIgnoreCase("Name")){
super.onCreate(icicle);
setContentView(R.layout.screen3);
Button b = (Button) findViewById(R.id.btnClick3);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
setResult(RESULT_OK);
finish();
}
});
} else {
super.onCreate(icicle);
setContentView(R.layout.screen2);
Button b = (Button) findViewById(R.id.btnClick2);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
setResult(RESULT_OK);
finish();
}
});
}
// DOES NOT WORK !!!!!!!!!
System.out.println("--- Name is -->"+ term);
}
}
Layouts:
screen1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You are in the first Screen"
/>
<Button
android:id ="#+id/btnClickA"
android:background="#drawable/sleep0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Screen 2"
/>
<Button
android:id ="#+id/btnClickB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Screen 3"
/>
<ImageView android:id="#+id/icon" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="#drawable/icon"
android:layout_gravity="center"/>
</LinearLayout>
screen2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You are in Screen 2"
/>
<Button
android:id ="#+id/btnClick2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close"
/>
</LinearLayout>
screen3.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- ScrollView: will allow the layout to be scroll Up/Down and Left/right -->
<ScrollView
android:id="#+id/widget54"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You are in Screen 3"
/>
<Button
android:id ="#+id/btnClick3"
android:background="#drawable/sss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close"
/>
<ImageView android:id="#+id/sssq" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="#drawable/sssq"
android:layout_gravity="center" />
</LinearLayout>
</ScrollView>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.android">
<application android:icon="#drawable/icon">
<activity android:name="screen1"
android:label="SCREEN 1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="screen2"
android:label="SCREEN 2">
</activity>
<activity android:name="screen3"
android:label="SCREEN 3">
</activity>
</application>
</manifest>
=====
The error is caused by these lines of code in screen2.java:
if(term.equalsIgnoreCase("Hello") || term.equalsIgnoreCase("Name")){
super.onCreate(icicle);
setContentView(R.layout.screen3);
Button b = (Button) findViewById(R.id.btnClick3);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
setResult(RESULT_OK);
finish();
}
});
}
else {
super.onCreate(icicle);
setContentView(R.layout.screen2);
Button b = (Button) findViewById(R.id.btnClick2);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
setResult(RESULT_OK);
finish();
}
});
}
**notice if I get rid of the entire IF statement and go with only the ELSE the program works fine.
i.setClassName("packageName", "packageName.IntentClass") is not required, if you are passing information to Intent constructor. Btw Is your Screen3 call working fine ?
You're passing the data incorrectly, try this:
public void onClick(View arg0) {
Intent i = new Intent(screen1.this, screen2.class);
strKey = "NAME";
//NO NEED FOR THIS, REMOVE -> i.setClassName("packageName", "packageName.IntentClass");
String term = "Hello";
//Add your string to a bundle:
Bundle b = new Bundle();
b.putString("packageName.term", term);
//Then add the bundle to your intent
i.putExtra(b);
//i.putExtra(strKey, strValue);
startActivity(i);
}
The way you retrieve it in screen2 activity is fine, I would just check if term is null:
if(term != null && (term.equalsIgnoreCase("Hello") || term.equalsIgnoreCase("Name"))){
...