Socket client program error - android

After the program running,click the send button,then pop-up dialog said the program has already exited。
I don‘t know what is the problem,how can I fix it?
Is there anybody has the same issue,can you help me?
package com.secion9.clienttest;
import android.os.Bundle;
import android.app.Activity;
import android.widget.*;
import java.net.Socket;
import java.io.IOException;
import java.io.OutputStream;
import android.view.View;
import android.view.View.OnClickListener;
public class ClientActivity extends Activity {
Button btSend;
EditText etMsg;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_client);
btSend=(Button)this.findViewById(R.id.button1);
etMsg=(EditText)this.findViewById(R.id.EditText1);
btSend.setOnClickListener(
new OnClickListener(){
public void onClick(View v)
{
try
{
Socket socket=new Socket("127.0.0.1",5050);
OutputStream outputStream=socket.getOutputStream();
byte[] buffer=etMsg.getText().toString().getBytes();
outputStream.write(buffer);
outputStream.flush();
}
catch(IOException e)
{
e.printStackTrace();
}
}
});
}
}
logcat
09-02 08:24:31.189: E/Trace(627): error opening trace file: No such file or directory (2)
09-02 08:24:32.259: D/gralloc_goldfish(627): Emulator without GPU emulation detected.
09-02 08:24:32.598: I/Choreographer(627): Skipped 40 frames! The application may be doing too much work on its main thread.
09-02 08:25:04.471: D/AndroidRuntime(627): Shutting down VM
09-02 08:25:04.471: W/dalvikvm(627): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-02 08:25:04.539: E/AndroidRuntime(627): FATAL EXCEPTION: main
09-02 08:25:04.539: E/AndroidRuntime(627): android.os.NetworkOnMainThreadException
09-02 08:25:04.539: E/AndroidRuntime(627): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
09-02 08:25:04.539: E/AndroidRuntime(627): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
09-02 08:25:04.539: E/AndroidRuntime(627): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
09-02 08:25:04.539: E/AndroidRuntime(627): at libcore.io.IoBridge.connect(IoBridge.java:112)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.Socket.startupSocket(Socket.java:566)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.Socket.tryAllAddresses(Socket.java:127)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.Socket.<init>(Socket.java:177)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.net.Socket.<init>(Socket.java:149)
09-02 08:25:04.539: E/AndroidRuntime(627): at com.secion9.clienttest.ClientActivity$1.onClick(ClientActivity.java:31)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.view.View.performClick(View.java:4084)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.view.View$PerformClick.run(View.java:16966)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.os.Handler.handleCallback(Handler.java:615)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.os.Handler.dispatchMessage(Handler.java:92)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.os.Looper.loop(Looper.java:137)
09-02 08:25:04.539: E/AndroidRuntime(627): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 08:25:04.539: E/AndroidRuntime(627): at java.lang.reflect.Method.invoke(Method.java:511)
09-02 08:25:04.539: E/AndroidRuntime(627): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-02 08:25:04.539: E/AndroidRuntime(627): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-02 08:25:04.539: E/AndroidRuntime(627): at dalvik.system.NativeStart.main(Native Method)
09-02 08:25:07.079: I/Process(627): Sending signal. PID: 627 SIG: 9

It sounds like you're doing networking on the main thread. That's a no-no:
http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
SOLUTION:
Modify your app so that it spawns off a thread or async task to do the network I/O.
Here's a good link that discusses how:
http://www.vogella.com/articles/AndroidPerformance/article.html

Have put in AndroidManifest.xml Internet permission?
Regards,

Skipped 40 frames! The application may be doing too much work on its main thread.
and
NetworkOnMainThreadException
Are there to tell you that you're blocking the main thread, which causes and ANR and the app can get killed :)
Try to implement your network stuff on a background thread, or with an AsyncTask

According to the documentation at [Android Developers][1]:
The exception that is thrown when an application attempts to perform a
networking operation on its main thread.
This is only thrown for applications targeting the Honeycomb SDK or
higher. Applications targeting earlier SDK versions are allowed to do
networking on their main event loop threads, but it's heavily
discouraged.
So you need to target a lower SDK or make a new thread for handling networks connections.

Related

react native webview java.lang.NullPointerException

