"App has stopped" "Close app" android studio - java

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"
android:background="#77dd77"
tools:context=".MainActivity">
<ImageView
android:id="#+id/splashIcon"
android:layout_width="97dp"
android:layout_height="216dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:contentDescription="#string/todo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/logo1" />
</android.support.constraint.ConstraintLayout>
MAIN_SCREEN.XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Main Screen BVOOM!"
android:textSize="35sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
SCREENONE.JAVA
package com.example.admin.test2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class ScreenOne extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
}
}
MAINACTIVITY.JAVA
package com.example.admin.test2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Timer().schedule(new TimerTask(){
#Override
public void run(){
startActivity(new Intent(getApplicationContext(), ScreenOne.class));
}
}, 2000);
}
}
ANDROID MANIFEST
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.test2">
<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=".ScreenOne">
</activity>
</application>
</manifest>
Error from Logcat/Run tab:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.admin.test2, PID: 16184
java.lang.RuntimeException: Canvas: trying to draw too large(144000000bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:229)
at android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:97)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:529)
at android.widget.ImageView.onDraw(ImageView.java:1367)
at android.view.View.draw(View.java:20370)
at android.view.View.updateDisplayListIfDirty(View.java:19315)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.draw(View.java:20373)
at android.view.View.updateDisplayListIfDirty(View.java:19315)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.draw(View.java:20373)
at com.android.internal.policy.DecorView.draw(DecorView.java:980)
at android.view.View.updateDisplayListIfDirty(View.java:19315)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:686)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:692)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:800)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3501)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3288)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2823)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1785)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7822)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Application terminated.
When I build my file and emulate in my Phone Samsung Galaxy A3 2017 the app will crash and say "Test2 has stopped." "Close app" what can I do with these please help

Bro, In the SCREENONE.JAVA, you have, override the same method twice. Please correct it and your app your run perfectly

Related

Setting up a text view as a clickable button

