imageview fadeineffect not working - android

I've been practicing some animation on Android but I could not get my code to work. the application fails at launch. Here is my main class + fade in class,
can you help me find out the problem?
package send.Shift;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
public class ShiftsActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView Arrow = (ImageView) findViewById(R.drawable.arrow);
Animation fadeInAnimation = AnimationUtils.loadAnimation(this,
R.anim.fade_in);
// Now Set your animation
Arrow.startAnimation(fadeInAnimation);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500" />
logcat:
12-16 03:40:23.863: D/AndroidRuntime(707): Shutting down VM
12-16 03:40:23.863: W/dalvikvm(707): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-16 03:40:23.873: E/AndroidRuntime(707): FATAL EXCEPTION: main
12-16 03:40:23.873: E/AndroidRuntime(707): java.lang.RuntimeException: Unable to start activity ComponentInfo{send.Shift/send.Shift.ShiftsActivity}: java.lang.NullPointerException
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:99)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:123)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-16 03:40:23.873: E/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 03:40:23.873: E/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:507)
12-16 03:40:23.873: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-16 03:40:23.873: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-16 03:40:23.873: E/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method)
12-16 03:40:23.873: E/AndroidRuntime(707): Caused by: java.lang.NullPointerException
12-16 03:40:23.873: E/AndroidRuntime(707): at send.Shift.ShiftsActivity.onCreate(ShiftsActivity.java:21)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-16 03:40:23.873: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-16 03:40:23.873: E/AndroidRuntime(707): ... 11 more

R.drawable.arrow cannot be an id of an imageview. That's a drawable, as in some picture you saved (png, or jpg) in your drawable folder. What you need is something like R.id.my_image_view

Try like this,
ImageView imageView= (ImageView)findViewById(R.id.imageView);
Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.your_fade_in_anim);
//Now Set your animation
imageView.startAnimation(fadeInAnimation );

Related

AndroidRunTime error, application has stopped unexpectedly

07-10 08:32:43.863: E/AndroidRuntime(718): FATAL EXCEPTION: main
07-10 08:32:43.863: E/AndroidRuntime(718): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.burp/com.example.burp.MainActivity}: java.lang.ClassNotFoundException: com.example.burp.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.burp-2.apk]
07-10 08:32:43.863: E/AndroidRuntime(718): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
07-10 08:32:43.863: E/AndroidRuntime(718): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-10 08:32:43.863: E/AndroidRuntime(718): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-10 08:32:43.863: E/AndroidRuntime(718): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-10 08:32:43.863: E/AndroidRuntime(718): at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 08:32:43.863: E/AndroidRuntime(718): at android.os.Looper.loop(Looper.java:123)
07-10 08:32:43.863: E/AndroidRuntime(718): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-10 08:32:43.863: E/AndroidRuntime(718): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 08:32:43.863: E/AndroidRuntime(718): at java.lang.reflect.Method.invoke(Method.java:507)
07-10 08:32:43.863: E/AndroidRuntime(718): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-10 08:32:43.863: E/AndroidRuntime(718): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-10 08:32:43.863: E/AndroidRuntime(718): at dalvik.system.NativeStart.main(Native Method)
07-10 08:32:43.863: E/AndroidRuntime(718): Caused by: java.lang.ClassNotFoundException: com.example.burp.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.burp-2.apk]
07-10 08:32:43.863: E/AndroidRuntime(718): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
07-10 08:32:43.863: E/AndroidRuntime(718): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
07-10 08:32:43.863: E/AndroidRuntime(718): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-10 08:32:43.863: E/AndroidRuntime(718): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-10 08:32:43.863: E/AndroidRuntime(718): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
07-10 08:32:43.863: E/AndroidRuntime(718): ... 11 more
how do I solve this problem? I am using Windows 7
Include your Activity in Manifest file. Like this
<activity
android:name=".application's starting activity" <!-- (.)dot means current dir, if your activity is in another package then give full package name ex: com.xxx.Activity -->
android:label="LABEL FOR ACTIVITY "
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

My app freezes crashes when it's supposed to go to the next activity

I don't know why the app crashes whenever it's supposed to go to the next Activity. I made a practice app that works as it should when using the same format. I uploaded the files to gist.github.
The error is
1216-1216/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ArrayIndexOutOfBoundsException
at com.example.chiozokamalu.newfreshstart.MainActivity.onClick(MainActivity.java:164)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
On line 164 of MainActivity.java:
questionView.setText(questions[questionIndex]); // set the text to the next question
EDIT: After Varun helped me, I get a new error which is
1307-1307/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chiozokamalu.newfreshstart/com.example.chiozokamalu.newfreshstart.Results1}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.chiozokamalu.newfreshstart.Results1.onCreate(Results1.java:58)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3683)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
            at dalvik.system.NativeStart.main(Native Method)
