AndroidMoron
AndroidMoron

Reputation: 35

android - Error running simple wall paper application

Im very new to android programming. Im trying to learn android by creating a simple app that will set wall paper background. I admit there are lots of basic concepts in android development that I still don't know and understand so please be kind to me.

Im using Android SDK 4.1, Eclipse Indigo.

I set my AVD specs:

CPU/ABI: ARM (armeabi-v7a)
Target: Android 4.1 (API level 16)
Skin: WVGA800 
SD Card: 512

I am having an error everytime I run the application.

The error:


08-11 14:11:51.733: E/Trace(696): error opening trace file: No such file or directory (2)
08-11 14:11:52.383: D/dalvikvm(696): GC_FOR_ALLOC freed 44K, 3% free 8054K/8259K, paused 44ms, total 45ms
08-11 14:11:52.443: I/dalvikvm-heap(696): Grow heap (frag case) to 14.643MB for 7056016-byte allocation
08-11 14:11:52.534: D/dalvikvm(696): GC_CONCURRENT freed 1K, 2% free 14943K/15175K, paused 25ms+5ms, total 85ms
08-11 14:11:53.093: D/dalvikvm(696): GC_FOR_ALLOC freed (ImageView.java:120)
08-11 14:11:53.724: I/dalvikvm(696):   at android.widget.ImageView.(ImageView.java:110)
08-11 14:11:53.724: I/dalvikvm(696):   at java.lang.reflect.Constructor.constructNative(Native Method)
08-11 14:11:53.724: I/dalvikvm(696):   at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-11 14:11:53.763: I/dalvikvm(696):   at android.view.LayoutInflater.createView(LayoutInflater.java:587)
08-11 14:11:53.763: I/dalvikvm(696):   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-11 14:11:53.763: I/dalvikvm(696):   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
08-11 14:11:53.763: I/dalvikvm(696):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-11 14:11:53.763: I/dalvikvm(696):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
08-11 14:11:53.763: I/dalvikvm(696):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
08-11 14:11:53.763: I/dalvikvm(696):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
08-11 14:11:53.763: I/dalvikvm(696):   at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-11 14:11:53.763: I/dalvikvm(696):   at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-11 14:11:53.763: I/dalvikvm(696):   at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-11 14:11:53.763: I/dalvikvm(696):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
08-11 14:11:53.763: I/dalvikvm(696):   at android.app.Activity.setContentView(Activity.java:1867)
08-11 14:11:53.763: I/dalvikvm(696):   at com.example.androidwallpaper.MainActivity.onCreate(MainActivity.java:12)
08-11 14:11:53.773: I/dalvikvm(696):   at android.app.Activity.performCreate(Activity.java:5008)
08-11 14:11:53.773: I/dalvikvm(696):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-11 14:11:53.773: I/dalvikvm(696):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-11 14:11:53.773: I/dalvikvm(696):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-11 14:11:53.773: I/dalvikvm(696):   at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-11 14:11:53.773: I/dalvikvm(696):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-11 14:11:53.773: I/dalvikvm(696):   at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 14:11:53.773: I/dalvikvm(696):   at android.os.Looper.loop(Looper.java:137)
08-11 14:11:53.773: I/dalvikvm(696):   at android.app.ActivityThread.main(ActivityThread.java:4745)
08-11 14:11:53.773: I/dalvikvm(696):   at java.lang.reflect.Method.invokeNative(Native Method)
08-11 14:11:53.773: I/dalvikvm(696):   at java.lang.reflect.Method.invoke(Method.java:511)
08-11 14:11:53.773: I/dalvikvm(696):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-11 14:11:53.773: I/dalvikvm(696):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-11 14:11:53.773: I/dalvikvm(696):   at dalvik.system.NativeStart.main(Native Method)
08-11 14:11:53.804: D/skia(696): --- decoder->decode returned false
08-11 14:11:53.804: D/AndroidRuntime(696): Shutting down VM
08-11 14:11:53.804: W/dalvikvm(696): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
08-11 14:11:53.823: E/AndroidRuntime(696): FATAL EXCEPTION: main
08-11 14:11:53.823: E/AndroidRuntime(696): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidwallpaper/com.example.androidwallpaper.MainActivity}: android.view.InflateException: Binary XML file line #43: Error inflating class 
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.os.Looper.loop(Looper.java:137)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.app.ActivityThread.main(ActivityThread.java:4745)
08-11 14:11:53.823: E/AndroidRuntime(696):  at java.lang.reflect.Method.invokeNative(Native Method)
08-11 14:11:53.823: E/AndroidRuntime(696):  at java.lang.reflect.Method.invoke(Method.java:511)
08-11 14:11:53.823: E/AndroidRuntime(696):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-11 14:11:53.823: E/AndroidRuntime(696):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-11 14:11:53.823: E/AndroidRuntime(696):  at dalvik.system.NativeStart.main(Native Method)
08-11 14:11:53.823: E/AndroidRuntime(696): Caused by: android.view.InflateException: Binary XML file line #43: Error inflating class 
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
08-11 14:11:53.823: E/AndroidRuntime(696):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-11 14:11:53.823: E/AndroidRuntime(696):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.app.Activity.setContentView(Activity.java:1867)
08-11 14:11:53.823: E/AndroidRuntime(696):  at com.example.androidwallpaper.MainActivity.onCreate(MainActivity.java:12)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.app.Activity.performCreate(Activity.java:5008)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-11 14:11:53.823: E/AndroidRuntime(696):  ... 11 more
08-11 14:11:53.823: E/AndroidRuntime(696): Caused by: java.lang.reflect.InvocationTargetException
08-11 14:11:53.823: E/AndroidRuntime(696):  at java.lang.reflect.Constructor.constructNative(Native Method)
08-11 14:11:53.823: E/AndroidRuntime(696):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
08-11 14:11:53.823: E/AndroidRuntime(696):  ... 26 more
08-11 14:11:53.823: E/AndroidRuntime(696): Caused by: java.lang.OutOfMemoryError
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.content.res.Resources.loadDrawable(Resources.java:1930)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.widget.ImageView.(ImageView.java:120)
08-11 14:11:53.823: E/AndroidRuntime(696):  at android.widget.ImageView.(ImageView.java:110)
08-11 14:11:53.823: E/AndroidRuntime(696):  ... 29 more
08-11 14:11:59.383: I/Process(696): Sending signal. PID: 696 SIG: 9

