0

アプリケーションで通知を使用してリモートビューを使用しようとしていますが、アプリケーションを実行すると、E/AndroidRuntime(11337): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.jeema.HWDTest/net.jeema.HWDTest.HWDTestActivity}: java.lang.NullPointerExceptionなぜそれが起こっているのかわかりません.Androidの初心者です.助けてください.ここでランタイム例外が発生する理由のヒントを得ることができません.

私のコード:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
        final RemoteViews contentView = new RemoteViews(getPackageName(),
                R.layout.upload_progress_bar);
        contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS,
                mProgressStatus, false);
        notification=new Notification();
        notification.contentView = contentView;

        // Start file upload in a background thread
        new Thread(new Runnable() {
            public void run() {
                while (mProgressStatus < MAX_PROGRESS) {
                    mProgressStatus = doWork();

                    // Update the progress bar
                    mHandler.post(new Runnable() {
                        public void run() {
                            contentView.setProgressBar(R.id.progress_bar,
                                    MAX_PROGRESS, mProgressStatus, false);
                        }
                    });
                }
            }

            private int doWork() {
                HttpURLConnection conn = null;
                DataOutputStream dos = null;
                DataInputStream inStream = null;
                String lineEnd = "\r\n";
                String twoHyphens = "--";
                String boundary = "*****";
                int bytesRead;
                byte[] buffer;
                String urlString = "http://xxxxx/xxxx/xxx.php";
                try {
                    UUID uniqueKey = UUID.randomUUID();
                    fname = uniqueKey.toString();
                    Log.e("UNIQUE NAME", fname);
                    FileInputStream fileInputStream = new FileInputStream(
                            new File(selectedPath));
                    URL url = new URL(urlString);
                    conn = (HttpURLConnection) url.openConnection();
                    int length = fileInputStream.available();
                    System.out.println("Video Length--->>>>" + length);
                    conn.setDoInput(true);
                    conn.setDoOutput(true);
                    conn.setUseCaches(false);
                    conn.setRequestMethod("POST");
                    conn.setRequestProperty("Connection", "Keep-Alive");
                    conn.setRequestProperty("Content-Type",
                            "multipart/form-data;boundary=" + boundary);
                    dos = new DataOutputStream(conn.getOutputStream());
                    dos.writeBytes(twoHyphens + boundary + lineEnd);
                    dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\""
                            + fname + "" + lineEnd);
                    dos.writeBytes(lineEnd);
                    buffer = new byte[8192];
                    bytesRead = 0;
                    while ((bytesRead = fileInputStream.read(buffer)) > 0) {
                        dos.write(buffer, 0, bytesRead);
                    }
                    dos.writeBytes(lineEnd);
                    dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
                    Log.e("Debug", "File is written");
                    fileInputStream.close();
                    dos.flush();
                    dos.close();

                } catch (MalformedURLException ex) {
                    Log.e("Debug", "error: " + ex.getMessage(), ex);
                } catch (IOException ioe) {
                    Log.e("Debug", "error: " + ioe.getMessage(), ioe);
                }
                // ------------------ read the SERVER RESPONSE
                try {
                    inStream = new DataInputStream(conn.getInputStream());
                    String str;
                    while ((str = inStream.readLine()) != null) {
                        Log.e("Debug", "Server Response " + str);
                    }
                    inStream.close();

                } catch (IOException ioex) {
                    Log.e("Debug", "error: " + ioex.getMessage(), ioex);
                }
                return 0;
            }
        }).start();
    }

私のlogcat:

08-26 14:15:49.542: E/AndroidRuntime(12359): FATAL EXCEPTION: main
08-26 14:15:49.542: E/AndroidRuntime(12359): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.jeema.HWDTest/net.jeema.HWDTest.HWDTestActivity}: java.lang.NullPointerException
08-26 14:15:49.542: E/AndroidRuntime(12359):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at android.os.Looper.loop(Looper.java:123)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at android.app.ActivityThread.main(ActivityThread.java:3683)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at java.lang.reflect.Method.invokeNative(Native Method)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at java.lang.reflect.Method.invoke(Method.java:507)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at dalvik.system.NativeStart.main(Native Method)
08-26 14:15:49.542: E/AndroidRuntime(12359): Caused by: java.lang.NullPointerException
08-26 14:15:49.542: E/AndroidRuntime(12359):    at net.jeema.HWDTest.HWDTestActivity.onCreate(HWDTestActivity.java:36)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-26 14:15:49.542: E/AndroidRuntime(12359):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-26 14:15:49.542: E/AndroidRuntime(12359):    ... 11 more

私のmanifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.jeema.HWDTest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".HWDTestActivity"
            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>
4

1 に答える 1

0

作成する前に通知を使用しています...次の方法で試してください:

notification=new Notification();
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
于 2012-08-26T08:55:28.513 に答える