I am developing a simple application which allows users to login using a username and password, I am trying to set up a "register" link in the form of a TextView which will take the user to the register page of the app. I can't find any error in my coding or logic but when I run the app and click the register link, the app just shuts down.
Here is my MainActivity code -
package com.example.squashsademo;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText mTextUsername;
EditText mTextPassword;
Button mButtonLogin;
TextView mTextViewRegister;
// #RequiresApi(api = Build.VERSION_CODES.M)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextUsername = (EditText)findViewById(R.id.edittext_username);
mTextPassword = (EditText)findViewById(R.id.edittext_password);
mButtonLogin = (Button)findViewById(R.id.button_login);
mTextViewRegister = (TextView)findViewById(R.id.textview_register);
mTextViewRegister.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
Intent registerIntent = new Intent(MainActivity.this,RegisterActivity.class);
startActivity(registerIntent);
}
});
}
}
Here is the RegisterActivity I am trying to get to -
package com.example.squashsademo;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class RegisterActivity extends AppCompatActivity {
EditText mTextUsername;
EditText mTextPassword;
EditText mTextCnfPassword;
Button mButtonRegister;
TextView mTextViewLogin;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mTextUsername = (EditText)findViewById(R.id.edittext_username);
mTextPassword = (EditText)findViewById(R.id.edittext_password);
mTextCnfPassword = (EditText) findViewById(R.id.edittext_cnf_password);
mButtonRegister = (Button)findViewById(R.id.button_login);
mTextViewLogin = (TextView)findViewById(R.id.textview_register);
mTextViewLogin.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent LoginIntent = new Intent(RegisterActivity.this,MainActivity.class);
startActivity(LoginIntent);
}
});
}
}
and here is my AndroidManifest -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.squashsademo">
<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.SquashSADemo">
<activity android:name=".RegisterActivity"></activity>
<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>
Can anyone help see why this is not working because from my understanding it should be :(
Thank you
EDIT - here are the layout files aswell
MainActivity -
<?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:orientation="vertical"
android:gravity="center_horizontal"
android:background="#drawable/background">
<ImageView
android:layout_width="299dp"
android:layout_height="80dp"
app:srcCompat="#drawable/logo" />
<EditText
android:id="#+id/edittext_username"
android:layout_width="356dp"
android:layout_height="57dp"
android:layout_marginTop="160dp"
android:background="#drawable/custom_input"
android:drawableLeft="#drawable/username"
android:drawablePadding="12dp"
android:hint="#string/username"
android:textColorHint="#color/white"/>
<EditText
android:id="#+id/edittext_password"
android:layout_width="356dp"
android:layout_height="57dp"
android:layout_marginTop="20dp"
android:background="#drawable/custom_input"
android:drawableLeft="#drawable/password"
android:drawablePadding="12dp"
android:hint="#string/password"
android:textColorHint="#color/white"/>
<Button
android:id="#+id/button_login"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:text="#string/login"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:textColor="#ffffff"
android:text="#string/not_registered"/>
<TextView
android:id="#+id/textview_register"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="#string/register"/>
</LinearLayout>
</LinearLayout>
RegisterActivity -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".RegisterActivity">
<ImageView
android:layout_width="298dp"
android:layout_height="80dp"
app:srcCompat="#drawable/logo" />
<EditText
android:id="#+id/edittext_username"
android:layout_width="356dp"
android:layout_height="57dp"
android:layout_marginTop="160dp"
android:background="#drawable/custom_input"
android:drawableLeft="#drawable/username"
android:drawablePadding="12dp"
android:hint="#string/username"
android:textColorHint="#color/white"/>
<EditText
android:id="#+id/edittext_password"
android:layout_width="356dp"
android:layout_height="57dp"
android:layout_marginTop="20dp"
android:background="#drawable/custom_input"
android:drawableLeft="#drawable/password"
android:drawablePadding="12dp"
android:hint="#string/password"
android:textColorHint="#color/white" />
<EditText
android:id="#+id/edittext_cnf_password"
android:drawablePadding="12dp"
android:background="#drawable/custom_input"
android:layout_width="356dp"
android:layout_height="57dp"
android:layout_marginTop="20dp"
android:drawableLeft="#drawable/password"
android:hint="#string/confirm_password"
android:textColorHint="#color/white"/>
<Button
android:id="#+id/button_register"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:text="#string/register"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:textColor="#ffffff"
android:text="#string/already_registered"/>
<TextView
android:id="#+id/textview_login"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="16dp"
android:text="#string/login"/>
</LinearLayout>
</LinearLayout>
here are the log files aswell -
2020-10-21 20:56:22.881 11328-11328/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.squashsademo, PID: 11328
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.squashsademo/com.example.squashsademo.RegisterActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3654)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.squashsademo.RegisterActivity.onCreate(RegisterActivity.java:28)
at android.app.Activity.performCreate(Activity.java:7963)
at android.app.Activity.performCreate(Activity.java:7952)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:237) 
at android.app.ActivityThread.main(ActivityThread.java:8167) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 
Below line of code is throwing NullPoinerException
mTextViewLogin = (TextView)findViewById(R.id.textview_register);
in the register activity layout, there is no id as textview_register that's why you are getting the issue
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
possible fix using below line
mTextViewLogin = (TextView)findViewById(R.id.textview_login);
instead of
mTextViewLogin = (TextView)findViewById(R.id.textview_register);
you can see you are trying to link XML view to java with an invalid id

Not switching accounts in same project on button click

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);

on Button click redirect to open PDF from link

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.

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 am trying to show pause button in second activity

