Saturday 15 June 2019

java - How to add a class to AndroidManifest.xml file in Android Studio?

I switched over from eclipse to android studio and I'm trying to add an activity to my manifest file, I dont know the code I'm supposed to use and my app keeps crashing heres the code from my manifest





package="penis.jason.payday" >

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:name=".MainActivity"

android:label="@string/app_name" >







android:label="Pay Day!!">




android:label="Pay Day!!">











what i have it doing is when the user pushes the settings button than it takes the to that class and new xml. heres the code i used to send the intent



Settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent GoToSettings = new Intent(getApplicationContext(), settings.class);

startActivity(GoToSettings);
finish();
}
});


heres my logcat




08-24 10:41:52.098  21750-21750/penis.jason.payday E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: penis.jason.payday, PID: 21750
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{penis.jason.payday/penis.jason.payday.settings}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)

at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:1986)
at penis.jason.payday.settings.(settings.java:23)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)

at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2250)


this is the whole settings class



package penis.jason.payday;

import android.app.Activity;
import android.content.Context;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;

import java.util.Calendar;



@SuppressWarnings("unused")
public class settings extends Activity {

boolean FullScreen;


Button SaveAndExit = (Button) findViewById(R.id.SaveAndExit);
Button Save = (Button) findViewById(R.id.Save);

Button Cls = (Button) findViewById(R.id.Cls);
CheckBox FullScreenOnOff = (CheckBox) findViewById(R.id.fullScreen);
CheckBox SaveWarningOnOff = (CheckBox) findViewById(R.id.SaveWarningOnOff);


Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month= cal.get(Calendar.MONTH)+1;
int day = cal.get(Calendar.DATE);


String FullDate = (" "+month+"/"+day+"/"+year);
String Date=(String.valueOf(FullDate));

@Override
protected void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.settings);



FullScreen = getSharedPreferences("Settings",MODE_PRIVATE).getBoolean("FullScreen",false);
if(FullScreen==true){
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.settings);
}


SaveAndExit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent GoToMain = new Intent(getApplicationContext(), MainActivity.class);

startActivity(GoToMain);
finish();

}
});


Save.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

}
});


Cls.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


}
});


if(FullScreenOnOff.isChecked()){
FullScreen = true;
SharedPreferences FullScreenSave = getSharedPreferences("Settings", Context.MODE_PRIVATE);
SharedPreferences.Editor FullScreenE = FullScreenSave.edit();
FullScreenE.putBoolean("FullScreen", FullScreen);

FullScreenE.commit();
}




}
}



_______UPDATE______
i found the problem!



i had to change the way i declared my button varables to this



 boolean FullScreen;
Button SaveAndExit,Save,Cls;
CheckBox FullScreenOnOff,SaveWarningOnOff;





Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month= cal.get(Calendar.MONTH)+1;
int day = cal.get(Calendar.DATE);

String FullDate = (" "+month+"/"+day+"/"+year);
String Date=(String.valueOf(FullDate));


@Override
protected void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.settings);


FullScreen = getSharedPreferences("Settings",MODE_PRIVATE).getBoolean("FullScreen",false);
if(FullScreen==true){
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.settings);
}

SaveAndExit = (Button) findViewById(R.id.SaveAndExit);
Save = (Button) findViewById(R.id.Save);
Cls = (Button) findViewById(R.id.Cls);
FullScreenOnOff = (CheckBox) findViewById(R.id.fullScreen);
SaveWarningOnOff = (CheckBox) findViewById(R.id.SaveWarningOnOff);



}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...