2012-08-26 8 views
0

Iam пытается использовать remoteviews с уведомлением в моем приложении. Но когда я запустил мое приложение, я получил E/AndroidRuntime(11337): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.jeema.HWDTest/net.jeema.HWDTest.HWDTestActivity}: java.lang.NullPointerException. Не знаю, почему это происходит. Возможно, новое для android.Пожалуйста, помогите мне. iam получает исключение во время выполнения.Невозможно запустить мое приложение

Мой код:

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> 
+0

Опубликовать полную трассировку LogCat. –

+0

@RaghavSood Я разместил свой logcat.U теперь может видеть это – Manikandan

+0

и манифест Android ... –

ответ

0

вы используете уведомление, прежде чем создать его ... попробовать таким образом:

notification=new Notification(); 
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT; 
+0

yes.Thank u.I очистил эти строки. – Manikandan

+0

проблема решена? –

+0

Будет проверять и позволять вам знать. Не знаю, как это будет работать. Можете ли я проверить свой код полностью? – Manikandan

Смежные вопросы