Connection being refused while sending data from Android app to server [duplicate] - java

This question already has answers here:
How can I fix 'android.os.NetworkOnMainThreadException'?
(66 answers)
Closed 8 years ago.
I'm new to android application development and i want to send three parameters Latitude ,
Longitude and Bimari(which i am mentioning in
my code below) to phpMyAdmin server via internet.
The problem is that after selecting bimari from
spinner when i click send button my app crashes.
My server side is working correctly.Can anyone
please tell me why i can't send my data to server ?
Thanks alot for reading !
MainActivity.java is as follows:-
public final static String EXTRA_MESSAGE = "com.example.sushma.myfirstapp.MESSAGE";
String nn, nn1, nn2, nn3, nn4, nn5, nnf; // used to make URL
String sss1, sss2; // used to convert lat and long to string
String s; // used to save bimari as string
double lat, lng;
LocationManager lm;
String provider;
Location l;
private View view;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
Criteria c = new Criteria();
provider = lm.getBestProvider(c, false);
l = lm.getLastKnownLocation(provider);
if (l != null) {
//get latitude and longitude of the location
lng = l.getLongitude();
lat = l.getLatitude();
} else {
System.out.println("No lat/long");
}
{
LinearLayout l1 = new LinearLayout(this);
l1.setBackgroundResource(R.drawable.ambulance);
setContentView(R.layout.activity_main);
}
}
public void ongobuttonclick(View view) {
this.view = view;
Spinner sp = (Spinner) findViewById(R.id.problems);
s = sp.getSelectedItem().toString();
sss1 = String.valueOf(lng);
sss2 = String.valueOf(lat);
nn = "http://192.168.2.8/tech/new_predict.php?Latitude=";
nn1 = sss2;
nn2 = "&Longitude=";
nn3 = sss1;
nn4 = "&Bimari=";
nn5 = s;
nnf = nn + nn1 + nn2 + nn3 + nn4 + nn5;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httPost = new HttpPost(nnf);
System.out.println(nnf);
new Thread(new Runnable() {
#Override
public void run() {
try {
httpclient.execute(httPost);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Logcat
01-26 19:32:22.859 14247-14247/com.example.sushma.myfirstapp E/ViewRootImpl﹕ sendUserActionEvent() mView == null
01-26 19:32:29.085 14247-14247/com.example.sushma.myfirstapp D/AndroidRuntime﹕ Shutting down VM
01-26 19:32:29.085 14247-14247/com.example.sushma.myfirstapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40da9930)
01-26 19:32:29.105 14247-14247/com.example.sushma.myfirstapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3804)
at android.view.View.performClick(View.java:4439)
at android.widget.Button.performClick(Button.java:139)
at android.view.View$PerformClick.run(View.java:18395)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3799)
at android.view.View.performClick(View.java:4439)
at android.widget.Button.performClick(Button.java:139)
at android.view.View$PerformClick.run(View.java:18395)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1128)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
at java.net.Socket.connect(Socket.java:842)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.example.sushma.myfirstapp.MainActivity.ongobuttonclick(MainActivity.java:176)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3799)
at android.view.View.performClick(View.java:4439)
at android.widget.Button.performClick(Button.java:139)
at android.view.View$PerformClick.run(View.java:18395)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
NewLogcat
01-26 22:45:48.807 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
01-26 22:45:48.807 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 11750: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 11756: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 9401: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 534: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 556: Landroid/content/res/TypedArray;.getType (I)I
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-26 22:45:48.947 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ GC_FOR_ALLOC freed 157K, 13% free 8676K/9872K, paused 24ms, total 24ms
01-26 22:45:48.957 23318-23318/com.example.sushma.myfirstapp I/dalvikvm-heap﹕ Grow heap (frag case) to 10.654MB for 1228816-byte allocation
01-26 22:45:48.967 23318-23329/com.example.sushma.myfirstapp D/dalvikvm﹕ GC_FOR_ALLOC freed 1K, 11% free 9875K/11076K, paused 14ms, total 14ms
01-26 22:45:49.007 23318-23323/com.example.sushma.myfirstapp E/dalvikvm﹕ adjustAdaptiveCoef max=4194304, min=1048576, ut=568
01-26 22:45:49.007 23318-23323/com.example.sushma.myfirstapp D/dalvikvm﹕ GC_CONCURRENT freed 4K, 11% free 9871K/11076K, paused 16ms+3ms, total 40ms
01-26 22:45:49.257 23318-23318/com.example.sushma.myfirstapp D/libEGL﹕ loaded /system/lib/egl/libGLES_hawaii.so
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ mem_init ++
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ gHwMemAllocator client 3
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ **** Using ION allocator ****
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ registered SIGUSR1[10] for pid[23318]
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ HwMemAllocatorImpl Static Counters 0 0
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ HwMemAllocatorImpl[490a9dcc] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0]
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/﹕ mem_init 490a9dcc--
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/ION﹕ config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608)
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/MM_DEVICE﹕ Waiting for mm thread to come up
01-26 22:45:49.277 23318-23346/com.example.sushma.myfirstapp D/MM_DEVICE﹕ mm_device_thread starting
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglCreateContext() config: 18 context: 0x4f3c4db8, VC context 1, Thread 23318
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ Set SWAP INTERVAL 0
01-26 22:45:49.287 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglCreateWindowSurface() surface: 0x4beeea48, VC surface: 1, Thread: 23318
01-26 22:45:49.287 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:49.287 23318-23318/com.example.sushma.myfirstapp D/OpenGLRenderer﹕ Enabling debug mode 0
01-26 22:45:50.849 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ Get MotionRecognitionManager
01-26 22:45:50.959 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ Set SWAP INTERVAL 0
01-26 22:45:50.969 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglCreateWindowSurface() surface: 0x4c0f1be8, VC surface: 2, Thread: 23318
01-26 22:45:50.969 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4c0f1be8, 0x4c0f1be8) Thread: 23318
01-26 22:45:50.989 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4c0f1be8, 0x4c0f1be8) Thread: 23318
01-26 22:45:51.079 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:51.089 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:52.150 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4c0f1be8, 0x4c0f1be8) Thread: 23318
01-26 22:45:52.791 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ onDetachedFromWindow
01-26 22:45:52.791 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(NULL) Thread: 23318
01-26 22:45:52.791 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglDestroySurface() surface: 0x4c0f1be8, android window 0x4c05c8f8, Thread: 23318
01-26 22:45:52.811 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:52.871 23318-23318/com.example.sushma.myfirstapp E/ViewRootImpl﹕ sendUserActionEvent() mView == null
01-26 22:45:53.802 23318-23318/com.example.sushma.myfirstapp I/System.out﹕ http://192.168.2.8/tech/new_predict.php?Latitude=31.310573780338718&Longitude=75.55498407042245&Bimari=Bones
01-26 22:45:56.945 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.2.8 refused
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at com.example.sushma.myfirstapp.MainActivity$1.run(MainActivity.java:173)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.lang.Thread.run(Thread.java:856)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ Caused by: java.net.ConnectException: failed to connect to /192.168.2.8 (port 80): connect failed: EHOSTUNREACH (No route to host)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:114)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.net.Socket.connect(Socket.java:842)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ ... 8 more
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ Caused by: libcore.io.ErrnoException: connect failed: EHOSTUNREACH (No route to host)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.Posix.connect(Native Method)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:112)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ ... 13 more