My codes are as follows:

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/IVDisplay"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:src="@drawable/wp1" />

<Button
    android:id="@+id/bSetWallPaper"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Set Wallpaper" />

<HorizontalScrollView
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/IVimage1"
            android:layout_width="125dp"
            android:layout_height="125dp"
            android:padding="15dp"
            android:src="@drawable/wp1" />

        <ImageView
            android:id="@+id/IVimage2"
            android:layout_width="125dp"
            android:layout_height="125dp"
            android:padding="15dp"
            android:src="@drawable/wp2" />

        <ImageView
            android:id="@+id/IVimage3"
            android:layout_width="125dp"
            android:layout_height="125dp"
            android:padding="15dp"
            android:src="@drawable/wp3" />

        <ImageView
            android:id="@+id/IVimage4"
            android:layout_width="125dp"
            android:layout_height="125dp"
            android:padding="15dp"
            android:src="@drawable/wp4" />

        <ImageView
            android:id="@+id/IVimage5"
            android:layout_width="125dp"
            android:layout_height="125dp"
            android:padding="15dp"
            android:src="@drawable/wp5" />

        <ImageView
            android:id="@+id/IVimage6"
            android:layout_width="125dp"
            android:layout_height="125dp"
            android:padding="15dp"
            android:src="@drawable/wp6" />

        <ImageView
            android:id="@+id/IVimage7"
            android:layout_width="125dp"
            android:layout_height="125dp"
            android:padding="15dp"
            android:src="@drawable/wp7" />

        <ImageView
            android:id="@+id/IVimage8"
            android:layout_width="125dp"
            android:layout_height="125dp"
            android:padding="15dp"
            android:src="@drawable/wp8" />
    </LinearLayout>
</HorizontalScrollView>

</RelativeLayout>

MainActivity.java

package com.example.androidwallpaper;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void setWallPaper (View view) {
        new AlertDialog.Builder(this).setTitle("Codes").setMessage("Put codes here later!").
        setNeutralButton("Close", null).show();  
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidwallpaper"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

Below is the screenshot of the error.

enter image description here

Below is the screenshot of the graphical layout.

enter image description here

Please help. I really really need help.

Upvotes: 1

Views: 345

Answers (2)

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

1. First of all please see that you are giving the right path of the wallpaper to be set.

2. If you are new to Android or any programming language or framework, then break things into parts and when you have all the functional parts then put them together...

You have used Alert Dialog, Menu, etc.... But have you tried putting the wall paper at the very first place, which in this case is your main aim.

You should apply OOAD principles when writing a program, whether tiny or huge....

Here is the 2 line code to apply wall paper, try this out..then try building around it

WallpaperManager wpm = WallpaperManager.getInstance(Your_Activity.this);
wpm.setBitmap(bit_map_name);

Upvotes: 1

corecase
corecase

Reputation: 1298

Try changing your java file to this and see how it works. Not sure if this is exactly what you want it to do, but I think it should help you out a bit.

package com.example.androidwallpaper;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    AlertDialog.Builder builder;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        builder = new AlertDialog.Builder(this);
        builder.setTitle("Codes");
        builder.setMessage("Put codes here later!");
        builder.show();
    }
    /*
    public void setWallPaper (View view) {
        new AlertDialog.Builder(this).setTitle("Codes").setMessage("Put codes here later!").
        setNeutralButton("Close", null).show();  
    }*/

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

You should also be able to say builder.setNeutralButton()

Upvotes: 1

Related Questions