Android AccountManager throws AuthenticatorException: bind failure when adding account - java

I am trying to add custom account with AccountManager.addAccount() on android. I was following this tutorial. When I am trying to get result with AccountManagerCallback's run method I get AuthenticatorException with message: android.accounts.AuthenticatorException: bind failure.
After some research I found two potential solutions, but I already declared authenticator inside application tag, and checked my account type. I also compared manifest permissions with those from tutorial. I am using android studio 1.4, and I tried it on several emulators, and on physical device.
Here is my AndroidManifest.xml, and also authenticator.xml and account_preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.myproject" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/test_logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".view.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".view.LoginActivity"
android:label="#string/app_name">
</activity>
<service
android:name="com.test.myproject.model.utility.MyAuthenticatorService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="#xml/authenticator" />
</service>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
I have also tried naming service .model.utility.MyAuthenticatorService with no effect.
authenticator.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.test.myproject"
android:icon="#drawable/test_logo"
android:smallIcon="#drawable/test_logo"
android:label="#string/not_implemented"
android:accountPreferences="#xml/account_preferences"
/>
</PreferenceScreen>
account_preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="#string/not_implemented" />
<CheckBoxPreference android:title="Use debug server"
android:key="isDebug"
android:summary="Connecting to a debug server instead of prod server"/>
<SwitchPreference android:title="Debug Logs" android:key="logsVerbose" android:summary="Show debug logs on LogCat"/>
</PreferenceScreen>
Here is MyAuthenticatorService:
public class MyAuthenticatorService extends Service {
#Nullable
#Override
public IBinder onBind(Intent intent) {
MyAuthenticator myAuthenticator = new MyAuthenticator(this);
return myAuthenticator.getIBinder();
}
}
Here is MyAuthenticator:
public class MyAuthenticator extends AbstractAccountAuthenticator {
private Context context;
public MyAuthenticator(Context context) {
super(context);
this.context = context;
}
#Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
final Intent intent = new Intent(context, LoginActivity.class);
intent.putExtra(LoginActivity.ARG_ACCOUNT_TYPE, accountType);
intent.putExtra(LoginActivity.ARG_AUTH_TYPE, authTokenType);
intent.putExtra(LoginActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
final Bundle bundle = new Bundle();
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
return bundle;
}
//other override methods (they all return null for now)
}
And here is MainActivity:
public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
private NavigationView navigationView;
private DrawerLayout drawerLayout;
private SharedPreferences sharedPreferences;
private AccountManager accountManager;
private static final String ACCOUNT_TYPE = "com.test.myproject";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer);
this.accountManager = AccountManager.get(this);
signIn(ACCOUNT_TYPE, "access_token");
//other stuff
}
private void signIn(String accountType, String authTokenType) {
final AccountManagerFuture<Bundle> future = accountManager.addAccount(ACCOUNT_TYPE, authTokenType, null, null, this, new AccountManagerCallback<Bundle>() {
#Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bnd = future.getResult();
showMessage("Account was created");
Log.d("udinic", "AddNewAccount Bundle is " + bnd);
} catch (Exception e) {
e.printStackTrace();
showMessage(e.getMessage());
}
}
}, null);
}
}
When debbuging, error is thrown on Bundle bnd = future.getResult();, and future has state 3 and outcome android.accounts.AuthenticatorException: bind failure. Tough execution never gets to LoginActivity, or at least breakpoints are not triggered, here it is:
public class LoginActivity extends AccountAuthenticatorActivity {
public final static String ARG_ACCOUNT_TYPE = "ACCOUNT_TYPE";
public final static String ARG_ACCOUNT_NAME = "AUTH_TYPE";
public final static String ARG_AUTH_TYPE = "ACCOUNT_NAME";
public final static String PARAM_USER_PASS = "USER_PASS";
private AccountManager accountManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
this.accountManager = AccountManager.get(getBaseContext());
}
public void login(View view) {
EditText usernameEditText = (EditText)findViewById(R.id.textLoginUsername);
EditText passwordEditText = (EditText)findViewById(R.id.textLoginPassword);
String ownerUsername = usernameEditText.getText().toString();
String ownerPassword = passwordEditText.getText().toString();
String clientId = "test";
String clientSecret = "test";
AccountManager manager = AccountManager.get(this);
TokenRequestTask tokenRequestTask = new TokenRequestTask();
tokenRequestTask.execute(ownerUsername, ownerPassword, clientId, clientSecret);
}
private class TokenRequestTask extends AsyncTask<String, Void, Intent> {
#Override
protected Intent doInBackground(String... params) {
final String accountType = getIntent().getStringExtra(ARG_ACCOUNT_TYPE);
String ownerUsername = params[0];
String ownerSecret = params[1];
String clientId = params[2];
String clientSecret = params[3];
String authToken = signIn(clientId, clientSecret, ownerUsername, ownerSecret, "password");
Bundle resultData = new Bundle();
resultData.putString(AccountManager.KEY_ACCOUNT_NAME, ownerUsername);
resultData.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
resultData.putString(AccountManager.KEY_AUTHTOKEN, authToken);
resultData.putString(PARAM_USER_PASS, ownerSecret);
final Intent resultIntent = new Intent();
resultIntent.putExtras(resultData);
return resultIntent;
}
}
private String signIn(String clientId, String clientSecret, String ownerUsername, String ownerSecret, String grantType) {
MyApi20ServiceImpl service = (MyApi20ServiceImpl)new ServiceBuilder().provider(MyApi20.class)
.apiKey(clientId)
.apiSecret(clientSecret)
.signatureType(SignatureType.QueryString)
.build();
Token token = service.getAccessToken(ownerUsername, ownerSecret, grantType);
return token.getToken();
}
}
Here is complete stack trace:
10-19 10:39:05.042 25931-25931/? I/art: Not late-enabling -Xcheck:jni (already on)
10-19 10:39:05.042 25931-25931/? I/art: Late-enabling JIT
10-19 10:39:05.068 25931-25931/? I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
10-19 10:39:05.118 25931-25931/com.test.myproject W/System: ClassLoader referenced unknown path: /data/app/com.test.myproject-1/lib/x86
10-19 10:39:05.355 25931-25960/com.test.myproject D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
10-19 10:39:05.358 25931-25931/com.test.myproject D/: HostConnection::get() New Host Connection established 0xad974e50, tid 25931
10-19 10:39:05.366 25931-25931/com.test.myproject W/System.err: android.accounts.AuthenticatorException: bind failure
10-19 10:39:05.366 25931-25931/com.test.myproject W/System.err: at android.accounts.AccountManager.convertErrorToException(AccountManager.java:2147)
10-19 10:39:05.366 25931-25931/com.test.myproject W/System.err: at android.accounts.AccountManager.-wrap0(AccountManager.java)
10-19 10:39:05.366 25931-25931/com.test.myproject W/System.err: at android.accounts.AccountManager$AmsTask$Response.onError(AccountManager.java:1990)
10-19 10:39:05.366 25931-25931/com.test.myproject W/System.err: at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69)
10-19 10:39:05.366 25931-25931/com.test.myproject W/System.err: at android.os.Binder.execTransact(Binder.java:453)
10-19 10:39:05.423 25931-25960/com.test.myproject D/: HostConnection::get() New Host Connection established 0xac17e080, tid 25960
10-19 10:39:05.433 25931-25960/com.test.myproject I/OpenGLRenderer: Initialized EGL, version 1.4
10-19 10:39:05.538 25931-25960/com.test.myproject W/EGL_emulation: eglSurfaceAttrib not implemented
10-19 10:39:05.538 25931-25960/com.test.myproject W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaf125cc0, error=EGL_SUCCESS
10-19 10:39:05.903 25931-25931/com.test.myproject I/Choreographer: Skipped 31 frames! The application may be doing too much work on its main thread.
10-19 10:39:05.975 25931-25960/com.test.myproject W/EGL_emulation: eglSurfaceAttrib not implemented
10-19 10:39:05.975 25931-25960/com.test.myproject W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3fe0c40, error=EGL_SUCCESS
10-19 10:39:07.392 25931-25960/com.test.myproject E/Surface: getSlotFromBufferLocked: unknown buffer: 0xac027c50
Can someone help me with resolving this issue?