Many times to open the WebView, resulting in a number of WebView, it is estimated that the memory leak, I would like to ask a way to solve it?
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0xa617e908)
uncaughtException java.lang.NullPointerException
java.lang.NullPointerException
at android.webkit.WebViewClassic.loadUrlImpl(WebViewClassic.java:2525)
at android.webkit.WebViewClassic.loadUrlImpl(WebViewClassic.java:2541)
at android.webkit.WebViewClassic.loadUrl(WebViewClassic.java:2534)
at android.webkit.WebView.loadUrl(WebView.java:784)
at cn.nin.common.MyAndroid$MyAsyncTask.onPostExecute(MyAndroid.java:1461)
at cn.nin.common.MyAndroid$MyAsyncTask.onPostExecute(MyAndroid.java:1362)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
You didn't give us enough information. NullPointerException can be thrown for many reasons.That error means that an application attempts to use an object reference that has the null value.

AVD crashes saying 'Unfortunately, libcocos2dx has crashed'

I just loaded my app created by cocos2dx-3.10 and when I open with it an AVD (again I haven't done any modifications to the app) the app crashes and gives the error: Unfortunately, libcocos2dx has crashed.
here is what I get in my android Monitor:
03-05 18:34:56.668 1435-1435/? D/dalvikvm: Not late-enabling CheckJNI (already on)
03-05 18:34:56.989 1435-1435/com.trying.name E/Trace: error opening trace file: No such file or directory (2)
03-05 18:34:57.419 1435-1435/com.trying.name D/AndroidRuntime: Shutting down VM
03-05 18:34:57.419 1435-1435/com.trying.name W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb2f2b288)
03-05 18:34:57.518 1435-1435/com.trying.name E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:263)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
03-05 18:35:11.559 1435-1435/? I/Process: Sending signal. PID: 1435 SIG: 9

Having issues integrating Scandit SDK into my app

Decided to use Scandit SDK to get the barcode scanning feature in my app. Unfortunately, since I'm relatively new to Android development and Java in general I've run into a few issues that I can't seem to work out. The demo that Scandit provided doesn't give any errors(runs fine) but crashes when I try to start it up (pressing a button from one activity is meant to start it up). I've tried reading the logcat and googling a solution to the problems but I'm not getting the right solutions. Does anyone have an idea of what I'm doing wrong?
Logcat is provided below:
10-08 23:30:00.807 21563-21563/com.kwesimbia.management D/AndroidRuntime? Shutting down VM
10-08 23:30:00.807 21563-21563/com.kwesimbia.management W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0x40aa4228)
10-08 23:30:00.817 21563-21563/com.kwesimbia.management E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3082)
at android.view.View.performClick(View.java:3549)
at android.view.View$PerformClick.run(View.java:14393)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
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:3077)
at android.view.View.performClick(View.java:3549)
at android.view.View$PerformClick.run(View.java:14393)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.kwesimbia.management.ScanditSDKDemoSimple
at com.kwesimbia.management.Activity_D.initiateCodeScan(Activity_D.java:63)
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:3077)
at android.view.View.performClick(View.java:3549)
at android.view.View$PerformClick.run(View.java:14393)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
10-08 23:30:00.817 32726-587/? E/EmbeddedLogger? App crashed!
Process: com.kwesimbia.management
10-08 23:30:00.817 32726-587/? E/EmbeddedLogger? App crashed!
Package: com.kwesimbia.management v1 (1.0)
10-08 23:30:00.817 32726-587/? E/EmbeddedLogger?
Application Label: firstapp
10-08 23:30:00.827 32726-587/? W/ActivityManager?
Force finishing activity com.kwesimbia.management/.Activity_D
I came across this problem as well, my solution was to extract the library files and put them as their files in the lib folder
The library basically isn't being exported with it
EDIT
So I checked out my project, basically I did these things:
In the libs folder I have a new folder called armeabi and inside that I have libscanditsdk-android-3.3.1.so
Then in my build path I have also referenced the jar file that they provide:
<classpathentry exported="true" kind="lib" path="C:/GIT/Android/FwayScannerProject/FwayScanner/libs/scanditsdk-barcodepicker-android-3.3.1.jar"/>

pointing the error message in the following log snippet

