raza mehdi's Profile

About

 
Points: 0

Contact

 

raza mehdi
June 18, 2014 · Public

xml file













raza mehdi
June 18, 2014 · Public

im taking your android tutorials and i stuck when compiling my first activity.

unfortunately app has stopped android eclipse

my fragment xml file














main java file

package com.example.counter;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class MainActivityCounter extends Activity {

int counter;
Button add;
Button sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity_counter);

counter =0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);

add.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
counter++;
display.setText("your total is " + counter);
}
});

sub.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
counter--;
display.setText("your total is " + counter);
}
});



if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity_counter, menu);
return true;
}

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

/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(
R.layout.fragment_main_activity_counter, container, false);
return rootView;
}
}

}


log file

06-18 18:19:37.985: D/dalvikvm(535): Not late-enabling CheckJNI (already on)
06-18 18:19:39.725: D/AndroidRuntime(535): Shutting down VM
06-18 18:19:39.725: W/dalvikvm(535): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
06-18 18:19:39.745: E/AndroidRuntime(535): FATAL EXCEPTION: main
06-18 18:19:39.745: E/AndroidRuntime(535): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.counter/com.example.counter.MainActivityCounter}: java.lang.NullPointerException
06-18 18:19:39.745: E/AndroidRuntime(535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
06-18 18:19:39.745: E/AndroidRuntime(535): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-18 18:19:39.745: E/AndroidRuntime(535): at android.app.ActivityThread.access$600(ActivityThread.java:122)
06-18 18:19:39.745: E/AndroidRuntime(535): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
06-18 18:19:39.745: E/AndroidRuntime(535): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 18:19:39.745: E/AndroidRuntime(535): at android.os.Looper.loop(Looper.java:137)
06-18 18:19:39.745: E/AndroidRuntime(535): at android.app.ActivityThread.main(ActivityThread.java:4340)
06-18 18:19:39.745: E/AndroidRuntime(535): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 18:19:39.745: E/AndroidRuntime(535): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 18:19:39.745: E/AndroidRuntime(535): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-18 18:19:39.745: E/AndroidRuntime(535): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-18 18:19:39.745: E/AndroidRuntime(535): at dalvik.system.NativeStart.main(Native Method)
06-18 18:19:39.745: E/AndroidRuntime(535): Caused by: java.lang.NullPointerException
06-18 18:19:39.745: E/AndroidRuntime(535): at com.example.counter.MainActivityCounter.onCreate(MainActivityCounter.java:30)
06-18 18:19:39.745: E/AndroidRuntime(535): at android.app.Activity.performCreate(Activity.java:4465)
06-18 18:19:39.745: E/AndroidRuntime(535): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-18 18:19:39.745: E/AndroidRuntime(535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
06-18 18:19:39.745: E/AndroidRuntime(535): ... 11 more
06-18 18:27:16.925: D/AndroidRuntime(591): Shutting down VM
06-18 18:27:16.925: W/dalvikvm(591): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
06-18 18:27:16.945: E/AndroidRuntime(591): FATAL EXCEPTION: main
06-18 18:27:16.945: E/AndroidRuntime(591): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.counter/com.example.counter.MainActivityCounter}: java.lang.NullPointerException
06-18 18:27:16.945: E/AndroidRuntime(591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
06-18 18:27:16.945: E/AndroidRuntime(591): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-18 18:27:16.945: E/AndroidRuntime(591): at android.app.ActivityThread.access$600(ActivityThread.java:122)
06-18 18:27:16.945: E/AndroidRuntime(591): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
06-18 18:27:16.945: E/AndroidRuntime(591): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 18:27:16.945: E/AndroidRuntime(591): at android.os.Looper.loop(Looper.java:137)
06-18 18:27:16.945: E/AndroidRuntime(591): at android.app.ActivityThread.main(ActivityThread.java:4340)
06-18 18:27:16.945: E/AndroidRuntime(591): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 18:27:16.945: E/AndroidRuntime(591): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 18:27:16.945: E/AndroidRuntime(591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-18 18:27:16.945: E/AndroidRuntime(591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-18 18:27:16.945: E/AndroidRuntime(591): at dalvik.system.NativeStart.main(Native Method)
06-18 18:27:16.945: E/AndroidRuntime(591): Caused by: java.lang.NullPointerException
06-18 18:27:16.945: E/AndroidRuntime(591): at com.example.counter.MainActivityCounter.onCreate(MainActivityCounter.java:30)
06-18 18:27:16.945: E/AndroidRuntime(591): at android.app.Activity.performCreate(Activity.java:4465)
06-18 18:27:16.945: E/AndroidRuntime(591): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-18 18:27:16.945: E/AndroidRuntime(591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
06-18 18:27:16.945: E/AndroidRuntime(591): ... 11 more
06-18 18:48:10.045: D/AndroidRuntime(640): Shutting down VM
06-18 18:48:10.045: W/dalvikvm(640): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
06-18 18:48:10.065: E/AndroidRuntime(640): FATAL EXCEPTION: main
06-18 18:48:10.065: E/AndroidRuntime(640): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.counter/com.example.counter.MainActivityCounter}: java.lang.NullPointerException
06-18 18:48:10.065: E/AndroidRuntime(640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
06-18 18:48:10.065: E/AndroidRuntime(640): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-18 18:48:10.065: E/AndroidRuntime(640): at android.app.ActivityThread.access$600(ActivityThread.java:122)
06-18 18:48:10.065: E/AndroidRuntime(640): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
06-18 18:48:10.065: E/AndroidRuntime(640): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 18:48:10.065: E/AndroidRuntime(640): at android.os.Looper.loop(Looper.java:137)
06-18 18:48:10.065: E/AndroidRuntime(640): at android.app.ActivityThread.main(ActivityThread.java:4340)
06-18 18:48:10.065: E/AndroidRuntime(640): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 18:48:10.065: E/AndroidRuntime(640): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 18:48:10.065: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-18 18:48:10.065: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-18 18:48:10.065: E/AndroidRuntime(640): at dalvik.system.NativeStart.main(Native Method)
06-18 18:48:10.065: E/AndroidRuntime(640): Caused by: java.lang.NullPointerException
06-18 18:48:10.065: E/AndroidRuntime(640): at com.example.counter.MainActivityCounter.onCreate(MainActivityCounter.java:30)
06-18 18:48:10.065: E/AndroidRuntime(640): at android.app.Activity.performCreate(Activity.java:4465)
06-18 18:48:10.065: E/AndroidRuntime(640): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-18 18:48:10.065: E/AndroidRuntime(640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
06-18 18:48:10.065: E/AndroidRuntime(640): ... 11 more
06-18 18:48:12.975: I/Process(640): Sending signal. PID: 640 SIG: 9