[Q] First program (error message) - Android Apps and Games

Hi, i know a little bit of java so i was thinking start to create program to my android phone.
but even "hello world" program can't run, i get message:
An internal error occurred during: "Launching New_configuration".
Path for project must have only one segment.
How to fix this ?
Thanks

so no one knows how to fix this ?

I might be helpfull if you would've posted the code you have

it's from google site android hello world program
nevertheless :
package com.android.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}

Related

Android Developers: HelloGallery tutorial: "android.R.styleable cannot be resolved"

Android Developers: HelloGallery tutorial: "android.R.styleable cannot be resolved"
Hello,
I've been following the Views tutorials included in the android developer site:
http://developer.android.com/guide/t...o-gallery.html
When testing the "Hello Gallery" view, I get the compile-time error:
"android.R.styleable cannot be resolved"
I searched for this error on this group but is wasn't answered.
Can anyone help?
The problem reference occurs in the imageAdapter class that is appended after the onCreate() method in the HelloGallery class:
public class ImageAdapter extends BaseAdapter
{
...
TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);
}
Strangely enough, when I insert this line into the onCreate() method at the start of the package, there is no problem. It seems that the android.R class is not known to this class.
Thanks,
Paul
any resolution to this issue?
I am running into the same issue and was wondring if you had found a resolution?
Thanks in advance,
-Nathan
tell me you know what is import
If it is what you mean, "import android.R.styleable" is not possible.
vincebodi said:
If it is what you mean, "import android.R.styleable" is not possible.
Click to expand...
Click to collapse
No, it's impossible. As I realized after I did that post, they changed the example codes in 1.5 SDK and broke some applications. If you lose "android." the code should compile.
I copied "ImageAdapter" Class into "HelloGallery" Class. And it's work.
Here is my code:
package com.example.hellogallery;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class HelloGallery extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
Toast.makeText(HelloGallery.this, "" + position,
Toast.LENGTH_SHORT).show();
}
});
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = { R.drawable.sample_1, R.drawable.sample_2,
R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7 };
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
}
attrs.xml and obtainStyledAttributes
Thanks for the code tonghoho...I still had the same problem until I uploaded attrs.xml from the samples, following instructions here: http://www.mail-archive.com/[email protected]/msg34088.html . I used the same code above, but now I'm getting another error. Here's the part with the problem:
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
The error is for obtainStyledAttributes, and is:
The method obtainStyledAttributes(int[]) is undefined for the type ImageAdapter
Any ideas?
Thanks ahead of time...
@Collene: you probably have ImageAdapter in a separate file and not as an inner class of HelloGalery? obtainStyledAttributes() is a method of the Context class so you have to change the code like so:
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = c.obtainStyledAttributes(R.styleable.default_gallery);
Complete solution can be found in this thread: http://www.mail-archive.com/[email protected]/msg11862.html
Thank you so much for your help David B. I can see now that the tutorial left off the letter "c" there, and eclipse, while awesome, wasn't really helping me out with diagnosing the problem.

[Resolved] [Q] Android App Problem (Linking list items to the android market)

Hey guys,
I need some help with my first app.
I cannot post this in the Anddev section because of my low post count, so I apologize that this goes here.
I want to link some list positions to the respective android market pages. My current code looks like this:
Code:
package com.asm.reader;
import java.util.ArrayList;
import java.util.Arrays;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
public class TitlesActivity extends ListActivity {
/** Called when the activity is first created. */
String[] links = {
"Get Full Version", "Get Reading Sample 2", "Get Reading Sample 3", "Get Reading Sample 4", "Get Reading Sample 5",
"Get Story 2", "Get Story 3", "Get Story 4", "Get Story 5"};
private ArrayAdapter<String> adapter;
private String selectedItem;
private final Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OnItemClickListener itemListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int position,
long arg3) {
}
};
ArrayList<String> list = new ArrayList<String>(Arrays.asList(links));
adapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
list);
setListAdapter(adapter);
getListView().setOnItemClickListener(itemListener);
}
}
The dev guide says I have to do this:
Code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.example"));
startActivity(intent);
But how do I set it with the right position?
Thanks a lot in advance, I hope you guys can help me out a little bit.
-----
edit: i got it
Please post how you did it!

[APP]2 java files dosen't work

Hi people.
I'm new in JAVA develop, and I'm trying do a simple game.
I tryed to work with 2 separated java files, but I don't know what I'm doing wrong. Example:
File "TesteActivity.java"
package pack.teste;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TesteActivity extends Activity {
test1 test = new test1();
public TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView)findViewById(R.id.maoe);
text.setText(test.hahae);
}
}
File "test1.java"
package pack.teste;
public class test1 {
TesteActivity test = new TesteActivity();
public String hahae = "maoe";
}
And dosen't work. Somebody can help me?
Thanks

[Q] WebView app opens up default browser.

Hello I am a Android newbie and I am currently learning how to code applications using Eclipse so I made one yesterday using webview on eclipse but everytime I open the app it takes me to the website but on my default browser. I want the website to open up in the app not on my browser. Anyone know how to fix this?
You need to read the WebView Reference on Android.
Apparently you open the website on a Intent, so the website is opened on the default browser.
Instead, you need to make you Activity act as a WebView on the 'onCreate()' :
Code:
WebView webview = new WebView(this);
setContentView(webview);
And then open the website :
Code:
// Simplest usage: note that an exception will NOT be thrown
// if there is an error loading this page (see below).
webview.loadUrl("my_url");
// OR, you can also load from an HTML string:
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
// ... although note that there are restrictions on what this HTML can do.
// See the JavaDocs for loadData() and loadDataWithBaseURL() for more info.
Um this is my MainActivity.java
package com.graaltailor.JFA;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("examplewebsite");
}
}
You need to do something like this to overwrite urlredirect opened in the default browser :
Code:
package com.graaltailor.JFA;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("examplewebsite");
}
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
}
I replaced the code with the one you replied with and I get a bunch of errors.
sorry I made a mistake in the code
Code:
package com.graaltailor.JFA;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("examplewebsite");
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
}
}

API 19 and Bluetooth Low Energy

I am currently working on a project to connect a Google Glass Explorer Edition (Android Kitkat and therefore API 19) to an Arduino board emitting data in BLE.
I have checked that this is possible and I have found and installed an APK that manages to make the link. However, I want to make a slightly different application.
The application I want to make has a splash screen and a main activity displaying the different values on TextView. This part is already working.
Splash Screen:
Java:
package com.example.flyin_glass;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
/* loaded from: classes.dex */
public class SplashScreenActivity extends AppCompatActivity {
/* JADX INFO: Access modifiers changed from: protected */
@Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
Runnable runnable = new Runnable() { // from class: com.example.myapplication.SplashScreenActivity.1
@Override // java.lang.Runnable
public void run()
{
Intent intent = new Intent(SplashScreenActivity.this.getApplicationContext(), MainActivity.class);
SplashScreenActivity.this.startActivity(intent);
SplashScreenActivity.this.finish();
}
};
new Handler().postDelayed(runnable, 3000L);
}
}
Main activity :
Java:
package com.example.flyin_glass;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.*;
import android.bluetooth.le.*;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.content.Context;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
My goal would be to code (in main activity) the management of the BLE, i.e. the automatic connection to my Arduino (which has a specific UUID) as well as the data retrieval and display in TextView.
Being a novice in Android development, the task of managing the BLE is very complex for me. Do you have any advice?
Thank you in advance.
GAUBERT36

Categories

Resources