Ok below here is what my log generates when I try to run my application . The application fails unexpectedly and does not even start
09-02 04:28:51.856: D/dalvikvm(781): GC_FOR_ALLOC freed 66K, 7% free 2542K/2728K, paused 51ms, total 66ms
09-02 04:28:51.866: I/dalvikvm-heap(781): Grow heap (frag case) to 3.181MB for 614500-byte allocation
09-02 04:28:51.936: D/dalvikvm(781): GC_FOR_ALLOC freed <1K, 6% free 3142K/3332K, paused 67ms, total 67ms
09-02 04:28:52.406: W/SoundPool(781): sample 1 not READY
09-02 04:28:53.116: D/gralloc_goldfish(781): Emulator without GPU emulation detected.
09-02 04:28:53.376: I/Choreographer(781): Skipped 33 frames! The application may be doing too much work on its main thread.
09-02 04:29:22.606: E/AudioTrack(781): Could not get audio output for stream type 3
09-02 04:29:22.606: E/SoundPool(781): Error creating AudioTrack
09-02 04:29:22.756: D/dalvikvm(781): GC_FOR_ALLOC freed 30K, 5% free 3523K/3672K, paused 19ms, total 21ms
09-02 04:29:22.756: I/dalvikvm-heap(781): Grow heap (frag case) to 4.159MB for 635812-byte allocation
09-02 04:29:22.856: D/dalvikvm(781): GC_FOR_ALLOC freed 1K, 4% free 4143K/4296K, paused 97ms, total 97ms
09-02 04:29:22.966: I/Choreographer(781): Skipped 91 frames! The application may be doing too much work on its main thread.
09-02 04:29:23.206: I/Choreographer(781): Skipped 55 frames! The application may be doing too much work on its main thread.
09-02 04:29:23.375: I/Choreographer(781): Skipped 35 frames! The application may be doing too much work on its main thread.
09-02 04:29:23.776: I/Choreographer(781): Skipped 79 frames! The application may be doing too much work on its main thread.
09-02 04:29:28.016: D/dalvikvm(781): GC_FOR_ALLOC freed 108K, 5% free 4436K/4664K, paused 111ms, total 133ms
09-02 04:29:28.045: I/dalvikvm-heap(781): Grow heap (frag case) to 5.030MB for 614500-byte allocation
09-02 04:29:28.096: D/dalvikvm(781): GC_FOR_ALLOC freed 1K, 5% free 5034K/5268K, paused 55ms, total 56ms
09-02 04:29:28.235: W/SoundPool(781): sample 1 not READY
09-02 04:29:28.785: I/Choreographer(781): Skipped 50 frames! The application may be doing too much work on its main thread.
09-02 04:29:31.626: E/AudioTrack(781): Could not get audio output for stream type 3
09-02 04:29:31.626: E/SoundPool(781): Error creating AudioTrack
09-02 04:29:31.746: E/SlaveBlueTooth(781): +++ ON CREATE +++
09-02 04:29:31.766: W/System.err(781): java.io.IOException: open failed: EROFS (Read-only file system)
09-02 04:29:31.776: W/System.err(781): at java.io.File.createNewFile(File.java:948)
09-02 04:29:31.785: W/System.err(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:118)
09-02 04:29:31.796: W/System.err(781): at android.app.Activity.performCreate(Activity.java:5133)
09-02 04:29:31.796: W/System.err(781): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-02 04:29:31.796: W/System.err(781): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-02 04:29:31.816: W/System.err(781): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-02 04:29:31.816: W/System.err(781): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-02 04:29:31.816: W/System.err(781): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-02 04:29:31.826: W/System.err(781): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 04:29:31.826: W/System.err(781): at android.os.Looper.loop(Looper.java:137)
09-02 04:29:31.826: W/System.err(781): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-02 04:29:31.836: W/System.err(781): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 04:29:31.836: W/System.err(781): at java.lang.reflect.Method.invoke(Method.java:525)
09-02 04:29:31.846: W/System.err(781): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-02 04:29:31.846: W/System.err(781): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-02 04:29:31.856: W/System.err(781): at dalvik.system.NativeStart.main(Native Method)
09-02 04:29:31.856: W/System.err(781): Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
09-02 04:29:31.876: W/System.err(781): at libcore.io.Posix.open(Native Method)
09-02 04:29:31.886: W/System.err(781): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
09-02 04:29:31.886: W/System.err(781): at java.io.File.createNewFile(File.java:941)
09-02 04:29:31.896: W/System.err(781): ... 15 more
09-02 04:29:32.016: D/AndroidRuntime(781): Shutting down VM
09-02 04:29:32.016: W/dalvikvm(781): threadid=1: thread exiting with uncaught exception (group=0x41465700)
09-02 04:29:32.066: E/AndroidRuntime(781): FATAL EXCEPTION: main
09-02 04:29:32.066: E/AndroidRuntime(781): java.lang.RuntimeException: Unable to start activity ComponentInfo{hellog.diwesh.NugaBest/helog.diwesh.NugaBest.BTSmartSlavemodule}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.os.Looper.loop(Looper.java:137)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-02 04:29:32.066: E/AndroidRuntime(781): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 04:29:32.066: E/AndroidRuntime(781): at java.lang.reflect.Method.invoke(Method.java:525)
09-02 04:29:32.066: E/AndroidRuntime(781): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-02 04:29:32.066: E/AndroidRuntime(781): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-02 04:29:32.066: E/AndroidRuntime(781): at dalvik.system.NativeStart.main(Native Method)
09-02 04:29:32.066: E/AndroidRuntime(781): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-02 04:29:32.066: E/AndroidRuntime(781): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:226)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.Activity.requestWindowFeature(Activity.java:3264)
09-02 04:29:32.066: E/AndroidRuntime(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:141)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.Activity.performCreate(Activity.java:5133)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-02 04:29:32.066: E/AndroidRuntime(781): ... 11 more
This is the error from your LogCat :
FATAL EXCEPTION: main
09-02 04:29:32.066: E/AndroidRuntime(781): java.lang.RuntimeException: Unable to start activity ComponentInfo{hellog.diwesh.NugaBest/helog.diwesh.NugaBest.BTSmartSlavemodule}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
Multiple issues here:
09-02 04:29:31.766: W/System.err(781): java.io.IOException: open failed: EROFS (Read-only file system)
09-02 04:29:31.776: W/System.err(781): at java.io.File.createNewFile(File.java:948)
09-02 04:29:31.785: W/System.err(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:118)
In BTSmartSlavemodule.java line 118 you're trying to create a new file on a read-only file system.
09-02 04:29:32.066: E/AndroidRuntime(781): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
09-02 04:29:32.066: E/AndroidRuntime(781): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:226)
09-02 04:29:32.066: E/AndroidRuntime(781): at android.app.Activity.requestWindowFeature(Activity.java:3264)
09-02 04:29:32.066: E/AndroidRuntime(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:141)
On line 141 of the same file you're trying to call requestWindowFeature() after calling setContentView(). You need to set window features before setContentView().
You call requestFeature() not in right place... try to call this method before setContentView(R.layout.activity)
The cause of this error is :
09-02 04:29:32.066: E/AndroidRuntime(781): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
And this cause happened at :
09-02 04:29:31.785: W/System.err(781): at helog.diwesh.NugaBest.BTSmartSlavemodule.onCreate(BTSmartSlavemodule.java:118)
Where you put code .requestWindowFeature(). To avoid this cause you must put this code before setContentView(R.layout.your_layout);
I think you are trying to create file on sdcard but you don't have specified permission to write external storage in manifest file
Add this line to manifest.xml file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Android app stops unexpectedly

