I have the following situation: I need to get xml file from the Internet and then get lyrics from this file. Here's the url of this xml. Here's the code, which I wrote and which should do it.
private static class NetworkLyricsDownload extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... voids) {
try {
URL url = new URL("http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=Eminem&song=Lose%20Yourself");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xmlPullParser = factory.newPullParser();
xmlPullParser.setInput(getInputStream(url), "UTF-8");
boolean insideItem = false;
int eventType = xmlPullParser.getEventType();
while (eventType!=XmlPullParser.END_DOCUMENT){
if (eventType == XmlPullParser.START_TAG){
if (xmlPullParser.getName().equalsIgnoreCase("lyric")){
insideItem = true;
Log.i(getClass().getName(), xmlPullParser.nextText());
}
}
eventType = xmlPullParser.next();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private InputStream getInputStream(URL url){
try {
return url.openConnection().getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
But when I run the app, I have the following error:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
Process: asus.example.com.player, PID: 14458
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.IllegalArgumentException: is == null
at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1636)
at asus.example.com.player.UploadLyricsActivity$NetworkLyricsDownload.doInBackground(UploadLyricsActivity.java:114)
at asus.example.com.player.UploadLyricsActivity$NetworkLyricsDownload.doInBackground(UploadLyricsActivity.java:86)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
I have permission in manifest file ( <uses-permission android:name="android.permission.INTERNET"/>
) but it still doesn't help. So, what's the matter and how can I solve it?
UPD
Here's my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="asus.example.com.player"
android:targetSandboxVersion="1">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<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"
android:networkSecurityConfig="#xml/network_security_config"
android:usesCleartextTraffic="true"
tools:ignore="AllowBackup,GoogleAppIndexingWarning,UnusedAttribute">
<activity android:name=".SongLyricsActivity"/>
<activity android:name=".UploadLyricsActivity" />
<activity
android:name=".ListOfSongsActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<service
android:name=".MyService"
android:enabled="true"
android:exported="true"
tools:ignore="ExportedService" />
</application>
</manifest>
Related
So i have a function which downloads and then installs the apk. When the intent launches I get "There was a problem parsing this package." error. However,if i try installing it manually it works fine.
DownloadActivity.java:
public void onClickUpdate(View view) throws IOException {
Toast.makeText(SettingsActivity.this, "Checking for updates", Toast.LENGTH_SHORT).show();
OkHttpClient client = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).writeTimeout(10,TimeUnit.SECONDS).readTimeout(10,TimeUnit.SECONDS).build();
final Request request=new Request.Builder().url("theurl").addHeader("version",version).get().build();
client.newCall(request).enqueue(new Callback() {
#Override
public void onFailure(#NotNull Call call, #NotNull IOException e) {
e.printStackTrace();
}
#Override
public void onResponse(#NotNull Call call, #NotNull Response response) throws IOException {
try {
File sdcard=new File("sdcard/Download");
File file=new File(sdcard,"app-debug.apk");
file.createNewFile();
BufferedSink sink=Okio.buffer(Okio.sink(file));
sink.writeAll(Objects.requireNonNull(response.body()).source());
sink.close();
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(SettingsActivity.this, "Installed successfully!", Toast.LENGTH_LONG).show();
try{
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri uri=Uri.parse("content://"+"sdcard/Download/app-debug.apk");
intent.setDataAndType(uri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);}catch (Exception e){
e.printStackTrace();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}finally {
response.close();
}
}
});
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.testapp.test">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="false"
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=".VersionActivity">
</activity>
<activity android:name=".SettingsActivity">
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Also I did try Android install apk programmatically error - Package Parse error but that did not help at all.
the logs:
2020-09-29 07:31:13.669 24595-29726/? E/ActivityThread: Failed to find provider info for sdcard
2020-09-29 07:31:13.671 24595-29726/? W/InstallStaging: Error staging apk from content URI
java.io.FileNotFoundException: No content provider: content://sdcard/Download/app-debug.apk
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1506)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1357)
at android.content.ContentResolver.openInputStream(ContentResolver.java:1071)
at com.android.packageinstaller.InstallStaging$StagingAsyncTask.doInBackground(InstallStaging.java:167)
at com.android.packageinstaller.InstallStaging$StagingAsyncTask.doInBackground(InstallStaging.java:161)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
I fixed it by adding this:
StrictMode.VmPolicy.Builder builder=new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure;
I don't recommend doing this.
Try wrapping your file URI with content:// instead.
App launches normally. When I try to minimize it and reopen through the recent apps history, again it works fine. But when I minimize and try to re open it with the app icon, it crashes.
MainActivity.java
public class MainActivity extends AppCompatActivity implements ResetPasswordDialog.Listener {
public static final String TAG = MainActivity.class.getSimpleName();
private LoginFragment mLoginFragment;
private ResetPasswordDialog mResetPasswordDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
loadFragment();
}
}
private void loadFragment(){
if (mLoginFragment == null) {
mLoginFragment = new LoginFragment();
}
getFragmentManager().beginTransaction().replace(R.id.fragmentFrame,mLoginFragment,LoginFragment.TAG).commit();
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String data = intent.getData().getLastPathSegment();
Log.d(TAG, "onNewIntent: "+data);
mResetPasswordDialog = (ResetPasswordDialog) getFragmentManager().findFragmentByTag(ResetPasswordDialog.TAG);
if (mResetPasswordDialog != null)
mResetPasswordDialog.setToken(data);
}
#Override
public void onPasswordReset(String message) {
showSnackBarMessage(message);
}
private void showSnackBarMessage(String message) {
Snackbar.make(findViewById(R.id.activity_main),message, Snackbar.LENGTH_SHORT).show();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<!--singleTask => flag of launchMode -->
<application
android:name="io.github.froger.xinger.InstaMaterialApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="io.github.froger.xinger.ui.activity.MainActivity"
android:launchMode="singleTop"
android:theme="#style/AppTheme.LoginRegister"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="learn2crack"
android:scheme="http" />
</intent-filter>
</activity>
<activity
android:name="io.github.froger.xinger.ui.activity.DashboardActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="io.github.froger.xinger.ui.activity.CommentsActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.TransparentActivity" />
<activity
android:name="io.github.froger.xinger.ui.activity.UserProfileActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.TransparentActivity"
android:launchMode="singleInstance" />
<activity
android:name="io.github.froger.xinger.ui.activity.TakePhotoActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.TransparentActivity" />
<activity
android:name="io.github.froger.xinger.ui.activity.PublishActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"
android:windowSoftInputMode="stateHidden">
</activity>
</application>
Error
04-01 00:51:26.015 25525-25525/io.github.froger.instamaterial D/AndroidRuntime: Shutting down VM
04-01 00:51:26.016 25525-25525/io.github.froger.instamaterial E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.github.froger.instamaterial, PID: 25525
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
at io.github.froger.xinger.ui.activity.MainActivity.onNewIntent(MainActivity.java:44)
at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1245)
at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1257)
at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2804)
at android.app.ActivityThread.performNewIntents(ActivityThread.java:2816)
at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2825)
at android.app.ActivityThread.-wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1552)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
The stack trace clearly indicates that the call to intent.getData() at line 44 of your MainActivity is returning a null. You should check for the null, and not try to interrogate the Intent if it is null.
You could store string data in a static variable, and then check to see if it's null. If it's null use the static data. I know static variables are frowned upon and you should address the root problem, but this will fix your immediate problem.
static String yourStaticString;
...
String data;
if (intent.getData()==NULL)
{
data = yourStaticString;
}
else
{
if (intent.getData().getLastPathSegment()!=NULL)
{
data = intent.getData().getLastPathSegment();
yourStaticString = data;
} else return;
}
I am using android studio 1.3, and libgdx 1.6.2 to create a game. I want to incorporate google play services to my game and I have completed everything in one step, because I did it before without problem. However, this time it gave me an exception:
java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
at com.google.android.gms.common.internal.zzi$zza.zzc(Unknown Source)
at com.google.android.gms.common.internal.zzi$zza.zzr(Unknown Source)
at com.google.android.gms.common.internal.zzi$zzc.zznQ(Unknown Source)
at com.google.android.gms.common.internal.zzi$zzb.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
So here is what I changed other than adding baseGameUtils (which was sucessfully added).
EDIT:
The Full Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bearfishapps.cells.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="com.example.app.android.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.purplebrain.adbuddiz.sdk.AdBuddizActivity"
android:theme="#android:style/Theme.Translucent" />
</application>
</manifest>
And here is my android main activity.
public class AndroidLauncher extends AndroidApplication implements GameHelper.GameHelperListener{
private GameHelper gameHelper;
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (gameHelper == null) {
gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
}
gameHelper.setup(this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new Cells(new ActionResolver() {
#Override
public boolean getSignedInGPGS() {
return gameHelper.isSignedIn();
}
#Override
public void loginGPGS() {
try {
runOnUiThread(new Runnable() {
public void run() {
gameHelper.beginUserInitiatedSignIn();
}
});
} catch (final Exception ex) {
}
}
#Override
public void submitScoreGPGS(int score) {
Games.Leaderboards.submitScore(gameHelper.getApiClient(), "CgkI6ZHYr9IEEAIQBg", score);
}
#Override
public void getLeaderboardGPGS() {
if (gameHelper.isSignedIn()) {
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), "CgkI6ZHYr9IEEAIQBg "), 100);
}
else if (!gameHelper.isConnecting()) {
loginGPGS();
}
}
#Override
public void unlockAchievementGPGS(String achievementId) {
Games.Achievements.unlock(gameHelper.getApiClient(), achievementId);
}
#Override
public void getAchievementsGPGS() {
if (gameHelper.isSignedIn()) {
startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), 101);
}
else if (!gameHelper.isConnecting()) {
loginGPGS();
}
}
}), config);
}
#Override
public void onStart(){
super.onStart();
gameHelper.onStart(this);
}
#Override
public void onStop(){
super.onStop();
gameHelper.onStop();
}
#Override
public void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
gameHelper.onActivityResult(request, response, data);
}
#Override
public void onSignInFailed() {
}
#Override
public void onSignInSucceeded() {
}
}
I can't tell whats wrong here.
Thanks in advance.
You need to use <meta-data> inside your <application> tag in the AndroidManifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bearfishapps.cells.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="com.example.app.android.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.purplebrain.adbuddiz.sdk.AdBuddizActivity"
android:theme="#android:style/Theme.Translucent" />
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
Clear your data and uninstall updates on Google Play Services.
Then, reinstall it.
java.lang.ClassCastException: android.app.Application cannot be cast to com.example.project.DataDevice
My code:
public class Project extends Activity{
private boolean connection = false;
public Tag tagFromIntent = null;
private Button textRead;
private NFCForegroundUtil nfcForegroundUtil;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.project);
nfcForegroundUtil = new NFCForegroundUtil(this);
this.textRead= (Button) findViewById(R.id.button2);
initListeners();
}
private void initListeners() {
textRead.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (connection == true)
{
DataDevice dataDevice = (DataDevice) getApplication();
dataDevice.setCurrentTag(tagFromIntent);
IsoDep nfca = IsoDep.get(dataDevice.getCurrentTag());
try
{
byte[] read= new byte[] { 0x00};
byte[] ans = null;
nfca.setTimeout(2000);
nfca.connect();
nfca.setTimeout(2000);
if (nfca.isConnected())
{
nfca.setTimeout(2000);
ans = nfca.transceive(read);
try
{
Thread.sleep(1500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
nfca.close();
String textRead = HexBin.encode(ans);
}
catch (IOException e)
{
Log.i("A", "IOException is: " + e.getMessage());
e.printStackTrace();
}
if (nfca.isConnected())
{
try
{
nfca.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
});
}
#Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
action = intent.getAction();
tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
connection = true;
}
public void onPause()
{
super.onPause();
nfcForegroundUtil.disableForeground();
}
public void onResume()
{
super.onResume();
nfcForegroundUtil.enableForeground();
if (!nfcForegroundUtil.getNfc().isEnabled())
{
Toast.makeText(
getApplicationContext(),
"Please activate NFC and press Back to return to the application!",
Toast.LENGTH_LONG).show();
startActivity(new Intent(
android.provider.Settings.ACTION_WIRELESS_SETTINGS));
}
}
}
My manifest code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="android.app.Application">
<activity
android:name=".StartActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name=".Project"
android:label="#string/title_activity_main" />
</application>
My error:
FATAL EXCEPTION: main
java.lang.ClassCastException: android.app.Application cannot be cast to com.example.Project.DataDevice
at com.example.project.Project$1.onClick(Project.java:67)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14105)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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)
DataDevice class:
public class DataDevice extends Application
{
private Tag currentTag;
public void setCurrentTag(Tag currentTag) {
this.currentTag = currentTag;
}
public Tag getCurrentTag() {
return currentTag;
}
//(...)
}
I looked for answer on stackOverflow, nothing helped.
Anyone knows what's going on?
DataDevice and NFCUtilForeground works good (in other applications).
The android:name attribute in application tag in your manifest file should point to your DataDevice class. Like:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="your.package.DataDevice">
.........
..........
</application>
In my Android app I'll get the source of a html page. That's my Code: http://pastebin.com/FJyWhVrL It shows me every time by getHtml(); an Unhandled exception type IOException and Unhandled exception type ClientProtocolException. In the manifest file I've set the permission it looks like this:
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".DownloadsActivity"
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>
Can someone help me?
Thank you
Those are compile errors. You are calling getHtml, which can throw these two exceptions.
So you need to catch them in your code and do something about it.
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
getHtml();
}
catch (IOException e){
// do something
}
catch (ClientProtocolException e){
// do something
}
}
});