开发者

Temp Converter App: Fails with unknown error

开发者 https://www.devze.com 2023-02-07 03:46 出处:网络
I am beginning Android programming. I have made the rough GUI for a Temperature Converter but when I run my app I get an error that is hard to determine what is wrong & what point the program fail

I am beginning Android programming. I have made the rough GUI for a Temperature Converter but when I run my app I get an error that is hard to determine what is wrong & what point the program fails (Has anyone knowticed how vague/weird the console & debugging notes ar开发者_如何学Ce when the Android emulator/OS runs?).

I am developing an app in Eclipse with the plugin, the Device API version is 9 (Android 2.3), I dont use xml to create & layout the Views, I do it programmatically.

Output from Console when error occurs:

-Starting activity temperatureconv.main.TempMain on device emulator-5554

-ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=temperatureconv.main/.TempMain }

-Attempting to connect debugger to 'temperatureconv.main' on port 8675

After this error, eclipse then opens the "Class File Editor" & it says:

Source not found

The JAR file C:/..../android.jar has no source attachment.

You can attach the source by clicking Attach Source below

What error do you think is occuring? How can I fix this?

My code: package temperatureconv.main;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TempMain extends Activity 
{
    /// Class Variables:

    private LinearLayout layout;

    /// Class Methods:

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        initComponents();

        setContentView( layout );  // is this the correct way to set the main panel/view (remember I am not using the XML layout way)?
             // Can I use System.out.println(); in a google app, or will that crash it?
             // coz I get some funny errors when I do use it.
    }


    /**
     * Create & initialise all application components
     * 
     * @return True if the application components & facade were successfully created
     */
    public boolean initComponents()
    {
        layout          = new LinearLayout( this );
        TextView celLbl = new TextView( this );
        TextView fahLbl = new TextView( this );
        TextView celTxt = new TextView( this );
        TextView fahTxt = new TextView( this );


        // Set Component data
        celLbl.setText( "Celsius: " );
        fahLbl.setText( "Fahrenheit: " );
        celTxt.setText( "0" );
        fahTxt.setText( "32" );
        layout.setBackgroundColor( Color.BLUE );
        celTxt.setBackgroundColor( Color.WHITE );
        fahTxt.setBackgroundColor( Color.WHITE );

        layout.addView( celLbl );
        layout.addView( fahLbl );
        layout.addView( celTxt );
        layout.addView( fahTxt );

        celLbl.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) );
        fahLbl.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) );
        celTxt.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) );
        fahTxt.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) );

        return true;
    }
}


You can't use System.out.println in Android apps. You should use the standard Android logging facility - the Log class.

The actual issue Eclipse is complaining about is that it cannot find the sources for your application package. Not sure why this happens, though.

0

精彩评论

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