You tried execute httpclient.execute(httPost); method in UI thread. You can not do this.
You can use AsyncTask to resolve this issue.
public void ongobuttonclick(View view) {
...
//your code
//use AsyncTask if you want ot inform ui thread
final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httPost = new HttpPost(nnf);
new AsyncTask<HttpPost, Void, HttpResponse>() {
//YourParams, YourProgress, YourResult can be Void
#Override
protected HttpResponse doInBackground(HttpPost... params) {
HttpResponse response = null;
try {
response = httpclient.execute(params[0]);
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
#Override
protected void onPostExecute(HttpResponse response) {
if(response != null){
//do sth in UI thread
}
}
}.execute(httPost);
//or in new thread if you doesn't want ot inform ui thread
new Thread(new Runnable() {
#Override
public void run() {
try {
httpclient.execute(httPost);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}

Related

My app unfortunately stopped may be due to mistakes

My app consists of level, each level has 10 question. This is my first level and first question class..
public class level1 extends ActionBarActivity {
private EditText mans1;
private TextView mcount;
int sum;
public void Onclick(View v) {
mans1 = (EditText) findViewById(R.id.ans1);
mcount = (TextView) findViewById(R.id.count);
double answer = Double.parseDouble(mans1.getText().toString());
if (answer == (8 + 7))
{
Toast.makeText(level1.this, "الإجابة صحيحة", Toast.LENGTH_LONG).show();
mcount.setText(sum++);
}
else
{
Toast.makeText(level1.this, "الإجابة خاطئة", Toast.LENGTH_LONG).show();
mcount.setText(sum);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level1);
final TextView texview = (TextView)findViewById(R.id.count);
Button sendButton = (Button)findViewById(R.id.tm);
sendButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int count = Integer.parseInt(texview.getText().toString());
Intent intent = new Intent(getApplicationContext(), level1.class);
intent.putExtra("mycount", sum);
startActivity(intent);
}
});
}
public void buttonOnClickgo(View v) {
Button next = (Button) v;
startActivity(new Intent(getApplicationContext(), level1q2.class));
}
public void buttonOnClickBack(View v) {
Button back = (Button) v;
startActivity(new Intent(getApplicationContext(), Activity2.class));
}
}
and this is the first level second question class.
public class level1q2 extends ActionBarActivity {
private EditText mans1;
private TextView mcount;
int sum;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level1q2);
TextView textView = (TextView)findViewById(R.id.count);
Intent intent = getIntent();
int count = intent.getIntExtra("mycount", 0);
textView.setText(count);}
public void Onclick(View view)
{
mans1 = (EditText) findViewById(R.id.ans1);
mcount = (TextView) findViewById(R.id.count);
double answer = Double.parseDouble(mans1.getText().toString());
if (answer == (15-3)) {
Toast.makeText(level1q2.this, "الإجابة صحيحة", Toast.LENGTH_LONG).show();
int count = getIntent().getIntExtra("mycount", 0);
mcount.setText(count++);
} else {
Toast.makeText(level1q2.this, "الإجابة خاطئة", Toast.LENGTH_LONG).show();
int count = getIntent().getIntExtra("mycount", 0);
mcount.setText(count);
}
}
public void buttonOnClickgo(View v) {
Button next = (Button) v;
startActivity(new Intent(getApplicationContext(), level1q3.class));
}
public void buttonOnClickBack(View v) {
Button back = (Button) v;
startActivity(new Intent(getApplicationContext(), Activity2.class));
}
}
I did some changes in these classes because I want to pass the count variable from first question to the second question activity.
It is was working before I edited them but now it shows "unfortunately stopped" message ..
please review the codes
After debugging ..
04:30:29.101 1075-1075/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb3b03ba8)
08-23 04:30:29.121 1075-1075/com.mainuser.math.passgrade4.passgrade4 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mainuser.math.passgrade4.passgrade4, PID: 1075
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mainuser.math.passgrade4.passgrade4/com.mainuser.math.passgrade4.passgrade4.level1}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
at com.mainuser.math.passgrade4.passgrade4.level1.onCreate(level1.java:34)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
08-23 04:30:37.051 1075-1075/com.mainuser.math.passgrade4.passgrade4 I/Process﹕ Sending signal. PID: 1075 SIG: 9
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11347: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11353: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 9041: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
08-23 04:30:38.101 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
08-23 04:30:38.101 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 366: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
08-23 04:30:38.101 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-23 04:30:38.111 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
08-23 04:30:38.111 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 388: Landroid/content/res/TypedArray;.getType (I)I
08-23 04:30:38.111 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-23 04:30:38.591 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ GC_FOR_ALLOC freed 125K, 7% free 2894K/3100K, paused 35ms, total 35ms
The problem is exactly what your exception says:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mainuser.math.passgrade4.passgrade4/com.mainuser.math.passgrade4.passgrade4.level1}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
...
Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
at com.mainuser.math.passgrade4.passgrade4.level1.onCreate(level1.java:34)
...
Your button is an ImageButton, but you tried to cast it to Button (which is not a superclass of ImageButton).