Ok, so, it was really a copy paste error, it made me crazy. In authenticator.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.test.myproject"
android:icon="#drawable/test_logo"
android:smallIcon="#drawable/test_logo"
android:label="#string/not_implemented"
android:accountPreferences="#xml/account_preferences"
/>
</PreferenceScreen>
</PreferenceScreen> is not supposed to be here.
If you are getting this error, check your xml files.

You can using addAccountExplicitly

I had the same issue too.
Just like Miljac's, my problem was about AndroidManifest.xml file.

Related

Usage of getApplicationContext on the sync adapter context

My app includes a sync adapter; it has been working fine for years, but recently I've received a very strange crash report:
Samsung Galaxy S6 Edge+ (zenlte), 4096MB RAM, Android 7.0
java.lang.ClassCastException:
1. at com.myappid.android.ScormApplication.getApplication (ScormApplication.java:34)
2. at com.myappid.android.sync.SyncAdapter.onPerformSync (SyncAdapter.java:98)
3. at android.content.AbstractThreadedSyncAdapter$SyncThread.run (AbstractThreadedSyncAdapter.java:272)
ScormApplication.java:
public class ScormApplication extends Application {
//...
public static ScormApplication getApplication(Context context) {
if (context instanceof ScormApplication) {
return (ScormApplication) context;
}
return (ScormApplication) context.getApplicationContext(); // this is a line 34
}
//...
}
SyncAdapter.java:
public class SyncAdapter extends AbstractThreadedSyncAdapter {
//...
#Override
public void onPerformSync(Account account,
Bundle extras,
String authority,
ContentProviderClient provider,
SyncResult syncResult) {
// sync code here...
ScormApplication.getApplication(getContext()).sendOttoEvent(ottoEvent); // this is a line 98
}
}
Thus, it means that the returned object from the method getApplicationContext called on SyncAdapter's context is not an instance of my application class. But how can it be possible?
Here is a bit more of my code:
AndroidManifest.xml (no separate process is declared) :
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
<application ...>
...
<service
android:name="com.myappid.android.sync.SyncService"
android:exported="true">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/syncadapter" />
</service>
...
SyncService.java:
public class SyncService extends Service {
private static SyncAdapter sSyncAdapter = null;
private static final Object sSyncAdapterLock = new Object();
#Override
public void onCreate() {
synchronized (sSyncAdapterLock) {
if (sSyncAdapter == null) {
sSyncAdapter = new SyncAdapter(getApplicationContext(), true);
}
}
}
#Override
public IBinder onBind(Intent intent) {
return sSyncAdapter.getSyncAdapterBinder();
}
}
#xml/syncadapter:
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="#string/content_authority"
android:accountType="#string/account_type"
android:userVisible="true"
android:supportsUploading="true"
android:allowParallelSyncs="false"
android:isAlwaysSyncable="true" />

