开发者

android null pointer exception [closed]

开发者 https://www.devze.com 2023-03-26 17:11 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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}
0

精彩评论

暂无评论...
验证码 换一张
取 消