How to check if checkbox was checked?

I am creating a quiz app for androids. I have 3 fragments and 3 checkboxes on first two of them. On the last fragment there is a button which when pressed opens an activity called "End". I need that on the "End" activity a result would appear of how many correct answers one have chosen.
Firstly, I've tried to check if it's working with only the first fragment, but I got stuck. The app closes when I press the button.
End.java:
package bandymas.viewpagerexample;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class End extends ActionBarActivity {
private CheckBox checkBox1, checkBox2, checkBox3;
private Button button;
TextView newresult = (TextView)findViewById(R.id.textView1);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end);
getSupportActionBar().hide();
addListenerOnButton();
}
private void addListenerOnButton() {
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
//Run when button is clicked
#Override
public void onClick(View v) {
StringBuffer result = new StringBuffer();
result.append("CheckBox1 : ").append(checkBox1.isChecked());
result.append("\nCheckbox2 : ").append(checkBox2.isChecked());
result.append("\nCheckBox3 :").append(checkBox3.isChecked());
newresult.setText("My Awesome Text");
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_naujas_baigimas, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here's my logcat:
04-01 20:04:37.564 6020-6020/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:04:37.564 6020-6020/bandymas.viewpagerexample I/PersonaManager﹕ getPersonaService() name persona_policy
04-01 20:04:37.684 6020-6020/bandymas.viewpagerexample I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
04-01 20:04:37.734 6020-6020/bandymas.viewpagerexample D/OpenGLRenderer﹕ Enabling debug mode 0
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=SEPF_GT-I9505_4.4.2_0033
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample E/dalvikvm﹕ >>>>> Normal User
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample E/dalvikvm﹕ >>>>> bandymas.viewpagerexample [ userId:0 | appId:10229 ]
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ Late-enabling CheckJNI
04-01 20:07:31.584 7094-7094/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:07:31.594 7094-7094/bandymas.viewpagerexample I/PersonaManager﹕ getPersonaService() name persona_policy
04-01 20:07:31.794 7094-7094/bandymas.viewpagerexample I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
04-01 20:07:31.844 7094-7094/bandymas.viewpagerexample D/OpenGLRenderer﹕ Enabling debug mode 0
04-01 20:07:42.454 7094-7094/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 11347: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 11353: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 9041: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 365: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 387: Landroid/content/res/TypedArray;.getType (I)I
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample D/AndroidRuntime﹕ Shutting down VM
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4187fda0)
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: bandymas.viewpagerexample, PID: 7094
java.lang.RuntimeException: Unable to start activity ComponentInfo{bandymas.viewpagerexample/bandymas.viewpagerexample.End}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at bandymas.viewpagerexample.End.addListenerOnButton(End.java:33)
at bandymas.viewpagerexample.End.onCreate(End.java:23)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
            at android.app.ActivityThread.access$900(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            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:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
activity_end.xml:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="bandymas.viewpagerexample.End">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Result"
android:id="#+id/textView1"
android:layout_marginTop="100dp"
android:textSize="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Please Check that there is the button(R.id.button) in activity_end.xml.
I guess that the button's id doesn't exist in activity_end.xml.

New Activity Problems

Okay, so i finally got my button to start my new activity from the main activity. now, the problem i have is that when the new activity starts, the avd gives me an error saying "unfortunately, yourApp has stopped working". I tried for hours to detect the problem untill i began to comment some part of the new activity's code and then finally, i found it. keep in mind, that almost all the variables i used in the new activity also had common names and ids to those in the mainActivity, but this should not be the problem since i am not passing anything through both activities...at least not now. The problem was from the spinners. their declaration worked fine...i guess, the findViewByid method gave no problem, the arrayAdapter also gave no problems but i noticed that the app only shuts down when i remove the comments from the onItemSelectedListener and the setAdapters methods. i don't know why this happens. i used the same code for the mainActivity and it works perfectly. Dunno if i overloaded the onCreate method but as i said earlier, it works fine in the mainActivity. the new activity code for th onCreate method is given below...the other parts of the code works fine.
public class firstYearSecondSemester2 extends Activity implements AdapterView.OnItemSelectedListener {
private String[] grades;
public Spinner spinner0, spinner1, spinner2, spinner3, spinner4, spinner5, spinner6, spinner7, spinner8;
private double[] grade_values = {0.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0};
//private Spinner gpa_grade0, gpa_grade1, gpa_grade2, gpa_grade3, gpa_grade4, gpa_grade5;
private double gpa_grade_0, gpa_grade_1, gpa_grade_2, gpa_grade_3, gpa_grade_4, gpa_grade_5, gpa_grade_6, gpa_grade_7, gpa_grade_8;
private TextView gpa, gpa_credits0, gpa_credits1, gpa_credits2, gpa_credits3, gpa_credits4,gpa_credits5, gpa_credits6, gpa_credits7,gpa_credits8;
private int gpa_credits_0, gpa_credits_1, gpa_credits_2, gpa_credits_3, gpa_credits_4, gpa_credits_5, gpa_credits_6, gpa_credits_7, gpa_credits_8;
public int[] spinner_ids;
public int spinner_check;
public int spinner_index;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_year_second_semester2);
spinner_ids = new int[9];
spinner_check = 0;
spinner_index = 0;
gpa = (TextView) findViewById(R.id.gpa_results_text);
grades = getResources().getStringArray(R.array.grades);
gpa_credits0 = (TextView) findViewById(R.id.gpa_credits_0);
gpa_credits1 = (TextView) findViewById(R.id.gpa_credits_1);
gpa_credits2 = (TextView) findViewById(R.id.gpa_credits_2);
gpa_credits3 = (TextView) findViewById(R.id.gpa_credits_3);
gpa_credits4 = (TextView) findViewById(R.id.gpa_credits_4);
gpa_credits5 = (TextView) findViewById(R.id.gpa_credits_5);
gpa_credits6 = (TextView) findViewById(R.id.gpa_credits_6);
gpa_credits7 = (TextView) findViewById(R.id.gpa_credits_7);
gpa_credits8 = (TextView) findViewById(R.id.gpa_credits_8);
spinner0 = (Spinner) findViewById(R.id.gradeSpinner0);
spinner1 = (Spinner) findViewById(R.id.gradeSpinner1);
spinner2 = (Spinner) findViewById(R.id.gradeSpinner2);
spinner3 = (Spinner) findViewById(R.id.gradeSpinner3);
spinner4 = (Spinner) findViewById(R.id.gradeSpinner4);
spinner5 = (Spinner) findViewById(R.id.gradeSpinner5);
spinner6 = (Spinner) findViewById(R.id.gradeSpinner6);
spinner7 = (Spinner) findViewById(R.id.gradeSpinner7);
spinner8 = (Spinner) findViewById(R.id.gradeSpinner8);
ArrayAdapter<String> each_grade = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, grades);
each_grade.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner0.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner1.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner2.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner3.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner4.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner5.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner6.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner7.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner8.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner0.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner1.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner2.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner3.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner4.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner5.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner6.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner7.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner8.setOnItemSelectedListener(firstYearSecondSemester2.this);
}
Logcat Messages
04-14 02:21:16.260 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ Not late-enabling CheckJNI (already on)
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11350: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11356: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 9044: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 368: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 390: Landroid/content/res/TypedArray;.getType (I)I
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-14 02:21:17.150 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ GC_FOR_ALLOC freed 140K, 8% free 3075K/3340K, paused 0ms, total 5ms
04-14 02:21:17.150 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm-heap﹕ Grow heap (frag case) to 4.195MB for 1127532-byte allocation
04-14 02:21:17.210 1772-1781/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ GC_FOR_ALLOC freed 13K, 7% free 4163K/4444K, paused 3ms, total 4ms
04-14 02:21:18.930 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/Choreographer﹕ Skipped 103 frames! The application may be doing too much work on its main thread.
04-14 02:21:18.930 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
04-14 02:27:17.189 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/Choreographer﹕ Skipped 60 frames! The application may be doing too much work on its main thread.
04-14 02:27:17.309 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ GC_FOR_ALLOC freed 168K, 7% free 4507K/4796K, paused 2ms, total 2ms
04-14 02:29:34.831 2264-2264/com.daftnerds.juliusugochukwu.cgpa4 D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
Now, once i click the button to start the new activity, this happens
04-14 02:30:40.562 2264-2264/com.daftnerds.juliusugochukwu.cgpa4 D/AndroidRuntime﹕ Shutting down VM
04-14 02:30:40.562 2264-2264/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0d3cb20)
04-14 02:30:40.602 2264-2264/com.daftnerds.juliusugochukwu.cgpa4 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.daftnerds.juliusugochukwu.cgpa4, PID: 2264
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.daftnerds.juliusugochukwu.cgpa4/com.daftnerds.juliusugochukwu.cgpa4.firstYearSecondSemester2}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.daftnerds.juliusugochukwu.cgpa4.firstYearSecondSemester2.onCreate(firstYearSecondSemester2.java:76)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
change line with
spinner0.setAdapter(new NothingSelectedSpinnerAdapter(each_grade,R.layout.contact_spinner_row_nothing_selected,this));
and clean your project once.
Omg...found the problem. Truly it was line 76. Please don't be annoyed. I initially had 9 spinners in the main activity and 7 in the new activity. I copied the main activity spinner codes and pasted in the new activity. So when it gets to the 8th spinner (line 76), it gives an error since that spinner is not available in the layout. Thanks for all the help suggested guys...really appreciate them.