Illegal argument exception: Failed to find configured root

I tried to share an image loaded into the imageview from glide following this guide, it gives me a illegal argument exception. I've posted the code and stacktrace below, it
MainAcitvity.xml
public class MainActivity extends AppCompatActivity {
private EditText editText;
private ShareActionProvider myShareActionProvider;
//private Bitmap bitmap;
private Uri uri;
private Intent shareIntent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView imageView = (ImageView) findViewById(R.id.imageView);
String hi = "http://37n98a43dqtb4bua9n28nidp.wpengine.netdna-cdn.com/wp-content/uploads/2016/09/MyFriendPikachu.jpg";
Glide
.with(this)
.load(hi)
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
prepareShareIntent(((GlideBitmapDrawable) resource).getBitmap());
attachShareIntentAction();
return false;
}
})
.placeholder(R.drawable.ic_action_name)
.error(R.drawable.ic_img_error)
.centerCrop()
.into(imageView);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.img_menu, menu);
MenuItem item = menu.findItem(R.id.action_share);
myShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
attachShareIntentAction();
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
return super.onOptionsItemSelected(item);
}
public void prepareShareIntent(Bitmap drawableImage) {
Uri bmpUri = getBitmapFromDrawable(drawableImage);
shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/*");
}
public void attachShareIntentAction() {
if (myShareActionProvider != null && shareIntent != null)
myShareActionProvider.setShareIntent(shareIntent);
}
public Uri getBitmapFromDrawable(Bitmap bmp) {
Uri bmpUri = null;
try {
//also tried getExternalDir(Environment.DIRECTORY_PICTURES)
File file = new File(Environment.getExternalStorageDirectory(), "images" + System.currentTimeMillis() + ".png");
FileOutputStream out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
bmpUri = FileProvider.getUriForFile(MainActivity.this, "com.example.imnobody.sampleprojectnetwork.fileprovider", file); // use this version for API >= 24
// **Note:** For API < 24, you may use bmpUri = Uri.fromFile(file);
} catch (IOException e) {
e.printStackTrace();
}
return bmpUri;
}
}
Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imnobody.sampleprojectnetwork">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.imnobody.sampleprojectnetwork.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/fileprovider" />
</provider>
</application>
</manifest>
fileprovider.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-file-path
name="images"
path="Pictures" />
</paths>
Stacktrace
java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/sdcard0/images1502651207040.png
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
at com.example.imnobody.sampleprojectnetwork.MainActivity.getBitmapFromDrawable(MainActivity.java:134)
at com.example.imnobody.sampleprojectnetwork.MainActivity.prepareShareIntent(MainActivity.java:95)
at com.example.imnobody.sampleprojectnetwork.MainActivity$1.onResourceReady(MainActivity.java:59)
at com.example.imnobody.sampleprojectnetwork.MainActivity$1.onResourceReady(MainActivity.java:51)
at com.bumptech.glide.request.GenericRequest.onResourceReady(GenericRequest.java:522)
at com.bumptech.glide.request.GenericRequest.onResourceReady(GenericRequest.java:507)
at com.bumptech.glide.load.engine.EngineJob.handleResultOnMainThread(EngineJob.java:158)
at com.bumptech.glide.load.engine.EngineJob.access$100(EngineJob.java:22)
at com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(EngineJob.java:202)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
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:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeS
First, in your metadata, change external-file-path to external-files-path, adding the missing s.
Second, /storage/sdcard0/images1502651207040.png will not match that repaired metadata. The metadata is expecting you to be using getExternalFilesDir(), and specifically a Pictures directory under there. Your path does not resemble that.
According to the documentation:
<external-path name="name" path="path" />
Represents files in the root
of the external storage area. The root path of this subdirectory is
the same as the value returned
byEnvironment.getExternalStorageDirectory().
You are calling a reference from your external storage root (/storage/sdcard0) but you need to reference your package root at /storage/sdcard0/Android/data/your.package.name/Pictures instead.

Android Handler Chain NullPointerException

I'm trying to create communication between Activity - Service - Thread by Handlers. Activity starts a Service that starts a Thread. Thread sends request to the server, waits answer and resend it to Service by Handler (work fine). But when i have try to send message from Service's Handler to Activity app closed with NullPointerException. What am i do wrong?
Handler code based on Android Handler changing WeakReference
My Activity
public class ActivityLogin extends Activity{
public static LoginHandler loginHandler = null;
public static class LoginHandler extends Handler {
private WeakReference<ActivityLogin> target = null;
LoginHandler(ActivityLogin target) {
this.target = new WeakReference<ActivityLogin>(target);
}
public void setTarget(ActivityLogin target) {
this.target.clear();
this.target = new WeakReference<ActivityLogin>(target);
}
#Override
public void handleMessage(Message msg) {
ActivityLogin activity = this.target.get();
if(activity == null) return;
String response = msg.getData().getString("RESPONSE");
System.err.println("RESPONSE "+response);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("TAG","---------------------APP STARTED---------------------");
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_login);
if(loginHandler == null) loginHandler = new LoginHandler(this);
else loginHandler.setTarget(this);
}
public void onLogin(View v){
JsonUser user = new JsonUser();
user.login = "Name";
user.password = "Pazzword";
user.device = "4567-753-5768-2343";
Intent intent = new Intent(this,ComService.class);
intent.putExtra("DATA_KEY", new Gson().toJson(user));
this.startService(intent);
}
}
My Service
public class ComService extends Service {
public static ServiceHandler serviceHandler = null;
public static class ServiceHandler extends Handler {
private WeakReference<ComService> target = null;
ServiceHandler(ComService target) {
this.target = new WeakReference<ComService>(target);
}
public void setTarget(ComService target) {
this.target.clear();
this.target = new WeakReference<ComService>(target);
}
#Override
public void handleMessage(Message msg) {
//ComService service = this.target.get();
//Process message (msg) and resend to activity
ActivityLogin.loginHandler.sendMessage(msg);
}
}
#Override
public void onCreate() {
super.onCreate();
if(serviceHandler == null) serviceHandler = new ServiceHandler(this);
else serviceHandler.setTarget(this);
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
String message = intent.getStringExtra("DATA_KEY");
new SendData("http://xxx.xxx.xxx.xxx:27019/WebService.svc/login",message);
stopSelf(startId);
return START_REDELIVER_INTENT;
}
}
My Thread
public class SendData extends Thread {
private String requestUrl;
private String message;
public SendData(String requestUrl, String message){
super();
this.requestUrl = requestUrl;
this.message = message;
this.start();
}
public void run(){
String serverResponse = request();
if(serverResponse == null) return;
System.err.println(serverResponse);
Message msg = new Message();
Bundle bundle = new Bundle();
bundle.putString("RESPONSE", serverResponse);
msg.setData(bundle);
ComService.serviceHandler.sendMessage(msg);
}
private String request(){...}//if need, i can post request code too
}
UPDATE
04-15 18:36:35.292 24524-24524/com.example.test E/Trace﹕ error opening trace file: No such file or directory (2)
04-15 18:36:35.332 24524-24524/com.example.test D/TAG﹕ ---------------------APP STARTED---------------------
04-15 18:36:35.462 24524-24524/com.example.test D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
04-15 18:36:35.462 24524-24524/com.example.test D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
04-15 18:36:35.462 24524-24524/com.example.test D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
04-15 18:36:35.492 24524-24524/com.example.test D/OpenGLRenderer﹕ Enabling debug mode 0
04-15 18:36:36.442 24554-24554/com.example.test:background E/Trace﹕ error opening trace file: No such file or directory (2)
04-15 18:36:36.682 24554-24567/com.example.test:background W/System.err﹕ {"status":{"success":false,"message":"some_text"},"result":null}
04-15 18:36:36.682 24554-24554/com.example.test:background D/AndroidRuntime﹕ Shutting down VM
04-15 18:36:36.682 24554-24554/com.example.test:background W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41712300)
04-15 18:36:36.682 24554-24554/com.example.test:background E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.test.ComService$ServiceHandler.handleMessage(ComService.java:31)
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)
AndroidManifext.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="14"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<activity android:name=".ActivityLogin"
android:label="#string/app_name"
android:windowSoftInputMode="stateHidden"
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name=".ComService"
android:exported="false"
android:process=":background"
/>
</application>
</manifest>
In conclusion, i deleted Service from my application. Android Service is cancer tumor, threads without benefits. It's just my opinion.

How to pass get text from userinput (edittext) and put into a textview in another activity?

I would like to take user input entered in the EditTextField(in the EnterNewFile class) and put it into the TextField (in the NoteEdit class). Please help! Thanks! FYI- I use XML files for the layouts of these two classes.
***********EnterNewFile.class*********
package com.example.note;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class EnterNewFile extends Activity {
public EditText mText;
public Button mButton;
public final static String EXTRA_MESSAGE = "com.example.note.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.new_file_start);
mText = (EditText)findViewById(R.id.file_name_edittext);
mButton = (Button)findViewById(R.id.next_button);
}
public void nextButton(View view)
{
/** Called when the user clicks the Next button */
Log.d("EditText", mText.getText().toString());
mText.getText().toString();
Intent intent = new Intent(this, NoteEdit.class);
EditText editText = (EditText) findViewById(R.id.file_name_edittext);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
//
}
}
******************************************
********NoteEdit.class************
package com.example.note;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class NoteEdit extends Activity{
public static int numTitle = 1;
public static String curDate = "";
public static String curText = "";
private TextView mTitleText;
private EditText mBodyText;
private TextView mDateText;
private Long mRowId;
private Cursor note;
private NotesDbAdapter mDbHelper;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbHelper = new NotesDbAdapter(this);
mDbHelper.open();
setContentView(R.layout.note_edit_add);
setTitle(R.string.app_name);
mTitleText = (TextView) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
mDateText = (TextView) findViewById(R.id.notelist_date);
long msTime = System.currentTimeMillis();
Date curDateTime = new Date(msTime);
SimpleDateFormat formatter = new SimpleDateFormat("M'/'d'/'y");
curDate = formatter.format(curDateTime);
mDateText.setText(""+curDate);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(EnterNewFile.EXTRA_MESSAGE);
// Create the text view
// TextView textView = new TextView(this);
mTitleText.setText(message);
// Set the text view as the activity layout
// setContentView(textView);
// mTitleText.setText(dana);
mRowId = (savedInstanceState == null) ? null :
(Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
: null;
}
populateFields();
}
public void addFiles(View view)
{
/*Intent addFilesTarget = new Intent(this, Welcome.class);
startActivity(addFilesTarget);*/
}
public static class LineEditText extends EditText{
// we need this constructor for LayoutInflater
public LineEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setColor(Color.BLUE);
}
private Rect mRect;
private Paint mPaint;
#Override
protected void onDraw(Canvas canvas) {
int height = getHeight();
int line_height = getLineHeight();
int count = height / line_height;
if (getLineCount() > count)
count = getLineCount();
Rect r = mRect;
Paint paint = mPaint;
int baseline = getLineBounds(0, r);
for (int i = 0; i < count; i++) {
canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
baseline += getLineHeight();
super.onDraw(canvas);
}
}
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
saveState();
outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId);
}
#Override
protected void onPause() {
super.onPause();
saveState();
}
#Override
protected void onResume() {
super.onResume();
populateFields();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.noteedit_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_about:
/* Here is the intro about myself */
AlertDialog.Builder dialog = new AlertDialog.Builder(NoteEdit.this);
dialog.setTitle("About");
dialog.setMessage("Hello! I'm Dana, creator of this application. This is for documenting research."
+"\n melaninabeauty#gmail.com");
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
dialog.show();
return true;
case R.id.menu_delete:
if(note != null){
note.close();
note = null;
}
if(mRowId != null){
mDbHelper.deleteNote(mRowId);
}
finish();
return true;
case R.id.menu_save:
saveState();
finish();
default:
return super.onOptionsItemSelected(item);
}
}
private void saveState() {
String title = mTitleText.getText().toString();
String body = mBodyText.getText().toString();
if(mRowId == null){
mDbHelper.createNote(title, body, curDate);
}else{
mDbHelper.updateNote(mRowId, title, body, curDate);
}
}
private void populateFields() {
if (mRowId != null) {
note = mDbHelper.fetchNote(mRowId);
startManagingCursor(note);
mTitleText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
curText = note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY));
}
}
}
***********************************
****AndroidManifest.xml****
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.note"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.note.Welcome"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.note.NoteList">
</activity>
<activity
android:name="com.example.note.NoteEdit">
</activity>
<activity
android:name="com.example.note.Export">
</activity>
<activity
android:name="com.example.note.NoteEditAdd">
</activity>
<activity
android:name="com.example.note.EnterNewFile">
</activity>
</application>
</manifest>
<!--
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.note"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name="com.example.note.Welcome">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.note.NoteList"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.note.NoteEdit"
android:label="#string/edit_note"
android:parentActivityName="com.example.note.Welcome" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.note.Welcome" />
</activity>
</application>
</manifest>
-->
<!--
activity 2 android:name= com.example.note.NoteEdit
android:label=#string/app_name
android:windowSoftInputMode="djustUnspecified/>
-->
*****************************
> *****LogCat of crash**** Crash occurs after nextButton is clicked****(I inputted the text "nouy", clicked nextButton, then application crashes.********************
LogCat of crash** Crash occurs after nextButton is clicked*(I inputted the text "nouy", clicked nextButton, then application crashees.**
08-02 20:48:36.703: D/EditText(3575): nouy
08-02 20:48:36.793: I/Choreographer(3575): Skipped 68 frames! The application may be doing too much work on its main thread.
08-02 20:48:37.143: D/dalvikvm(3575): GC_CONCURRENT freed 1331K, 34% free 2956K/4428K, paused 4ms+59ms, total 137ms
08-02 20:48:37.353: D/AndroidRuntime(3575): Shutting down VM
08-02 20:48:37.394: W/dalvikvm(3575): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
08-02 20:48:37.443: E/AndroidRuntime(3575): FATAL EXCEPTION: main
08-02 20:48:37.443: E/AndroidRuntime(3575): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.note/com.example.note.NoteEdit}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.os.Looper.loop(Looper.java:137)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-02 20:48:37.443: E/AndroidRuntime(3575): at java.lang.reflect.Method.invokeNative(Native Method)
08-02 20:48:37.443: E/AndroidRuntime(3575): at java.lang.reflect.Method.invoke(Method.java:511)
08-02 20:48:37.443: E/AndroidRuntime(3575): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-02 20:48:37.443: E/AndroidRuntime(3575): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-02 20:48:37.443: E/AndroidRuntime(3575): at dalvik.system.NativeStart.main(Native Method)
08-02 20:48:37.443: E/AndroidRuntime(3575): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
08-02 20:48:37.443: E/AndroidRuntime(3575): at com.example.note.NoteEdit.populateFields(NoteEdit.java:231)
08-02 20:48:37.443: E/AndroidRuntime(3575): at com.example.note.NoteEdit.onCreate(NoteEdit.java:99)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.app.Activity.performCreate(Activity.java:5104)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-02 20:48:37.443: E/AndroidRuntime(3575): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-02 20:48:37.443: E/AndroidRuntime(3575): ... 11 more
08-02 20:48:40.073: E/Trace(3598): error opening trace file: No such file or directory
(2)
Take the input from Edittext send it through the Intent to your destination activity and then set it in the TextView there.
I think you seem to already be doing that in your code:
The issue might be the you've not defined in your XML that nextButton function should be call on click ( inside android:onClick: inside your Button).
What you can also do is, in your onCreate funcion set up a listener which listens to the button click and call the intent from within it.
final EditText editText = (EditText) findViewById(R.id.file_name_edittext);
mButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
/** Called when the user clicks the Next button */
Log.d("EditText", mText.getText().toString());
Intent intent = new Intent(EnterNewFile.this, NoteEdit.class);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
});
//here you are taking value from EditText and send it to other activity:
Instead of
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(EnterNewFile.EXTRA_MESSAGE);
use following in onCreate() of your other NoteEdit activity:
Intent intent = getIntent();
if((intent.getExtras()!=null) && !intent.getExtras().isEmpty()){
String message = intent.getExtras().getString(EnterNewFile.EXTRA_MESSAGE);
}
this code is working:-
scrollview=(ScrollView)findViewById(R.id.scrollview1);
tb2.setTextSize(30);
tb2.setMovementMethod(new ScrollingMovementMethod());
scrollview.post(new Runnable() {
public void run() {
scrollview.fullScroll(View.FOCUS_DOWN);
}
});
chat1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
{
textsaring1=edt1.getText().toString();
tb2.setText(tb2.getText()+" "+textsaring1);
edt1.setText("");
}
}
});

