For my project all my java classes are in one package - com.example.android.bitmapfun - and my manifest is:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.bitmapfun"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:description="#string/app_description"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.example.android.bitmapfun.ImageGridActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.android.bitmapfun.ImageDetailActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.FullScreen" >
</activity>
</application>
</manifest>
and the Activities are:
package com.example.android.bitmapfun;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
public class ImageGridActivity extends FragmentActivity {
private static final String TAG = "ImageGridFragment";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getSupportFragmentManager().findFragmentByTag(TAG) == null) {
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(android.R.id.content, new ImageGridFragment(), TAG);
ft.commit();
}
}
}
ImageDeatilActivity.java:
package com.example.android.bitmapfun;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager.LayoutParams;
import android.widget.Toast;
import com.example.android.bitmapfun.R;
import com.example.android.bitmapfun.Images;
import com.example.android.bitmapfun.DiskLruCache;
import com.example.android.bitmapfun.ImageCache;
import com.example.android.bitmapfun.ImageFetcher;
import com.example.android.bitmapfun.ImageResizer;
import com.example.android.bitmapfun.ImageWorker;
import com.example.android.bitmapfun.Utils;
public class ImageDetailActivity extends FragmentActivity implements OnClickListener {
private static final String IMAGE_CACHE_DIR = "images";
public static final String EXTRA_IMAGE = "extra_image";
private ImagePagerAdapter mAdapter;
private ImageResizer mImageWorker;
private ViewPager mPager;
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_detail_pager);
.....
}
LogCat: here
Why is the LogCat showing the ClassNotFoundException here? I tried but can't clear the error. Please any ideas to overcome this problem.
To use this FragMentActivity class, your application must specify API Level "11" or higher in its manifest and be compiled against a version of the Android library that supports an equal or higher API Level.
For what it is worth, I couldn't get any of the solutions to work when I imported the BitmapFun project into Eclipse. It was because of the ClassNotFoundException. I did notice that the project was missing the libs folder and the support library, but creating the libs folder and dropping the support library into it did not fix the problem. So, I created a new project in Eclipse, transferred the files over from the original imported project, and it worked on the first try. Victory.
Related
my app force closes I do not know why. All it should do is vibrating when it is in the foreground and stop if it is not but when I start it on my phone it force closes. I added lines about vibrator usage into the manifest by hand. Maybe this is the problem. I have to anything else with it to be valid for the app?
My manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kevinboonemidi"
android:versionCode="1"
android:versionName="1.0" >
<permission android:name="android.permission.VIBRATE" ></permission>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.haptic.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>
</application>
My code:
package com.example.haptic_sof;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import com.example.kevinboonemidi.R;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Vibrator;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
public class MainActivity extends Activity
{
protected Vibrator v = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
long pwmCycles[];
pwmCycles = new long[4];
v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = { 0, 200, 10 };
v.vibrate(pattern, 0);
}
#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;
}
protected void onPause(){
super.onPause();
v.cancel();
}
protected void onStop()
{
super.onStop();
v.cancel();
}
}
Your packages are a mess.
You define com.example.kevinboonemidi as your package in the manifest, declare your Activity to be in com.example.haptic and actually put your Activity in com.example.haptic_sof.
Change android:name="com.example.haptic.MainActivity" to android:name="com.example.haptic_sof.MainActivity" and your app should run, though you may need to end up using one package entirely at least to start with.
I'm still having problems with the Method AccountManager.addAccountExplicitly.
I want to create a App which is submitting a User PW combo to a website.
The app should save the login data and therefore i wanted to use AccountManager:
HttpAuth.java:
package com.geberit.eismi.httpauth;
import android.os.Bundle;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.HttpAuthHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.Button;
public class HttpAuth extends Activity {
private EditText field_username;
private EditText field_password;
private Button btn_login;
private AccountManager accountM;
private Account eismi;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
accountM = AccountManager.get(this);
eismi = new Account("eismi", "com.geberit.sap.t81");
boolean test = accountM.addAccountExplicitly(eismi, "testpassword", null);
field_username = (EditText) findViewById(R.id.field_user);
field_password = (EditText) findViewById(R.id.field_password);
btn_login = (Button) findViewById(R.id.btn_login);
field_username.setText(accountM.getPassword(eismi));
HttpAuth Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.geberit.eismi.httpauth"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="com.geberit.eismi"
>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.geberit.eismi.httpauth.HttpAuth"
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>
</manifest>
Everytime when executing the step
boolean test = accountM.addAccountExplicitly(eismi, "testpassword", null);
my app is stopping!!
some output of the console:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.geberit.eismi.httpauth/com.geberit.eismi.httpauth.HttpAuth}: java.lang.SecurityException: caller uid 10039 is different than the authenticator's uid
I hope you can help me
Thanks Michi
Here is my PlayerActivity:
package player.org;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.app.Activity;
import android.os.Bundle;
public class PlayerActivity extends Activity {
/** Called when the activity is first created. */
private MediaView media=new MediaView(this);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(media);
}
}
here is my MediaView:
package player.org;
import android.app.Activity;
import android.view.*;
import android.widget.ImageView;
import android.content.*;
import android.content.*;
import android.graphics.Color;
class MediaView extends View
{
public MediaView(Context context)
{
super(context);
setBackgroundColor(Color.WHITE);
}
}
and here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="player.org"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity
android:name=".MediaView"
android:label="#string/MediaView_title">
</activity>
<activity android:name=".PlayerActivity"
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>
</manifest>
But when I Launch the app., It force closes.
Do you have any suggestions?
Thanks for your answers
You are writing this line private MediaView media=new MediaView(this);,before the Activity is initiated.So 'this' keyword is force closing your application
Please use like this
public class PlayerActivity extends Activity {
/** Called when the activity is first created. */
private MediaView media;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(media);
media=new MediaView(this);
}
}
I am creating an app for NFC where my first objective is to get the tag uid from the mifare tag.
When i press the tag button my activvity goes to second activity where i should be getting the tagID.
I am getting error of resource lookup. I know i am doing some major mistakes but could not find it.
Request you to please help.
This is my Meanifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.chetan.nfc"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10"></uses-sdk>
<uses-feature android:required="true" android:name="android.hardware.nfc"></uses-feature>
<uses-permission android:name="android.permission.NFC"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true" android:enabled="true">
<activity android:name=".actOne"
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="taginfo" android:label="#string/app_name" android:launchMode="standard">
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data android:resource="#xml/nfc_tech_filter" android:name="#string/nfc_tech_filter"></meta-data>
</activity>
</application>
</manifest>
This is my activity one:
package com.chetan.nfc;
import java.util.Date;
import android.app.Activity;
import android.app.LauncherActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.nfc.NfcAdapter;
import android.nfc.tech.NdefFormatable;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class actOne extends Activity {
/** Called when the activity is first created. */
Button tag;
Intent i;
TextView tv;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tag=(Button)findViewById(R.id.Tag);
tv=(TextView)findViewById(R.id.textView1);
tag.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
i=new Intent(v.getContext(),taginfo.class);
startActivity(i);
//launchActivity();
}
});
}
}
This is my Activity 2
package com.chetan.nfc;
import java.io.IOException;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.MifareClassic;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
public class taginfo extends Activity{
TextView tv;
EditText tagIntent;
Log log;
IntentFilter mFilters[];
String mTechLists[][];
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.tagdata);
tagIntent=(EditText)findViewById(R.id.editText1);
tv=(TextView)findViewById(R.id.textView1);
tv.setText(getIntent().toString());
log.e("before get intetn", "");
readTag(getIntent());
}
public void readTag(Intent intent)
{
//tagIntent.setText(intent.getAction());
PendingIntent mPendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
NfcAdapter nfc_adapter=NfcAdapter.getDefaultAdapter(this);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
Tag myTag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
tagIntent.setText("");
tagIntent.setText(tagId.toString());
}
}
If the error is about "I am getting error of resource lookup", is not NFC related.
With this code you're getting the UID of the Tag correctly
.
.
.
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Log.d(TAG, "UID: " + bin2hex(tag.getId()));
.
.
.
//To display the UID
static String bin2hex(byte[] data) {
return String.format("%0" + (data.length * 2) + "X", new BigInteger(1,data));
}
If you are simulating a tag detection from your activity 1, then add the appropriate extras. Else let the android nfc service generate the intent for TECH_DISCOVERED, when it detects the actual tag.
here
I uploaded my Android project made in Eclipse. The idea is that i have a service, which computes the sum of two random numbers. But when i press the OK Button, i don't see the result in that edit box... why? What i'm doing wrong? Please help
Thanks!
EDIT: The code:
//service class
package service;
import java.util.Random;
import com.android.AplicatieSuma;
import android.widget.EditText;
import android.widget.TextView;
public class ServiciuSuma
{
public ServiciuSuma() { }
public int CalculateSum()
{
Random generator=new Random();
int n=generator.nextInt();
int m=generator.nextInt();
return n+m;
}
}
The Application class:
package com.android;
import android.app.*;
import service.*;
public class ApplicationSum extends Application {
public ServiciuSuma service = new ServiciuSuma();
}
and the main Activity class:
package com.android;
import com.android.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class Activitate extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View btn_ok = findViewById(R.id.btn_ok);
btn_ok.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
CalculeazaSuma();
}
});
}
private void CalculeazaSuma()
{
AplicatieSuma appState = ((AplicatieSuma)this.getApplication());
EditText txt_amount = (EditText)findViewById(R.id.txt_amount);
txt_amount.setText(appState.service.CalculateSum());
//BindData();
}
}
So that edit text does not show the sum of the random generated numbers, by the service. What's wrong?
Thanks
EDIT:
the manifest xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android"
android:versionCode="1"
android:versionName="1.0.1">
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true" />
<application android:name="ApplicationSum" android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true">
<activity android:label="#string/app_name" android:name=".Activitate">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" />
</manifest>
This fix will work:
txt_amount.setText(String.valueOf(appState.service.CalculateSum()));
Without that you pass integer and android thinks it's an id of a resource to display. You should really use DDMS to identify such problems.
Have you specified in manifest that you want ApplicationSum to be used as application class?
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:name="com.android.ApplicationSum">
...
</application>
</manifest>
Does this work?
public String CalculateSum()
{
Random generator=new Random();
int n=generator.nextInt();
int m=generator.nextInt();
String sum = Integer.toString(n+m) ;
Log.v("CalculateSum", "N+M = " + sum);
return sum;
}