Error finished activity with other class

Someone can explain why the error occurs LISTED AT THE END OF Question, closing the application, when I try to terminate the application through another class:
classe1.class
...
...
AlertDialogManager alert = new AlertDialogManager();
NetworkAvailable internet = new NetworkAvailable();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!internet.isNetworkAvailable(this)){
alert.showAlertDialog(MainActivity.this, "No network!", false);
if (alert.Saindo()){
//ERROR HAPPENS THE FINISH (), I WANTED THAT THIS FUNCTION execute
//AFTER I cancel THERE IN class3.
//The app NOT START, if I let this finish here, but if I withdraw,
//The LOG SPEAK:
Log("Finished", "Closing the application!")
finish();
}
}
}
}
classe2.class:
public class NetworkAvailable{
public boolean isNetworkAvailable (final Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
boolean isAvailable = false;
if(networkInfo != null && networkInfo.isConnected()){
Toast.makeText(context, "CONECTED", Toast.LENGTH_LONG).show();
isAvailable = true;
} else {
Toast.makeText(context, "NO CONECTED", Toast.LENGTH_LONG).show();
isAvailable = false;
}
return isAvailable;
}
}
classe3.class:
public class AlertDialogManager {
public boolean showAlertDialog(final Context context, final String title, final Boolean status) {
if(status == false){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(false);
builder.setTitle(title);
builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Log.v("CANCELANDO", "cancelado");
showAlertDialog(context, title, true);
Saindo();
}
});
builder.setPositiveButton("Tentar novamente", new DialogInterface.OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which)
{
final ConnectivityManager conectivtyManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (conectivtyManager.getActiveNetworkInfo() != null
&& conectivtyManager.getActiveNetworkInfo().isAvailable()
&& conectivtyManager.getActiveNetworkInfo().isConnected()) {
}
dialog.dismiss();
showAlertDialog(context, title, false);
}
});
AlertDialog dialog = builder.create(); // calling builder.create after adding buttons
dialog.show();
return status;
}
return status;
}
public boolean Saindo(){
Log.v("SAINDO", "saiu");
return true;
}
}
01-26 22:17:05.721: E/WindowManager(25592): Activity ffitteste.favoritos.mapa.rafael.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#418654f0 that was originally added here
01-26 22:17:05.721: E/WindowManager(25592): android.view.WindowLeaked: Activity ffitteste.favoritos.mapa.rafael.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#418654f0 that was originally added here
01-26 22:17:05.721: E/WindowManager(25592): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:351)
01-26 22:17:05.721: E/WindowManager(25592): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:279)
01-26 22:17:05.721: E/WindowManager(25592): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
01-26 22:17:05.721: E/WindowManager(25592): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
01-26 22:17:05.721: E/WindowManager(25592): at android.view.Window$LocalWindowManager.addView(Window.java:537)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.Dialog.show(Dialog.java:278)
01-26 22:17:05.721: E/WindowManager(25592): at ffitteste.favoritos.mapa.rafael.AlertDialogManager.showAlertDialog(AlertDialogManager.java:48)
01-26 22:17:05.721: E/WindowManager(25592): at ffitteste.favoritos.mapa.rafael.MainActivity.onCreate(MainActivity.java:103)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.Activity.performCreate(Activity.java:4465)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread.access$600(ActivityThread.java:128)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
01-26 22:17:05.721: E/WindowManager(25592): at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 22:17:05.721: E/WindowManager(25592): at android.os.Looper.loop(Looper.java:137)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread.main(ActivityThread.java:4514)
01-26 22:17:05.721: E/WindowManager(25592): at java.lang.reflect.Method.invokeNative(Native Method)
01-26 22:17:05.721: E/WindowManager(25592): at java.lang.reflect.Method.invoke(Method.java:511)
01-26 22:17:05.721: E/WindowManager(25592): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
01-26 22:17:05.721: E/WindowManager(25592): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
01-26 22:17:05.721: E/WindowManager(25592): at dalvik.system.NativeStart.main(Native Method)
01-26 22:17:05.729: E/WindowManager(25592): Activity ffitteste.favoritos.mapa.rafael.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41776208 that was originally added here
01-26 22:17:05.729: E/WindowManager(25592): android.view.WindowLeaked: Activity ffitteste.favoritos.mapa.rafael.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41776208 that was originally added here
01-26 22:17:05.729: E/WindowManager(25592): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:351)
01-26 22:17:05.729: E/WindowManager(25592): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:279)
01-26 22:17:05.729: E/WindowManager(25592): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
01-26 22:17:05.729: E/WindowManager(25592): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
01-26 22:17:05.729: E/WindowManager(25592): at android.view.Window$LocalWindowManager.addView(Window.java:537)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.Dialog.show(Dialog.java:278)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
01-26 22:17:05.729: E/WindowManager(25592): at ffiteteste.favoritos.servicos.rafael.GPSTracker.showSettingsAlert(GPSTracker.java:194)
01-26 22:17:05.729: E/WindowManager(25592): at ffitteste.favoritos.mapa.rafael.MainActivity.GPSzoom(MainActivity.java:819)
01-26 22:17:05.729: E/WindowManager(25592): at ffitteste.favoritos.mapa.rafael.MainActivity.onCreate(MainActivity.java:164)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.Activity.performCreate(Activity.java:4465)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread.access$600(ActivityThread.java:128)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
01-26 22:17:05.729: E/WindowManager(25592): at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 22:17:05.729: E/WindowManager(25592): at android.os.Looper.loop(Looper.java:137)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread.main(ActivityThread.java:4514)
01-26 22:17:05.729: E/WindowManager(25592): at java.lang.reflect.Method.invokeNative(Native Method)
01-26 22:17:05.729: E/WindowManager(25592): at java.lang.reflect.Method.invoke(Method.java:511)
01-26 22:17:05.729: E/WindowManager(25592): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
01-26 22:17:05.729: E/WindowManager(25592): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
01-26 22:17:05.729: E/WindowManager(25592): at dalvik.system.NativeStart.main(Native Method)
HELPER!
It's a little unclear since you didn't post the actual class names with your code snippets. But it looks like it's because you don't close the Dialog before finishing the Activity here
if (alert.Saindo()){
If you change that to
if (alert.Saindo()){
if (alert != null && alert.isShowing())
alert.dismiss();
it should take care of your problem.
You are finishing the Activity while the Dialog is still showing.

Can not use a Runnable

I'm using a Runnable as a Timer that alternatively runs a block.
I got this code from here and changed it as such:
public class TikingTimer {
private long countDownInterval;
private boolean status;
public TikingTimer(long pCountDownInterval) {
this.countDownInterval = pCountDownInterval;
status = false;
Initialize();
}
public void Stop() {
status = false;
}
public void Start() {
status = true;
}
public void Initialize()
{
final Handler handler = new Handler();
final Runnable counter = new Runnable(){
public void run(){
if(status) {
//TODO my code
} else {
handler.postDelayed(this, countDownInterval);
}
}
};
handler.postDelayed(counter, countDownInterval);
}
}
... and at onCreate method I used :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TikingTimer tt = new TikingTimer(1000);
tt.Start();
}
But when I run the project, it force-closes.
Is it wrong to use Runnable at onCreate method?
Thanks.
The LogCat stack trace is:
08-11 13:04:55.384: E/AndroidRuntime(3125): FATAL EXCEPTION: main
08-11 13:04:55.384: E/AndroidRuntime(3125): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{kawthar.taghvimdigital/kawthar.taghvimdigital.MainActivity}: java.lang.NullPointerException
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.os.Looper.loop(Looper.java:137)
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-11 13:04:55.384: E/AndroidRuntime(3125): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 13:04:55.384: E/AndroidRuntime(3125): at java.lang.reflect.Method.invoke(Method.java:511)
08-11 13:04:55.384: E/AndroidRuntime(3125): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-11 13:04:55.384: E/AndroidRuntime(3125): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-11 13:04:55.384: E/AndroidRuntime(3125): at dalvik.system.NativeStart.main(Native Method)
08-11 13:04:55.384: E/AndroidRuntime(3125): Caused by: java.lang.NullPointerException
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.app.Activity.findViewById(Activity.java:1839)
08-11 13:04:55.384: E/AndroidRuntime(3125): at kawthar.taghvimdigital.MainActivity.<init>(MainActivity.java:14)
08-11 13:04:55.384: E/AndroidRuntime(3125): at java.lang.Class.newInstanceImpl(Native Method)
08-11 13:04:55.384: E/AndroidRuntime(3125): at java.lang.Class.newInstance(Class.java:1319)
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
08-11 13:04:55.384: E/AndroidRuntime(3125): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
08-11 13:04:55.384: E/AndroidRuntime(3125): ... 11 more
In your MainActivity (not posted), at line 14, you are looking up a View through method:
findViewById(Activity.java:1839)
... which is not found.
Since you manipulate this view somehow, the NullPointerException you posted is thrown.
You are trying to access a view that is not defined in your xml layout of the main activity.
Check the Line 14 on your MainActivity
This issue is not due to Runnable.

Categories