My MainActivity java file
package com.example.lenovo.infinity.app;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends Activity {
RelativeLayout btn;
ImageView imageView;
TextView textView;
private AdView adView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adView = (AdView)findViewById(R.id.adsView);
//adView.setAdSize(AdSize.SMART_BANNER);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
//set font to text view
textView = (TextView)findViewById(R.id.start_Text);
Typeface custom = Typeface.createFromAsset(getAssets(),"fonts/font.ttf");
textView.setTypeface(custom);
btn.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, Game.class);
startActivity(myIntent);
}
});
}
}
Game java file
package com.example.lenovo.infinity.app;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
public class Game extends Activity {
View pauseButton;
RelativeLayout Rel_main_game;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
final int heights = dm.heightPixels;
final int widths = dm.widthPixels;
LayoutInflater layoutInflater = (LayoutInflater)getApplicationContext()
.getSystemService(getApplicationContext().LAYOUT_INFLATER_SERVICE);
pauseButton = layoutInflater.inflate(R.layout.activity_pause,null,false);
pauseButton.setX(widths - 250);
pauseButton.setY(0);
Rel_main_game.addView(pauseButton);
pauseButton.getLayoutParams().height = 250;
pauseButton.getLayoutParams().width = 250;
}
}
In my project, I have three layouts: the first, layout is main activity which has start button, the second layout is game panel which contains a pause button and button is the third layout
the XML files are
First XML, this xml have start button
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_activity"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:src="#drawable/game_bg"
android:contentDescription="#string/bg" />
<RelativeLayout
android:layout_width="#dimen/layout_width"
android:layout_height="#dimen/layout_height"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:layout_marginBottom="#dimen/layout_marginBottom"
android:layout_marginLeft="#dimen/layout_marginLeft"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/StartBtn"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="0dp"
android:layout_marginStart="0dp"
android:src="#drawable/btn"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start_game"
android:id="#+id/start_Text"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textSize="#dimen/textSize"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/adsView"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-5303974617236905/1000694879" />
</RelativeLayout>
The second XML, this contains the main game panel with pause button
<?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:id="#+id/rel_main_game"
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.example.lenovo.infinity.app.Game">
</RelativeLayout>
The third layout is a pause button
<?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="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/pause"
tools:context="com.example.lenovo.infinity.app.Pause"
android:background="#000000">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pauseImage"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/pause_margin"
android:scaleType="fitXY"
android:src="#drawable/btn" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="II"
android:id="#+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textSize="#dimen/pause_text_size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
</RelativeLayout>
My Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lenovo.infinity.app">
<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:supportsRtl="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<activity
android:name=".MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<activity
android:name=".Game"
android:screenOrientation="landscape" >
</activity>
</application>
</manifest>
Logcat
04-04 19:47:25.021 8325-8432/? D/GassUtils: Found app info for package com.example.lenovo.infinity.app:1. Hash: e93251d423a7add58a3428a9e259cdd8b57c335ec3a30cc9897279fdeed6e512
04-04 19:47:25.021 8325-8432/? D/k: Found info for package com.example.lenovo.infinity.app in db.
04-04 19:47:25.235 514-703/? V/ActivityManager: com.example.lenovo.infinity.app/.MainActivity: task=TaskRecord{41c684b8 #132 A com.example.lenovo.infinity.app U 0}
04-04 19:47:25.774 8409-8409/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lenovo.infinity.app/com.example.lenovo.infinity.app.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
at android.app.ActivityThread.access$600(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.lenovo.infinity.app.MainActivity.onCreate(MainActivity.java:38)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358) 
at android.app.ActivityThread.access$600(ActivityThread.java:156) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:153) 
at android.app.ActivityThread.main(ActivityThread.java:5297) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
at dalvik.system.NativeStart.main(Native Method) 
04-04 19:47:25.782 514-531/? W/ActivityManager: Force finishing activity com.example.lenovo.infinity.app/.MainActivity
04-04 19:47:25.789 131-131/? I/BufferQueue: [Starting com.example.lenovo.infinity.app](this:0x41f78008,api:2) new GraphicBuffer needed
04-04 19:47:25.803 131-14023/? I/BufferQueue: [Starting com.example.lenovo.infinity.app](this:0x41f78008,api:2) [queue] fps:0.28, dur:3530.34, max:3530.34, min:3530.34
04-04 19:47:25.820 131-204/? I/SurfaceTexture: [Starting com.example.lenovo.infinity.app](this:0x41f91558,api:2) [void* android::SurfaceTexture::createImage(EGLDisplay, const android::sp<android::GraphicBuffer>&)]
04-04 19:47:25.943 8409-8454/? D/dalvikvm: open_cached_dex_file : /data/data/com.example.lenovo.infinity.app/cache/ads1962259775.jar /data/data/com.example.lenovo.infinity.app/cache/ads1962259775.dex
04-04 19:47:26.024 514-535/? V/WindowManager: Changing focus from null to Window{41cae560 u0 Application Error: com.example.lenovo.infinity.app}
04-04 19:47:26.024 514-534/? I/WindowManager: Gaining focus: Window{41cae560 u0 Application Error: com.example.lenovo.infinity.app}
Logcat
You are using the same botton for both start and pause botton:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pauseImage"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/pause_margin"
android:scaleType="fitXY"
android:src="#drawable/btn" />
Change it for:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pauseImage"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/pause_margin"
android:scaleType="fitXY"
android:src="#drawable/btn_pause" />
where btn_pauseis the source of the pause image.
In the second xml you mentioned that you have pause button but the snippet you posted has relative layout only. Use Framelayout if you want to show button on top of the other view.
Also in third xml, you need to change the src to pause image reference. currently you are referring to the same btn image.
Add this in mainActivity
imageView = (ImageView)findViewById(R.id.StartBtn);
btn = (RelativeLayout)findViewById(R.id.Start_layout);

Categories