I wrote a program for android which connects to internet.
I got the following error:
The application has stopped unexpectedly.Please try again..
What's the problem?
Log cat in Eclipse is as follows:
09-02 12:43:42.421: W/dalvikvm(12362): threadid=1: thread exiting with uncaught exception (group=0x40018578)
09-02 12:43:42.437: E/AndroidRuntime(12362): FATAL EXCEPTION: main
09-02 12:43:42.437: E/AndroidRuntime(12362): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.networkusage/com.example.networkusage.NetworkActivity}: java.lang.ClassNotFoundException: com.example.networkusage.NetworkActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.networkusage-1.apk]
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.os.Looper.loop(Looper.java:130)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.main(ActivityThread.java:3687)
09-02 12:43:42.437: E/AndroidRuntime(12362): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 12:43:42.437: E/AndroidRuntime(12362): at java.lang.reflect.Method.invoke(Method.java:507)
09-02 12:43:42.437: E/AndroidRuntime(12362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-02 12:43:42.437: E/AndroidRuntime(12362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-02 12:43:42.437: E/AndroidRuntime(12362): at dalvik.system.NativeStart.main(Native Method)
09-02 12:43:42.437: E/AndroidRuntime(12362): Caused by: java.lang.ClassNotFoundException: com.example.networkusage.NetworkActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.networkusage-1.apk]
09-02 12:43:42.437: E/AndroidRuntime(12362): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
09-02 12:43:42.437: E/AndroidRuntime(12362): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-02 12:43:42.437: E/AndroidRuntime(12362): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-02 12:43:42.437: E/AndroidRuntime(12362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
09-02 12:43:42.437: E/AndroidRuntime(12362): ... 11 more
Found that my package name is:
com.example.android.networkusage
and on the manifest is as:
android:name="com.example.networkusage.NetworkActivity"
so changed the manifest to:
android:name="com.example.android.networkusage.NetworkActivity"
Looks like your com.example.networkusage.NetworkActivity class is missing.
If it is declared in an external library, add that jar file to the "libs" folder and add it to the build path and then build your project again.
Don't forget to clean it too!

Categories

Resources