This is an app about layout
first the screen will be in portrait layout on clciking button it will be changed to landscape layout.so here on clicking button it is not going to next activity though no compilation errors are found
activity_main.xml
?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.vamshivikas.orientation.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:text="#string/this_is_potrait_layout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.48"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.15" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="47dp"
android:layout_marginStart="8dp"
android:layout_marginTop="80dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="#string/go_to_next_activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
</android.support.constraint.ConstraintLayout>
activity_second.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="#string/this_is_landscape_layout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
activityManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vamshivikas.orientation">
<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="com.example.vamshivikas.orientation.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".SecondActivity"
android:screenOrientation="landscape">
</activity>
</application>
</manifest>
mainActivity.java
package com.example.vamshivikas.orientation;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button button1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1=(Button)findViewById(R.id.button1);
}
public void onClcik(View v){
Intent intent=new Intent(MainActivity.this,SecondActivity.class);
startActivity(intent);
}
secondActivity.java
package com.example.vamshivikas.orientation;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SecondActivity extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}
As I see you have no onClick-Attribute in your Button-Element in activity_main.xml.
Give your Button an onClick-Attribute like this
<Button
android:onClick="onButtonNextActivityClick"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="47dp"
android:layout_marginStart="8dp"
android:layout_marginTop="80dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="#string/go_to_next_activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
and then create a public void method in MainActivity.java with the same name and handle your stuff in there. Like this:
public void onButtonNextActivityClick(View v){
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
startActivity(intent);
}
And Consider using MrFishermans solution too
If I understand you in a good way, you want to go the another Activity when you click on Button? You also want to switch View to Landscape?
You can do: (in onClick() function)
Intent intent = new Intent(this, AnotherActivity.class);
startActivity(intent);
And then in your second activity, in onCreate() function call:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Related
i'm new at android studio and i'm developing my first app.
Everything worked fine until i implemented a splashscreen. Indeed, when i run the app, the splashcreen works, but then, it crashes.
The thing is that the splashscreen wasn't the first activity i've created (the main). I've created my app and when i finished it, i added a splashscreen.
Actually when i disable the splashscreen (the activity) and start directly with the previous "activity that appears on launch" (that is the "Menu"), it works fine.
And one weird thing: with the splashscreen enabled, it crashes only with certain devices. It runs perfectly with my Xiaomi Redmi Note 5 and a Galaxy S4 (or the nexus 5X emulator) but not with a Galaxy S3 and S6 .
I tried to replace the timer by a simple setonclicklistener button. But same, when it has to load the Menu, it crashes.
I haven't find similar problems on the forums so here i am !
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="#style/AppTheme">
<activity android:name=".Menu"/>
<activity android:name=".restaurant" />
<activity android:name=".courses" />
<activity android:name=".toilettes" />
<activity android:name=".distributeur" />
<activity android:name=".essence" />
<activity android:name=".hopital" />
<activity android:name=".Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />
</application>
Here is the Splashscreen -java
package fr.libertyg.messervices;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Handler;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Timer;
public class Splashscreen extends AppCompatActivity {
private ImageView daccord;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_splashscreen);
final TextView random = (TextView) findViewById(R.id.random);
final String[] mesphrases = {"S1", "S2",
"S3", "S4", "S5","S6"};
int rando = (int) (Math.random() * 6);
random.setText(mesphrases[rando]);
this.daccord = findViewById(R.id.daccord);
daccord.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otheractivity = new Intent(Splashscreen.this, Menu.class);
startActivity(otheractivity);
finish();
}
});
}
The Splashscreen xml:
<?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"
tools:context=".Splashscreen"
android:weightSum="10"
android:orientation="vertical"
android:background="#drawable/splashscreenfond">
<RelativeLayout
android:layout_weight="1.5"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:id="#+id/spashscreenbienvenue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/splashscreenbienvenue"
android:textSize="40sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5">
<ImageView
android:id="#+id/logo"
android:layout_width="249dp"
android:layout_height="217dp"
android:layout_centerInParent="true"
android:src="#drawable/icon" />
<TextView
android:id="#+id/nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/app_name"
android:textSize="30sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5">
<TextView
android:id="#+id/bonasavoir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="#string/bonasavoir"
android:textSize="17sp" />
<TextView
android:id="#+id/donnees"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/random"
android:layout_centerHorizontal="true"
android:text="#string/activezgps"
android:textSize="14sp" />
<TextView
android:id="#+id/random"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="13dp"
android:text="Un être humain a besoin d'environ 2000 kcal/jour"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<TextView
android:id="#+id/version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/version" />
<ImageView
android:id="#+id/daccord"
android:layout_width="124dp"
android:layout_height="105dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/daccord" />
</RelativeLayout>
</LinearLayout>
And the Menu -java
package fr.libertyg.messervices;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class Menu extends AppCompatActivity {
private ImageView distributeur;
private ImageView restaurant;
private ImageView courses;
private ImageView toilettes;
private ImageView essence;
private ImageView hopital;
AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_menu);
this.distributeur = findViewById(R.id.distributeur);
distributeur.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), distributeur.class);
startActivity(otherActivity);
}
});
this.restaurant = findViewById(R.id.restaurant);
restaurant.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), restaurant.class);
startActivity(otherActivity);
}
});
this.courses = findViewById(R.id.courses);
courses.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), courses.class);
startActivity(otherActivity);
}
});
this.toilettes = findViewById(R.id.toilettes);
toilettes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), toilettes.class);
startActivity(otherActivity);
}
});
this.essence = findViewById(R.id.essence);
essence.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), essence.class);
startActivity(otherActivity);
}
});
this.hopital = findViewById(R.id.hopital);
hopital.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), hopital.class);
startActivity(otherActivity);
}
});
MobileAds.initialize(this, "ca-app-pub-6520930039267956~4038950000");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
}
And the Menu xml
<?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"
tools:context=".MainActivity"
android:background="#drawable/fond"
android:orientation="vertical"
android:weightSum="10">
<RelativeLayout
android:layout_weight="1.5"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:id="#+id/bienvenue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/quoi"
android:textColor="#color/blanc"
android:textSize="30sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7.6">
<ImageView
android:id="#+id/distributeur"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_horizontal"
android:layout_marginStart="37dp"
android:layout_marginTop="29dp"
android:src="#drawable/distributeur" />
<ImageView
android:id="#+id/restaurant"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="37dp"
android:layout_marginTop="29dp"
android:src="#drawable/restaurant" />
<ImageView
android:id="#+id/courses"
top="#+id/distributeur"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignStart="#+id/distributeur"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal"
android:src="#drawable/courses" />
<ImageView
android:id="#+id/toilettes"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignStart="#+id/restaurant"
android:layout_alignTop="#+id/courses"
android:layout_gravity="center_horizontal"
android:src="#drawable/toilettes" />
<ImageView
android:id="#+id/essence"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/distributeur"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="28dp"
android:src="#drawable/essence" />
<ImageView
android:id="#+id/hopital"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignStart="#+id/restaurant"
android:layout_alignTop="#+id/essence"
android:layout_gravity="center_horizontal"
android:src="#drawable/hopital" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-6520930039267956/3068657000" />
</RelativeLayout>
Thanks by advance for helping me.
In your app gradle make sure that libs use the same version, like:
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:gridlayout-v7:28.0.0-alpha1'
You probably don't need all of them.
Make the changes and then click "Sync Now"
Solved it:
I had to add this to the manifest:
android:largeHeap="true"
And it worked fine.
I want to create a java page with a Button and a TextBox
So that when the user writes the number 1 in the TextBox and then presses the Button
It will redirect him to open a pdf file from
ex:
www.mywebsite / myfile1.pdf
When the user writes the number 2 in the TextBox and then presses the Button
It will redirect him to open pdf file from
www.mywebsite / myfile2.pdf
Thank you
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<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/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>
Activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter file number"
android:inputType="number"
app:layout_constraintBottom_toTopOf="#+id/Open"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
<Button
android:id="#+id/Open"
android:layout_width="138dp"
android:layout_height="wrap_content"
android:layout_marginBottom="276dp"
android:text="Open"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
Main_activity.java
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button Open;
EditText Filenumber;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Open=(Button)findViewById(R.id.Open);
Filenumber=(EditText)findViewById(R.id.editText);
Open.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
public void open(){
if(Filenumber.equals("1234"))
Uri.parse("http://www.xmlpdf.com/manualfiles/hello-world.pdf");
if(Filenumber.equals("12345"))
Uri.parse("http://www.google.com");
{
}
}
}
If your pdf source is a link, you can either download the pdf first or open it using WebView. Here is some link that might be of help.
Can anyone tell me what I am missing, this is driving me crazy.
Below is the java code for the Profile Activity. I've only been at this for about 30 days now and a lot is still confusing to me.
When I run the emulator, it opens, then crashes after the first button
that is supposed to send the user to the second activity.
Running Logcat, it gets hung up on line 26 of the page posted below, stating it hates something about my Listener for Button 2.
Help???
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class ProfileActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
// Button Click Goes to Main Activity
Button button1 = (Button) findViewById(R.id.start_over);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
back();
}
});
// Button Click Goes To Third Activity
Button button2 = (Button) findViewById(R.id.forward);
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
forward();
}
});
}
private void back() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
private void forward() {
Intent intent = new Intent(this, ThirdActivity.class);
startActivity(intent);
}
}
Logcat File is below:
FATAL EXCEPTION: main
Process: com.defy, PID: 2481
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.defy/com.defy.ProfileActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.defy.ProfileActivity.onCreate(ProfileActivity.java:26)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
MainActivity .XML Below:
<?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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.defy.trailmaster.MainActivity">
<ImageView
android:id="#+id/background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop"
android:src="#drawable/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="#+id/start_hiking"
android:layout_width="95dp"
android:layout_height="35dp"
android:background="#000000"
android:text="#string/app_start"
android:textColor="#FDFEFE"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.868"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.966"
tools:layout_editor_absoluteX="242dp" />
<ImageView
android:id="#+id/tent"
android:layout_width="121dp"
android:layout_height="96dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26"
app:srcCompat="#drawable/tent" />
<ImageView
android:id="#+id/hiker_right"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="37dp"
android:layout_marginTop="8dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.991"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.889"
app:srcCompat="#drawable/hiker_right"
tools:ignore="MissingConstraints,RtlHardcoded" />
</android.support.constraint.ConstraintLayout>
Main Activity .JAVA Below:
package com.defy.trailmaster;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Button Click Goes To Profile Activity
Button button = (Button) findViewById(R.id.start_hiking);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
hike();
}
});
}
private void hike() {
Intent intent = new Intent(this, ProfileActivity.class);
startActivity(intent);
}
}
Last is the Manifest file Below:
<?xml version="1.0" encoding="utf-8"?>
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ProfileActivity" />
<activity android:name=".ThirdActivity"></activity>
</application>
Profile Activity XML Below:
<?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:id="#+id/activity_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.defy.trailmaster.ProfileActivity">
<ImageView
android:id="#+id/background"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop"
android:src="#drawable/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="#+id/start_over"
android:layout_width="95dp"
android:layout_height="35dp"
android:background="#000000"
android:text="#string/app_back"
android:textColor="#FDFEFE"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.145"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.966" />
<Button
android:id="#+id/hike_now"
android:layout_width="95dp"
android:layout_height="35dp"
android:background="#000000"
android:text="#string/app_hike"
android:textColor="#FDFEFE"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.868"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.966" />
<ImageView
android:id="#+id/tent"
android:layout_width="121dp"
android:layout_height="96dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26"
app:srcCompat="#drawable/tent" />
<ImageView
android:id="#+id/left_hiker"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginBottom="0dp"
android:layout_marginStart="42dp"
android:layout_marginLeft="42dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toTopOf="#+id/start_over"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/hiker_right"
app:srcCompat="#drawable/hiker_left" />
<ImageView
android:id="#+id/hiker_right"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="37dp"
android:layout_marginTop="8dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.991"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.889"
app:srcCompat="#drawable/hiker_right"
tools:ignore="MissingConstraints,RtlHardcoded" />
</android.support.constraint.ConstraintLayout>
It is crashing most likely due to R.id.forward, button2 is null.
It looks like you either named the button id something else, or missed it.
Post the XML for ProfileActivity
Here's your problem. button2 should refer to hike_now
Final Button button2 = (Button) findViewById(R.id.hike_now);
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 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.)