The questions array at line no. 164 is going out of bound that means questionIndex is greater than the total length of the questions array. So you should add a check on the length before extracting value from the array.
You have added the check but after that you incremented the value so either you modify the if condition to if (questionIndex < questions.length -1)
or modify the questionIndex variable before the if condition
You are getting problem because you haven't initiated resultView9 that is why it is null and giving nullpointer, just initiatlise it as you done with other and everything is fine. You have initialised the resultView8 twice just add resultview9 over there

NoClassDefFoundError: AdWhirlLayout

i checked similar question on the forum, but couldn't get it to run.
Finally i removed everything not needed to focused on the error and i left with that chunk of code. But it's still crashing with a NoClassDefFoundError at the
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(TestActivity.this, key);
line.
I'am using AdWhirlSDK_Android_3.1.1 but tried as well the AdWhirlSDK_Android_3.0.0. I've got the same error.
Java Code.
import com.adwhirl.AdWhirlLayout;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.LinearLayout.LayoutParams;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setupAds();
}
private void setupAds() {
String key = "adwhirl_key";
int diWidth = 320;
int diHeight = 52;
float density = getResources().getDisplayMetrics().density;
LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
RelativeLayout.LayoutParams layoutParams =
new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(TestActivity.this, key);
adWhirlLayout.setMaxWidth((int) (diWidth * density));
adWhirlLayout.setMaxHeight((int) (diHeight * density));
layout.addView(adWhirlLayout, layoutParams);
layout.invalidate();
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<LinearLayout
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
LOGCAT:
04-11 17:59:50.451: E/AndroidRuntime(707): FATAL EXCEPTION: main
04-11 17:59:50.451: E/AndroidRuntime(707): java.lang.NoClassDefFoundError: com.adwhirl.AdWhirlLayout
04-11 17:59:50.451: E/AndroidRuntime(707): at com.testproject.TestActivity.setupAds(TestActivity.java:34)
04-11 17:59:50.451: E/AndroidRuntime(707): at com.testproject.TestActivity.onCreate(TestActivity.java:18)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:123)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-11 17:59:50.451: E/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 17:59:50.451: E/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:507)
04-11 17:59:50.451: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-11 17:59:50.451: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-11 17:59:50.451: E/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method)
Has anybody an idea and can tell my what i cant see.Please.
Best Regards
You should definitely check the link in your comments. Basically you need to handle all of your dependencies in android by putting the required libraries in a "libs" folder. Eclipse doesn't generate this automatically for you, so you have to make it yourself. Put the "libs" folder in the "res" folder (not bin/res, the res folder that shares the same directory as src).
Also make sure you have all the proper declarations in your manifest if you are launching other activities, need special permissions for those functions (uses-internet), etc.
Go to your project that uses .jar files (i.e. project under test). Click right button -> Properties-> Java Build Path -> Order and Export -> check libraries there. Check this link for the screenshot.

NullPointerException in com.reg.project

I have no Idea why I get this error :/
Exception class java.lang.NullPointerException
Source method Jax$7.onClick()
java.lang.NullPointerException
at com.reg.lolsoundboard.Jax$7.onClick(Jax.java:83)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9089)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Obviously you are dereferencing a variable in line 83 of the file Jax.java where the variable is null.
java.lang.NullPointerException
at com.reg.lolsoundboard.Jax$7.onClick(Jax.java:83)
If show the relevant code, people may be able to help you.

android null pointer exception [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I write a simple programm, but there is problem.
Here is the code:
package player.org;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
public class Player extends Activity {
/** Called when the activity is first created. */
private MediaPlayer media;
private ProgressBar progress;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
progress=(ProgressBar) findViewById(R.id.progress);
progress.setVisibility(ProgressBar.INVISIBLE);
And here is the tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#FFFFFF">
<ProgressBar
android:id="#+id/progress"
android:layout_width="250dp"
android:layout_height="8dp"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_x="35dp"
android:layout_y="320dp"/>
</AbsoluteLayout>
But when I run program, it's force closed because of Null pointer exception. Can anyone help?
Here is the LogCat:
08-07 08:24:02.516: ERROR/AndroidRuntime(334): FATAL EXCEPTION: main
08-07 08:24:02.516: ERROR/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{player.org/player.org.Player}: java.lang.NullPointerException
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.os.Looper.loop(Looper.java:123)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at java.lang.reflect.Method.invoke(Method.java:507)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at dalvik.system.NativeStart.main(Native Method)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): Caused by: java.lang.NullPointerException
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at player.org.Player.onCreate(Player.java:26)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-07 08:24:02.516: ERROR/AndroidRuntime(334): ... 11 more
08-07 08:24:02.536: WARN/ActivityManager(67): Force finishing activity player.org/.Player
08-07 08:24:03.056: WARN/ActivityManager(67): Activity pause timeout for HistoryRecord{4054b008 player.org/.Player}
08-07 08:24:03.167: INFO/ActivityManager(67): Displayed com.android.launcher/com.android.launcher2.Launcher: +37s552ms
08-07 08:24:13.233: WARN/ActivityManager(67): Activity destroy timeout for HistoryRecord{4054b008 player.org/.Player}

Categories

Resources