i'm trying to go to my next activity , which is Nieuw_huis1 This is my code of the mainactivity where SetupNieuwHuis should redirect to the next page
package com.jan.energyservice;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import android.support.v7.app.ActionBarActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private EditText test;
private String data;
private String file = "mydata";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
test = (EditText) (findViewById(R.id.txtTest));
setupNieuwHuis();
slaietsop();
tooniets();
}
private void tooniets() {
// 1 Reference
Button Movebutton = (Button) findViewById(R.id.btnLees);
// 2 click listener to run code
Movebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
read(test);
}});}
private void slaietsop() {
// 1 Reference
Button Movebutton = (Button) findViewById(R.id.btnTest);
// 2 click listener to run code
Movebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
save(test);
}
});
}
public void save(View view){
data = test.getText().toString();
try {
FileOutputStream fOut = openFileOutput(file,Context.MODE_PRIVATE);
new PrintStream(fOut).println("Naam van eerste ding");
fOut.write(data.getBytes());
fOut.close();
Toast.makeText(getBaseContext(),"file saved",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void read(View view){
try{
FileInputStream fin = openFileInput(file);
int c;
String temp="";
while( (c = fin.read()) != -1){
temp = temp + Character.toString((char)c);
}
test.setText(temp);
Toast.makeText(getBaseContext(),"file read",
Toast.LENGTH_SHORT).show();
}catch(Exception e){
}
}
private void setupNieuwHuis() {
// 1 Reference
Button Movebutton = (Button) findViewById(R.id.btnNieuwHuis);
// 2 click listener to run code
Movebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =(new Intent(MainActivity.this,Nieuw_huis1.class));
startActivity(intent);
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
But for some reason , when i start up my app, and i click on the button btnNieuwHuis , it crashes and gives me this error log
05-24 10:51:16.466: E/Trace(825): error opening trace file: No such file or directory (2) 05-24 10:51:18.707: D/gralloc_goldfish(825): Emulator without GPU emulation detected. 05-24 10:51:29.166: D/AndroidRuntime(825): Shutting down VM 05-24 10:51:29.166: W/dalvikvm(825): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 05-24 10:51:29.196: E/AndroidRuntime(825): FATAL EXCEPTION: main 05-24 10:51:29.196: E/AndroidRuntime(825): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.jan.energyservice/com.jan.energyservice.Nieuw_huis1}; have you declared this activity in your AndroidManifest.xml? 05-24 10:51:29.196: E/AndroidRuntime(825): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.app.Activity.startActivityForResult(Activity.java:3370) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.app.Activity.startActivityForResult(Activity.java:3331) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:840) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.app.Activity.startActivity(Activity.java:3566) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.app.Activity.startActivity(Activity.java:3534) 05-24 10:51:29.196: E/AndroidRuntime(825): at com.jan.energyservice.MainActivity$3.onClick(MainActivity.java:98) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.view.View.performClick(View.java:4204) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.view.View$PerformClick.run(View.java:17355) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.os.Handler.handleCallback(Handler.java:725) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.os.Handler.dispatchMessage(Handler.java:92) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.os.Looper.loop(Looper.java:137) 05-24 10:51:29.196: E/AndroidRuntime(825): at android.app.ActivityThread.main(ActivityThread.java:5041) 05-24 10:51:29.196: E/AndroidRuntime(825): at java.lang.reflect.Method.invokeNative(Native Method) 05-24 10:51:29.196: E/AndroidRuntime(825): at java.lang.reflect.Method.invoke(Method.java:511) 05-24 10:51:29.196: E/AndroidRuntime(825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 05-24 10:51:29.196: E/AndroidRuntime(825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 05-24 10:51:29.196: E/AndroidRuntime(825): at dalvik.system.NativeStart.main(Native Method)
Aucun commentaire:
Enregistrer un commentaire