Application code used to work but now crashes

Thing is my application used to run PERFECTLY but then i wanted to change packages names and classes names so i created another project and copy pasted my code and did the changes there. no error in eclipse but app crashes now !! here's whats my app is about:
public class LocationMobileUser implements LocationListener {
Context gContext;
boolean gps_enabled=false;
boolean network_enabled=false;
public LocationMobileUser(Context gContext){
this.gContext = gContext;
}
public static final String URL =
"http://www.ip2phrase.com/ip2phrase.asp?template=%20%3CISP%3E";
public void XML (View view) {
GetXMLTask task = new GetXMLTask();
task.execute(new String[] { URL });
}
public class GetXMLTask extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... urls) {
String output = null;
for (String url : urls) {
output = getOutputFromUrl(url);
}
return output;
}
public String getOutputFromUrl(String url) {
StringBuffer output = new StringBuffer("");
int x =1;
try {
InputStream stream = getHttpConnection(url);
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(stream));
String line = "";
int lineNo;
for (lineNo = 1; lineNo < 90; lineNo++) {
if (lineNo == x) {
line = lnr.readLine();
//output.append(line);
Pattern p = Pattern.compile(">(.*?)<");
Matcher m = p.matcher(line);
if (m.find()) {
output.append(m.group(1)); // => "isp"
}
} else
lnr.readLine();
}
} catch (IOException e1) {
e1.printStackTrace();
}
return output.toString();
}
// Makes HttpURLConnection and returns InputStream
public InputStream getHttpConnection(String urlString)
throws IOException {
InputStream stream = null;
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
try {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setRequestMethod("GET");
httpConnection.connect();
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
stream = httpConnection.getInputStream();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return stream;
}
}
public String getSimOperator() {
TelephonyManager telephonyManager = (TelephonyManager)gContext.getSystemService(Context.TELEPHONY_SERVICE);
String operator = telephonyManager.getSimOperatorName();
return operator;
}
public GsmCellLocation getCellLocation() {
//String Context=Context.Telephony_SERVICE;
TelephonyManager telephonyManager = (TelephonyManager)gContext.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation CellLocation = (GsmCellLocation)telephonyManager.getCellLocation();
return CellLocation;
}
public Location getLocation(){
String provider = null;
LocationManager locationManager;
Location gps_loc=null;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)gContext.getSystemService(context);
gps_loc=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
try{gps_enabled=locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);}catch(Exception ex){}
try{network_enabled=locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}catch(Exception ex){}
if(gps_enabled && gps_loc != null){
provider = LocationManager.GPS_PROVIDER;
}
else{
provider = LocationManager.NETWORK_PROVIDER;
}
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 20000, 1, this);
return location;
}
public String getProvider(Location location){
String provider = null;
LocationManager locationManager;
Location gps_loc=null;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)gContext.getSystemService(context);
gps_loc=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
try{gps_enabled=locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);}catch(Exception ex){}
try{network_enabled=locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}catch(Exception ex){}
if(gps_enabled && gps_loc != null ){
provider = LocationManager.GPS_PROVIDER;
}
else{
provider = LocationManager.NETWORK_PROVIDER;
}
return provider;
}
public String CellLacLocation(GsmCellLocation CellLocation){
String cidlacString;
if (CellLocation != null) {
int cid = CellLocation.getCid();
int lac = CellLocation.getLac();
cidlacString = "CellID:" + cid + "\nLAC:" + lac;}
else {
cidlacString="No Cell Location Available";
}
return cidlacString;
}
public String updateWithNewLocation(Location location) {
String latLongString;
if (location != null){
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Latitude:" + lat + "\nLongitude:" + lng;
}else{
latLongString = "No Location available";
}
return latLongString;
}
#Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
this app will be exported into a JAR file and then included into another app as a library using build path; and here's what i wrote in this new app:
public class LocationTheApp extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationMobileUser LMU = new LocationMobileUser (this);
Location location = LMU.getLocation();
GsmCellLocation CellLocation = LMU.getCellLocation();
String URL = LocationMobileUser.URL;
LocationMobileUser.GetXMLTask xmlp = LMU.new GetXMLTask();
String Provider = LMU.getProvider(location);
String isp = xmlp.getOutputFromUrl(URL);
String latLongString = LMU.updateWithNewLocation(location);
String cidlacString = LMU.CellLacLocation(CellLocation);
String operator = LMU.getSimOperator();
TextView myLocationText = (TextView)findViewById(R.id.myLocationText);
myLocationText.setText("Your current GPS position is:\n" + latLongString);
TextView myprovider = (TextView)findViewById(R.id.myprovider);
myprovider.setText("\nYour GPS position is provided by:\n" + Provider);
TextView myCellLocation = (TextView)findViewById(R.id.mycelllocation);
myCellLocation.setText("\nYour current Cell position is:\n" + cidlacString);
TextView myOperator = (TextView)findViewById(R.id.myoperator);
myOperator.setText("\nYour GSM operator is:\n" + operator);
TextView myispText = (TextView)findViewById(R.id.myispText);
myispText.setText("\nYour current ISP is:\n" + isp);
}
#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, menu);
return true;
}
}
Code contains no errors !!
if its any use here's my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.locationmobileuser"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.locationtheapp.LocationTheApp"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Tried to toggle the package name in the Manifest between locationmobileuser and locationtheapp but still app crashes !!
As i said used to work like a charm in my previous projects !!
LOG:
06-18 05:36:54.502: E/Trace(992): error opening trace file: No such file or directory (2)
06-18 05:36:54.852: D/dalvikvm(992): newInstance failed: no <init>()
06-18 05:36:54.862: D/AndroidRuntime(992): Shutting down VM
06-18 05:36:54.862: W/dalvikvm(992): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-18 05:36:55.002: E/AndroidRuntime(992): FATAL EXCEPTION: main
06-18 05:36:55.002: E/AndroidRuntime(992): java.lang.RuntimeException: Unable toinstantiate activity ComponentInfo{com.example.locationmobileuser/com.example.locationmobileuser.LocationMobileUser}: java.lang.InstantiationException: can't instantiate class com.example.locationmobileuser.LocationMobileUser; no empty constructor
06-18 05:36:55.002: E/AndroidRuntime(992): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
06-18 05:36:55.002: E/AndroidRuntime(992): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-18 05:36:55.002: E/AndroidRuntime(992): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-18 05:36:55.002: E/AndroidRuntime(992): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-18 05:36:55.002: E/AndroidRuntime(992): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 05:36:55.002: E/AndroidRuntime(992): at android.os.Looper.loop(Looper.java:137)
06-18 05:36:55.002: E/AndroidRuntime(992): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-18 05:36:55.002: E/AndroidRuntime(992): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 05:36:55.002: E/AndroidRuntime(992): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 05:36:55.002: E/AndroidRuntime(992): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-18 05:36:55.002: E/AndroidRuntime(992): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-18 05:36:55.002: E/AndroidRuntime(992): at dalvik.system.NativeStart.main(Native Method)
06-18 05:36:55.002: E/AndroidRuntime(992): Caused by: java.lang.InstantiationException: can't instantiate class com.example.locationmobileuser.LocationMobileUser; no empty constructor
06-18 05:36:55.002: E/AndroidRuntime(992): at java.lang.Class.newInstanceImpl(Native Method)
06-18 05:36:55.002: E/AndroidRuntime(992): at java.lang.Class.newInstance(Class.java:1319)
06-18 05:36:55.002: E/AndroidRuntime(992): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
06-18 05:36:55.002: E/AndroidRuntime(992): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
06-18 05:36:55.002: E/AndroidRuntime(992): ... 11 more
Any help would be really appreciated !!
see the package name of menifest
package="com.example.locationmobileuser
and activity package name both should be same change this package
<activity
android:name="com.example.locationtheapp.LocationTheApp"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
you need to add empty constructor in your locationmobileuser class.
public LocationMobileUser(){
}
don't need to do all these things , just go to old project and right click on the project ->> refactor to rename project name or package name

Categories